Commit 61fd444f authored by Kirill Smelkov's avatar Kirill Smelkov

Add support for more kind of tarball URLs

Hit issues with those urls on ERP5 SR because they were not recognized previously.
parent 6d3814ef
......@@ -32,6 +32,7 @@ import sys, configparser, re
from os.path import basename
from glob import glob
from collections import namedtuple
from urllib.parse import unquote
# PkgInfo represents information about a package
......@@ -194,29 +195,58 @@ def bom_node(XXX):
#
# http://www.python.org/ftp/python/2.7.18/Python-2.7.18.tar.xz -> ('Python', '2.7.18')
_gitweb_re = re.compile(r'/gitweb/\?p=(?P<name>\w+)\.git;a=snapshot;h=(?P<rev>\w+)')
_github_re = re.compile(r'github.com/\w+/(?P<name>\w+)/archive/(?P<rev>.+)$')
_github_re = re.compile(r'/github.com/[\w\-]+/(?P<name>[\w\-]+)/archive/(refs/tags/)?(?P<rev>.+)$')
_github_rre= re.compile(r'/raw.githubusercontent.com/[\w\-]+/(?P<name>[\w\-]+)/(?P<rev>[\w\.\-]+)/')
_SF_re = re.compile(r'/sourceforge.net/.+/(?P<name>[\w\_]+)-(?P<rev>[\w\.]+)/download$')
_go_re = re.compile(r'/golang.org/dl/(?P<name>go)(?P<rev>[\w\.]+).src$')
_osdn_f = re.compile(r'/osdn.net/frs/redir.php\?f=(?P<f>.+)$')
def namever(url): # -> (name, ver)
for tail in ('.tgz', '.tar.gz', '.tbz', '.tar.bz2', '.tar.xz', '.tar.lz',
# http://www.ijg.org/files/jpegsrc.v9d.tar.gz -> http://www.ijg.org/files/jpegsrc.v9d
def del_tgztail(s):
for tail in ('.tgz', '.tar.gz', '.tbz', '.tar.bz2', '.tar.xz', '.tar.lz', '.zip',
'-py2.7.egg', '-py2.7-linux-x86_64.egg'): # FIXME -> re to cover py2/py3 x86/arm ...
url = removesuffix(url, tail)
s = removesuffix(s, tail)
return s
url = del_tgztail(url)
name, ver = _namever(url)
if ver is not None:
# swig-3.0.12.tar.gz -> swig-3.0.12
# originally from https://sourceforge.net/projects/swig/files/swig/swig-3.0.12/swig-3.0.12.tar.gz/download
ver = del_tgztail(ver)
ver = removeprefix(ver, 'v')
return name, ver
def _namever(url):
for r in (_gitweb_re, _github_re):
for r in (_gitweb_re, _github_re, _github_rre, _SF_re, _go_re):
m = r.search(url)
if m is not None:
return m.group('name'), m.group('rev')
m = _osdn_f.search(url)
if m is not None:
url = unquote(m.group('f'))
filename = basename(url)
# re.rsplit([-_], filename, 1)
m = re.search('[-_][^-_]*$', filename)
assert m is not None
if m is not None:
name = filename[:m.start()]
ver = filename[m.start()+1:]
return name, ver
m = re.search(r'\.v.+$', filename) # jpegsrc.v9d
if m is not None:
name = filename[:m.start()]
ver = filename[m.start()+1:]
return name, ver
m = re.match(r'(?P<name>.*[^0-9])(?P<rev>[0-9]+)$', filename) # IPAexfont00201
if m is not None:
return m.group('name'), m.group('rev')
raise RuntimeError('Unsupported url: %r' % (url,))
# isconf returns whether url points to data related to configuration file
# (contrary to binary executable), or a simple/small script.
......
......@@ -27,8 +27,17 @@ from os.path import dirname
@pytest.mark.parametrize('url,nameok,verok', [
('http://www.python.org/ftp/python/2.7.18/Python-2.7.18.tar.xz', 'Python', '2.7.18'),
('http://www.ijg.org/files/jpegsrc.v9d.tar.gz', 'jpegsrc', '9d'),
('https://github.com/nghttp2/nghttp2/archive/v1.40.0.tar.gz', 'nghttp2', '1.40.0'),
('https://golang.org/dl/go1.18.9.src', 'go', '1.18.9'),
('https://github.com/tesseract-ocr/tesseract/archive/refs/tags/4.1.1.tar.gz', 'tesseract', '4.1.1'),
('https://raw.githubusercontent.com/zuphilip/ocropy-models/master/en-default.pyrnn.gz', 'ocropy-models', 'master'),
('https://sourceforge.net/projects/swig/files/swig/swig-3.0.12/swig-3.0.12.tar.gz/download', 'swig', '3.0.12'),
('https://git.savannah.gnu.org/gitweb/?p=config.git;a=snapshot;h=5e531d39;sf=tgz', 'config', '5e531d39'),
('/ROOT/develop-eggs/mysqlclient-1.3.12-py2.7-linux-x86_64.egg', 'mysqlclient', '1.3.12'),
('https://osdn.net/frs/redir.php?f=ipafonts%2F57330%2FIPAexfont00201.zip', 'IPAexfont', '00201'),
('https://osdn.net/frs/redir.php?f=ipafonts%2F51868%2FIPAfont00303.zip', 'IPAfont', '00303'),
('https://osdn.net/frs/redir.php?f=tsukurimashou%2F56948%2Focr-0.2.zip', 'ocr', '0.2'),
])
def test_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