euscan: mangle versions the gentoo-way
Signed-off-by: Corentin Chary <corentincj@iksaif.net>
This commit is contained in:
parent
da269b0711
commit
3da5fb5240
@ -72,8 +72,9 @@ def scan_directory_recursive(cp, ver, rev, url, steps, orig_url):
|
||||
|
||||
versions = []
|
||||
|
||||
for version, path in results:
|
||||
if helpers.version_filtered(cp, ver, version):
|
||||
for up_pv, path in results:
|
||||
pv = helpers.gentoo_mangle_version(up_pv)
|
||||
if helpers.version_filtered(cp, ver, pv):
|
||||
continue
|
||||
|
||||
if not url.endswith('/') and not path.startswith('/'):
|
||||
@ -82,7 +83,7 @@ def scan_directory_recursive(cp, ver, rev, url, steps, orig_url):
|
||||
path = url + path
|
||||
|
||||
if not steps and path not in orig_url:
|
||||
versions.append((path, version))
|
||||
versions.append((path, pv))
|
||||
|
||||
if steps:
|
||||
ret = scan_directory_recursive(cp, ver, rev, path, steps, orig_url)
|
||||
|
@ -52,16 +52,17 @@ def scan(cpv, url):
|
||||
cp, ver, rev = portage.pkgsplit(cpv)
|
||||
|
||||
for node in nodes:
|
||||
version = node.childNodes[0].data
|
||||
if helpers.version_filtered(cp, ver, version):
|
||||
up_pv = node.childNodes[0].data
|
||||
pv = helpers.gentoo_mangle_version(up_pv)
|
||||
if helpers.version_filtered(cp, ver, pv):
|
||||
continue
|
||||
|
||||
url = 'http://%s/get/%s-%s.tgz' % (channel, pkg, version)
|
||||
url = 'http://%s/get/%s-%s.tgz' % (channel, pkg, up_pv)
|
||||
|
||||
if url == orig_url:
|
||||
continue
|
||||
|
||||
ret.append(( url, version ))
|
||||
ret.append(( url, pv ))
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -39,12 +39,13 @@ def scan(cpv, url):
|
||||
|
||||
ret = []
|
||||
|
||||
for version in versions:
|
||||
if helpers.version_filtered(cp, ver, version):
|
||||
for up_pv in versions:
|
||||
pv = helpers.gentoo_mangle_version(up_pv)
|
||||
if helpers.version_filtered(cp, ver, pv):
|
||||
continue
|
||||
urls = client.release_urls(package, version)
|
||||
urls = client.release_urls(package, up_pv)
|
||||
urls = " ".join([ infos['url'] for infos in urls ])
|
||||
ret.append(( urls, version ))
|
||||
ret.append(( urls, pv ))
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -56,11 +56,12 @@ def scan(cpv, url):
|
||||
ret = []
|
||||
|
||||
for version in versions:
|
||||
version = version['number']
|
||||
if helpers.version_filtered(cp, ver, version):
|
||||
up_pv = version['number']
|
||||
pv = helpers.gentoo_mangle_version(up_pv)
|
||||
if helpers.version_filtered(cp, ver, pv):
|
||||
continue
|
||||
url = 'http://rubygems.org/gems/%s-%s.gem' % (gem, version)
|
||||
ret.append(( url, version ))
|
||||
url = 'http://rubygems.org/gems/%s-%s.gem' % (gem, up_pv)
|
||||
ret.append(( url, pv ))
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -33,6 +33,119 @@ VERSION_CMP_PACKAGE_QUIRKS = {
|
||||
_v_end = '((-|_)(pre|p|beta|b|alpha|a|rc|r)\d*)'
|
||||
_v = r'((\d+)((\.\d+)*)([a-zA-Z]*?)(' + _v_end + '*))'
|
||||
|
||||
# Stolen from g-pypi
|
||||
def gentoo_mangle_version(up_pv):
|
||||
"""Convert PV to MY_PV if needed
|
||||
|
||||
:param up_pv: Upstream package version
|
||||
:type up_pv: string
|
||||
:returns: pv
|
||||
:rtype: string
|
||||
|
||||
Can't determine PV from upstream's version.
|
||||
Do our best with some well-known versioning schemes:
|
||||
|
||||
* 1.0a1 (1.0_alpha1)
|
||||
* 1.0-a1 (1.0_alpha1)
|
||||
* 1.0b1 (1.0_beta1)
|
||||
* 1.0-b1 (1.0_beta1)
|
||||
* 1.0-r1234 (1.0_pre1234)
|
||||
* 1.0dev-r1234 (1.0_pre1234)
|
||||
* 1.0.dev-r1234 (1.0_pre1234)
|
||||
* 1.0dev-20091118 (1.0_pre20091118)
|
||||
|
||||
Regex match.groups():
|
||||
* pkgfoo-1.0.dev-r1234
|
||||
* group 1 pv major (1.0)
|
||||
* group 2 replace this with portage suffix (.dev-r)
|
||||
* group 3 suffix version (1234)
|
||||
|
||||
The order of the regexes is significant. For instance if you have
|
||||
.dev-r123, dev-r123 and -r123 you should order your regex's in
|
||||
that order.
|
||||
|
||||
The chronological portage release versions are:
|
||||
|
||||
* _alpha
|
||||
* _beta
|
||||
* _pre
|
||||
* _rc
|
||||
* release
|
||||
* _p
|
||||
|
||||
**Example:**
|
||||
|
||||
>>> gentoo_mangle_version('1.0b2')
|
||||
'1.0_beta2'
|
||||
|
||||
.. note::
|
||||
The number of regex's could have been reduced, but we use four
|
||||
number of match.groups every time to simplify the code
|
||||
|
||||
"""
|
||||
bad_suffixes = re.compile(
|
||||
r'((?:[._-]*)(?:dev|devel|final|stable|snapshot)$)', re.I)
|
||||
revision_suffixes = re.compile(
|
||||
r'(.*?)([\._-]*(?:r|patch|p)[\._-]*)([0-9]*)$', re.I)
|
||||
suf_matches = {
|
||||
'_pre': [
|
||||
r'(.*?)([\._-]*dev[\._-]*r?)([0-9]+)$',
|
||||
r'(.*?)([\._-]*(?:pre|preview)[\._-]*)([0-9]*)$',
|
||||
],
|
||||
'_alpha': [
|
||||
r'(.*?)([\._-]*(?:alpha|test)[\._-]*)([0-9]*)$',
|
||||
r'(.*?)([\._-]*a[\._-]*)([0-9]*)$',
|
||||
r'(.*[^a-z])(a)([0-9]*)$',
|
||||
],
|
||||
'_beta': [
|
||||
r'(.*?)([\._-]*beta[\._-]*)([0-9]*)$',
|
||||
r'(.*?)([\._-]*b)([0-9]*)$',
|
||||
r'(.*[^a-z])(b)([0-9]*)$',
|
||||
],
|
||||
'_rc': [
|
||||
r'(.*?)([\._-]*rc[\._-]*)([0-9]*)$',
|
||||
r'(.*?)([\._-]*c[\._-]*)([0-9]*)$',
|
||||
r'(.*[^a-z])(c[\._-]*)([0-9]+)$',
|
||||
],
|
||||
}
|
||||
rs_match = None
|
||||
pv = up_pv
|
||||
additional_version = ""
|
||||
|
||||
rev_match = revision_suffixes.search(up_pv)
|
||||
if rev_match:
|
||||
pv = up_pv = rev_match.group(1)
|
||||
replace_me = rev_match.group(2)
|
||||
rev = rev_match.group(3)
|
||||
additional_version = '.' + rev
|
||||
|
||||
for this_suf in suf_matches.keys():
|
||||
if rs_match:
|
||||
break
|
||||
for regex in suf_matches[this_suf]:
|
||||
rsuffix_regex = re.compile(regex, re.I)
|
||||
rs_match = rsuffix_regex.match(up_pv)
|
||||
if rs_match:
|
||||
portage_suffix = this_suf
|
||||
break
|
||||
|
||||
if rs_match:
|
||||
# e.g. 1.0.dev-r1234
|
||||
major_ver = rs_match.group(1) # 1.0
|
||||
replace_me = rs_match.group(2) # .dev-r
|
||||
rev = rs_match.group(3) # 1234
|
||||
pv = major_ver + portage_suffix + rev
|
||||
else:
|
||||
# Single suffixes with no numeric component are simply removed.
|
||||
match = bad_suffixes.search(up_pv)
|
||||
if match:
|
||||
suffix = match.groups()[0]
|
||||
pv = up_pv[: - (len(suffix))]
|
||||
|
||||
pv = pv + additional_version
|
||||
|
||||
return pv
|
||||
|
||||
def cast_int_components(version):
|
||||
for i, obj in enumerate(version):
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user