1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-09 00:40:11 +01:00

Merge branch 'parse-srclibs' into 'master'

handle all cases of @ in srclibs, and remove duplicate code

See merge request fdroid/fdroidserver!1424
This commit is contained in:
Hans-Christoph Steiner 2024-01-08 15:02:34 +00:00
commit a3b7c5ad12
2 changed files with 28 additions and 18 deletions

View File

@ -2059,15 +2059,15 @@ def parse_srclib_spec(spec):
"(not a string): '{}'") "(not a string): '{}'")
.format(spec)) .format(spec))
tokens = spec.split('@') tokens = spec.split('@', 1)
if len(tokens) > 2: if not tokens[0]:
raise MetaDataException(_("could not parse srclib spec " raise MetaDataException(
"(too many '@' signs): '{}'") _("could not parse srclib spec (no name specified): '{}'").format(spec)
.format(spec)) )
elif len(tokens) < 2: if len(tokens) < 2 or not tokens[1]:
raise MetaDataException(_("could not parse srclib spec " raise MetaDataException(
"(no ref specified): '{}'") _("could not parse srclib spec (no ref specified): '{}'").format(spec)
.format(spec)) )
name = tokens[0] name = tokens[0]
ref = tokens[1] ref = tokens[1]
@ -2103,11 +2103,7 @@ def getsrclib(spec, srclib_dir, basepath=False,
name = spec name = spec
ref = None ref = None
else: else:
name, ref = spec.split('@', 1) name, ref, number, subdir = parse_srclib_spec(spec)
if ':' in name:
number, name = name.split(':', 1)
if '/' in name:
name, subdir = name.split('/', 1)
if name not in fdroidserver.metadata.srclibs: if name not in fdroidserver.metadata.srclibs:
raise VCSException('srclib ' + name + ' not found.') raise VCSException('srclib ' + name + ' not found.')

View File

@ -1514,13 +1514,27 @@ class CommonTest(unittest.TestCase):
self.assertEqual(fdroidserver.common.parse_srclib_spec('1:Support/v7/appcompat@android-4.4_r1.1'), self.assertEqual(fdroidserver.common.parse_srclib_spec('1:Support/v7/appcompat@android-4.4_r1.1'),
('Support', 'android-4.4_r1.1', '1', 'v7/appcompat')) ('Support', 'android-4.4_r1.1', '1', 'v7/appcompat'))
def test_parse_srclib_spec_bad(self): def test_parse_srclib_spec_many_ats(self):
self.assertEqual(
fdroidserver.common.parse_srclib_spec('foo@@v2'), ('foo', '@v2', None, None)
)
self.assertEqual(
fdroidserver.common.parse_srclib_spec('bar@2@f'), ('bar', '2@f', None, None)
)
def test_parse_srclib_spec_none(self):
with self.assertRaises(MetaDataException): with self.assertRaises(MetaDataException):
self.assertEqual(fdroidserver.common.parse_srclib_spec(None)) fdroidserver.common.parse_srclib_spec(None)
def test_parse_srclib_spec_no_ref(self):
with self.assertRaises(MetaDataException): with self.assertRaises(MetaDataException):
self.assertEqual(fdroidserver.common.parse_srclib_spec('no-ref')) fdroidserver.common.parse_srclib_spec('no-ref')
with self.assertRaises(MetaDataException): with self.assertRaises(MetaDataException):
self.assertEqual(fdroidserver.common.parse_srclib_spec('@multi@at-signs@')) fdroidserver.common.parse_srclib_spec('noref@')
def test_parse_srclib_spec_no_name(self):
with self.assertRaises(MetaDataException):
fdroidserver.common.parse_srclib_spec('@ref')
def test_remove_signing_keys(self): def test_remove_signing_keys(self):
shutil.copytree( shutil.copytree(