Commit 589ca02a authored by Kirill Smelkov's avatar Kirill Smelkov

Fix support for icu4c url

See previous patch for how it was crashing.

Needed to improve version detection heuristic because with only trimming
-src suffix the version was detected as "2" and name as "icu4c-58".
parent 49514a19
...@@ -295,7 +295,7 @@ def namever(url, failonerr=True): # -> (name, ver) | None if !failonerr ...@@ -295,7 +295,7 @@ def namever(url, failonerr=True): # -> (name, ver) | None if !failonerr
s = removesuffix(s, tail) s = removesuffix(s, tail)
for tail in ['-py2.7'] + ['-py3.%d' % _ for _ in range(20)]: for tail in ['-py2.7'] + ['-py3.%d' % _ for _ in range(20)]:
s = removesuffix(s, tail) s = removesuffix(s, tail)
for tail in ('-source',): for tail in ('-source', '-src'):
s = removesuffix(s, tail) s = removesuffix(s, tail)
return s return s
url = del_tgztail(url) url = del_tgztail(url)
...@@ -332,15 +332,30 @@ def _namever(url, failonerr): ...@@ -332,15 +332,30 @@ def _namever(url, failonerr):
url = unquote(m.group('f')) url = unquote(m.group('f'))
filename = basename(url) filename = basename(url)
# re.rsplit([-_], filename, 1)
m = re.search('[-_][^-_]*$', filename) name = filename
if m is not None: ver = ''
name = filename[:m.start()] dashed = False
ver = filename[m.start()+1:] while 1:
if re.search(r'[0-9]', ver): # re.rsplit([-_], name, 1)
return name, ver m = re.search('[-_][^-_]*$', name)
if m is None:
break
dashed = True
v = name[m.start():]
v_ndigit = 0
for _ in v:
if _.isnumeric():
v_ndigit += 1
if v_ndigit < (len(v)-1) / 5: # doesn't look like a version
break
name = name[:m.start()]
ver = v + ver
if dashed:
if not ver:
return name, None # no version
else: else:
return filename, None # no version return name, ver[1:] # ver without leading '-'
m = re.search(r'\.v.+$', filename) # jpegsrc.v9d m = re.search(r'\.v.+$', filename) # jpegsrc.v9d
if m is not None: if m is not None:
......
...@@ -42,6 +42,7 @@ from os.path import dirname, exists ...@@ -42,6 +42,7 @@ from os.path import dirname, exists
('http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz', 'GeoLite2-Country', None), ('http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz', 'GeoLite2-Country', None),
('http://downloadarchive.documentfoundation.org/libreoffice/old/5.2.4.2/rpm/x86_64/LibreOffice_5.2.4.2_Linux_x86-64_rpm.tar.gz', 'LibreOffice', '5.2.4.2'), ('http://downloadarchive.documentfoundation.org/libreoffice/old/5.2.4.2/rpm/x86_64/LibreOffice_5.2.4.2_Linux_x86-64_rpm.tar.gz', 'LibreOffice', '5.2.4.2'),
('http://www.cups.org/software/1.7.4/cups-1.7.4-source.tar.bz2', 'cups', '1.7.4'), ('http://www.cups.org/software/1.7.4/cups-1.7.4-source.tar.bz2', 'cups', '1.7.4'),
('https://github.com/unicode-org/icu/releases/download/release-58-2/icu4c-58_2-src.tgz', 'icu4c', '58_2'),
]) ])
def test_namever(url, nameok, verok): def test_namever(url, nameok, verok):
assert nxdbom.namever(url) == (nameok, verok) assert nxdbom.namever(url) == (nameok, verok)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment