euscan: add a better way to compare versions

Fix issue reported by Tomáš Chvátal

> http://euscan.iksaif.net/package/media-video/kmplayer/
> 0.11.2c IS newer than 0.11.2 :)

Signed-off-by: Corentin Chary <corentincj@iksaif.net>
This commit is contained in:
Corentin Chary 2011-04-20 17:23:45 +02:00
parent c3dd96258b
commit 67566c164c

39
euscan
View File

@ -30,6 +30,7 @@ import StringIO
import pkg_resources import pkg_resources
import portage import portage
import portage.versions
from portage.output import white, yellow, turquoise, green, teal, red, EOutput from portage.output import white, yellow, turquoise, green, teal, red, EOutput
from portage.dbapi.porttree import _parse_uri_map from portage.dbapi.porttree import _parse_uri_map
@ -66,11 +67,24 @@ def cast_int_components(version):
pass pass
return version return version
def parse_version(version): def vercmp(a, b):
version = pkg_resources.parse_version(version) if a == b:
#version = list(version) return 0
#return cast_int_components(version)
return version # For sane versions
r = portage.versions.vercmp(a, b)
if r is not None:
return r
# Fallback
a = pkg_resources.parse_version(a)
b = pkg_resources.parse_version(b)
if a < b:
return -1
else:
return 1
def generate_templates_vars(version): def generate_templates_vars(version):
ret = [] ret = []
@ -297,15 +311,13 @@ def scan_directory_recursive(url, steps, vmin, vmax, output):
versions = [] versions = []
for version, path in results: for version, path in results:
ver = parse_version(version) if vmin and vercmp(version, vmin) <= 0:
if vmin and ver <= vmin:
continue continue
if vmax and ver >= vmax: if vmax and vercmp(version, vmax) >= 0:
continue continue
# Try to skip nightly builds when not wanted (www-apps/moodle) # Try to skip nightly builds when not wanted (www-apps/moodle)
if len(vmin) != len(ver) and len(ver) == 2 and len(ver[0]) == len('yyyymmdd'): if len(vmin) != len(version) and len(version) == 2 and len(version[0]) == len('yyyymmdd'):
continue continue
if not url.endswith('/') and not path.startswith('/'): if not url.endswith('/') and not path.startswith('/'):
@ -335,10 +347,8 @@ def scan_directory(cpv, fileurl, options, output, limit=None):
else: else:
output.einfo("Scanning: %s" % template) output.einfo("Scanning: %s" % template)
vmin = parse_version(ver)
steps = generate_scan_paths(template) steps = generate_scan_paths(template)
return scan_directory_recursive("", steps, vmin, limit, output) return scan_directory_recursive("", steps, ver, limit, output)
def brute_force(cpv, fileurl, options, output, limit=None): def brute_force(cpv, fileurl, options, output, limit=None):
if options["brute-force"] <= 0: if options["brute-force"] <= 0:
@ -387,9 +397,8 @@ def brute_force(cpv, fileurl, options, output, limit=None):
done.append(tuple(components)) done.append(tuple(components))
vstring = join_version(components) vstring = join_version(components)
version = parse_version(vstring)
if limit and version >= limit: if limit and vercmp(vstring, limit) >= 0:
continue continue
url = url_from_template(template, vstring) url = url_from_template(template, vstring)