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 = []
|
versions = []
|
||||||
|
|
||||||
for version, path in results:
|
for up_pv, path in results:
|
||||||
if helpers.version_filtered(cp, ver, version):
|
pv = helpers.gentoo_mangle_version(up_pv)
|
||||||
|
if helpers.version_filtered(cp, ver, pv):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not url.endswith('/') and not path.startswith('/'):
|
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
|
path = url + path
|
||||||
|
|
||||||
if not steps and path not in orig_url:
|
if not steps and path not in orig_url:
|
||||||
versions.append((path, version))
|
versions.append((path, pv))
|
||||||
|
|
||||||
if steps:
|
if steps:
|
||||||
ret = scan_directory_recursive(cp, ver, rev, path, steps, orig_url)
|
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)
|
cp, ver, rev = portage.pkgsplit(cpv)
|
||||||
|
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
version = node.childNodes[0].data
|
up_pv = node.childNodes[0].data
|
||||||
if helpers.version_filtered(cp, ver, version):
|
pv = helpers.gentoo_mangle_version(up_pv)
|
||||||
|
if helpers.version_filtered(cp, ver, pv):
|
||||||
continue
|
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:
|
if url == orig_url:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ret.append(( url, version ))
|
ret.append(( url, pv ))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -39,12 +39,13 @@ def scan(cpv, url):
|
|||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
|
|
||||||
for version in versions:
|
for up_pv in versions:
|
||||||
if helpers.version_filtered(cp, ver, version):
|
pv = helpers.gentoo_mangle_version(up_pv)
|
||||||
|
if helpers.version_filtered(cp, ver, pv):
|
||||||
continue
|
continue
|
||||||
urls = client.release_urls(package, version)
|
urls = client.release_urls(package, up_pv)
|
||||||
urls = " ".join([ infos['url'] for infos in urls ])
|
urls = " ".join([ infos['url'] for infos in urls ])
|
||||||
ret.append(( urls, version ))
|
ret.append(( urls, pv ))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -56,11 +56,12 @@ def scan(cpv, url):
|
|||||||
ret = []
|
ret = []
|
||||||
|
|
||||||
for version in versions:
|
for version in versions:
|
||||||
version = version['number']
|
up_pv = version['number']
|
||||||
if helpers.version_filtered(cp, ver, version):
|
pv = helpers.gentoo_mangle_version(up_pv)
|
||||||
|
if helpers.version_filtered(cp, ver, pv):
|
||||||
continue
|
continue
|
||||||
url = 'http://rubygems.org/gems/%s-%s.gem' % (gem, version)
|
url = 'http://rubygems.org/gems/%s-%s.gem' % (gem, up_pv)
|
||||||
ret.append(( url, version ))
|
ret.append(( url, pv ))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -33,6 +33,119 @@ VERSION_CMP_PACKAGE_QUIRKS = {
|
|||||||
_v_end = '((-|_)(pre|p|beta|b|alpha|a|rc|r)\d*)'
|
_v_end = '((-|_)(pre|p|beta|b|alpha|a|rc|r)\d*)'
|
||||||
_v = r'((\d+)((\.\d+)*)([a-zA-Z]*?)(' + _v_end + '*))'
|
_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):
|
def cast_int_components(version):
|
||||||
for i, obj in enumerate(version):
|
for i, obj in enumerate(version):
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user