1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-11-20 13:50:12 +01:00

add srclib spec parser

This commit is contained in:
Michael Pöhn 2020-04-25 17:22:48 +02:00
parent 8285f3d759
commit b076e8cba7
3 changed files with 49 additions and 3 deletions

View File

@ -63,7 +63,7 @@ import fdroidserver.metadata
import fdroidserver.lint
from fdroidserver import _
from fdroidserver.exception import FDroidException, VCSException, NoSubmodulesException,\
BuildException, VerificationException
BuildException, VerificationException, MetaDataException
from .asynchronousfilereader import AsynchronousFileReader
# The path to this fdroidserver distribution
@ -1808,6 +1808,36 @@ def get_app_from_url(url):
return app
def parse_srclib_spec(spec):
if type(spec) != str:
raise MetaDataException(_("can not parse scrlib spec "
"(not a string): '{}'")
.format(spec))
tokens = spec.split('@')
if len(tokens) > 2:
raise MetaDataException(_("could not parse srclib spec "
"(too many '@' signs): '{}'")
.format(spec))
elif len(tokens) < 2:
raise MetaDataException(_("could not parse srclib spec "
"(no ref specified): '{}'")
.format(spec))
name = tokens[0]
ref = tokens[1]
number = None
subdir = None
if ':' in name:
number, name = name.split(':', 1)
if '/' in name:
name, subdir = name.split('/', 1)
return (name, ref, number, subdir)
def getsrclib(spec, srclib_dir, subdir=None, basepath=False,
raw=False, prepare=True, preponly=False, refresh=True,
build=None):

View File

@ -616,7 +616,7 @@ def main():
for srclib in build.srclibs:
srclibs.add(srclib)
for srclib in srclibs:
name, numer, libdir = common.getsrclib(srclib, 'srclibs', prepare=False, refresh=False)
name, ref, number, subdir = common.parse_srclib_spec(srclib)
srclibpath = os.path.join('srclibs', name + '.yml')
if os.path.isfile(srclibpath):
yamllintresult = common.run_yamllint(srclibpath)

View File

@ -34,7 +34,7 @@ import fdroidserver.signindex
import fdroidserver.common
import fdroidserver.metadata
from testcommon import TmpCwd
from fdroidserver.exception import FDroidException, VCSException
from fdroidserver.exception import FDroidException, VCSException, MetaDataException
class CommonTest(unittest.TestCase):
@ -1014,6 +1014,22 @@ class CommonTest(unittest.TestCase):
subdir = fdroidserver.common.get_gradle_subdir(build_dir, paths)
self.assertEqual(subdirs[f], subdir)
def test_parse_srclib_spec_good(self):
self.assertEqual(fdroidserver.common.parse_srclib_spec('osmand-external-skia@android/oreo'),
('osmand-external-skia', 'android/oreo', None, None))
self.assertEqual(fdroidserver.common.parse_srclib_spec('1:appcompat@v7'),
('appcompat', 'v7', '1', None))
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'))
def test_parse_srclib_spec_bad(self):
with self.assertRaises(MetaDataException):
self.assertEqual(fdroidserver.common.parse_srclib_spec(None))
with self.assertRaises(MetaDataException):
self.assertEqual(fdroidserver.common.parse_srclib_spec('no-ref'))
with self.assertRaises(MetaDataException):
self.assertEqual(fdroidserver.common.parse_srclib_spec('@multi@at-signs@'))
def test_bad_urls(self):
for url in ('asdf',
'file://thing.git',