euscan: hopefully better CPAN gentoo version mangling

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-07-31 09:50:11 +02:00
parent d34e3d4c4c
commit d262b935e6

View File

@ -34,21 +34,39 @@ def guess_package(cp, url):
def gentoo_mangle_version(up_pv): def gentoo_mangle_version(up_pv):
pv = "" # clean
up_pv = up_pv.replace("._", "_") # e.g.: 0.999._002 -> 0.999_002
up_pv = up_pv.replace("_0.", "_") # e.g.: 0.30_0.1 -> 0.30_1
if up_pv.count('.') == 1: # Detect _rc versions
digits = 0 rc_part = ""
for i in range(len(up_pv)): if up_pv.count("_") == 1:
if digits == 3: up_pv, rc_part = up_pv.split("_")
pv += "."
digits = 0 # Gentoo creates groups of 3 digits, except for the first digit,
c = up_pv[i] # or when last digit is 0. e.g.: 4.11 -> 4.110.0
pv += c splitted = up_pv.split(".")
digits += int(c.isdigit()) if rc_part:
if c == '.': splitted.append(rc_part)
digits = 0
if len(splitted) == 2: # add last group if it's missing
splitted.append("0")
groups = [splitted[0]]
for part in splitted[1:-1]:
groups.append(part.ljust(3, "0"))
if splitted[-1] == "0":
groups.append(splitted[-1])
else: else:
pv = up_pv groups.append(splitted[-1].ljust(3, "0"))
# if there's a group with leading zeros strip it. e.g.: 002 -> 2
groups = [g.lstrip("0") if g != "0" else g for g in groups]
pv = ".".join(groups)
if rc_part:
pv = "%s_rc" % pv
return helpers.gentoo_mangle_version(pv) return helpers.gentoo_mangle_version(pv)