1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-07-02 15:30:38 +02:00

Merge branch 'getvcs-pathlib-fix' into 'master'

handle str and pathlib.Path in getvcs()

See merge request fdroid/fdroidserver!1311
This commit is contained in:
Hans-Christoph Steiner 2023-02-21 10:32:50 +00:00
commit c78aeb3947
2 changed files with 55 additions and 3 deletions

View File

@ -962,6 +962,11 @@ def setup_vcs(app):
def getvcs(vcstype, remote, local): def getvcs(vcstype, remote, local):
"""Return a vcs instance based on the arguments.
remote and local can be either a string or a pathlib.Path
"""
if vcstype == 'git': if vcstype == 'git':
return vcs_git(remote, local) return vcs_git(remote, local)
if vcstype == 'git-svn': if vcstype == 'git-svn':
@ -971,7 +976,7 @@ def getvcs(vcstype, remote, local):
if vcstype == 'bzr': if vcstype == 'bzr':
return vcs_bzr(remote, local) return vcs_bzr(remote, local)
if vcstype == 'srclib': if vcstype == 'srclib':
if local != Path('build', 'srclib', remote): if str(local) != os.path.join('build', 'srclib', str(remote)):
raise VCSException("Error: srclib paths are hard-coded!") raise VCSException("Error: srclib paths are hard-coded!")
return getsrclib(remote, os.path.join('build', 'srclib'), raw=True) return getsrclib(remote, os.path.join('build', 'srclib'), raw=True)
if vcstype == 'svn': if vcstype == 'svn':
@ -1989,13 +1994,18 @@ def getsrclib(spec, srclib_dir, basepath=False,
build=None): build=None):
"""Get the specified source library. """Get the specified source library.
Returns the path to it. Normally this is the path to be used when Return the path to it. Normally this is the path to be used when
referencing it, which may be a subdirectory of the actual project. If referencing it, which may be a subdirectory of the actual project. If
you want the base directory of the project, pass 'basepath=True'. you want the base directory of the project, pass 'basepath=True'.
spec and srclib_dir are both strings, not pathlib.Path.
""" """
number = None number = None
subdir = None subdir = None
if not isinstance(spec, str):
spec = str(spec)
if not isinstance(srclib_dir, str):
spec = str(srclib_dir)
if raw: if raw:
name = spec name = spec
ref = None ref = None

View File

@ -58,6 +58,7 @@ class CommonTest(unittest.TestCase):
fdroidserver.common.config = None fdroidserver.common.config = None
fdroidserver.common.options = mock.Mock() fdroidserver.common.options = mock.Mock()
fdroidserver.common.options.verbose = False fdroidserver.common.options.verbose = False
fdroidserver.metadata.srclibs = None
self._td = mkdtemp() self._td = mkdtemp()
self.testdir = self._td.name self.testdir = self._td.name
@ -412,6 +413,47 @@ class CommonTest(unittest.TestCase):
vcs1 = fdroidserver.common.getvcs('git', git_url, gitrepo) vcs1 = fdroidserver.common.getvcs('git', git_url, gitrepo)
vcs1.gotorevision('0.3', refresh=False) vcs1.gotorevision('0.3', refresh=False)
def test_setup_vcs_srclib(self):
app = fdroidserver.metadata.App(
{
'RepoType': 'srclib',
'Repo': 'TransportsRennes',
}
)
srclib = {
'RepoType': 'git',
'Repo': 'https://github.com/ybonnel/TransportsRennes',
}
fdroidserver.metadata.srclibs = {'TransportsRennes': srclib}
vcs, build_dir = fdroidserver.common.setup_vcs(app)
self.assertIsNotNone(vcs)
self.assertEqual(build_dir, Path('build/srclib/TransportsRennes'))
def test_getvcs_srclib(self):
vcstype = 'srclib'
remote = 'TransportsRennes'
local = 'build/srclib/' + remote
fdroidserver.metadata.srclibs = {
remote: {
'RepoType': 'git',
'Repo': 'https://github.com/ybonnel/TransportsRennes',
}
}
self.assertIsNotNone(fdroidserver.common.getvcs(vcstype, remote, local))
self.assertIsNotNone(fdroidserver.common.getvcs(vcstype, Path(remote), local))
self.assertIsNotNone(fdroidserver.common.getvcs(vcstype, remote, Path(local)))
self.assertIsNotNone(fdroidserver.common.getvcs(
vcstype, Path(remote), Path(local)
))
with self.assertRaises(VCSException):
fdroidserver.common.getvcs(vcstype, remote, 'bad')
with self.assertRaises(VCSException):
fdroidserver.common.getvcs(vcstype, remote, Path('bad'))
with self.assertRaises(VCSException):
fdroidserver.common.getvcs(vcstype, Path(remote), 'bad')
with self.assertRaises(VCSException):
fdroidserver.common.getvcs(vcstype, Path(remote), Path('bad'))
def test_fdroid_popen_stderr_redirect(self): def test_fdroid_popen_stderr_redirect(self):
config = dict() config = dict()
fdroidserver.common.fill_config_defaults(config) fdroidserver.common.fill_config_defaults(config)
@ -2315,7 +2357,7 @@ class CommonTest(unittest.TestCase):
fdroidserver.common.fill_config_defaults(config) fdroidserver.common.fill_config_defaults(config)
java_paths = [] java_paths = []
# use presence of javac to make sure its JDK not just JRE # use presence of javac to make sure its JDK not just JRE
for f in glob.glob('/usr/lib/jvm/java-*-openjdk-amd64/bin/javac'): for f in glob.glob('/usr/lib/jvm/java-*-openjdk-*/bin/javac'):
jdk = os.path.dirname(os.path.dirname(f)) jdk = os.path.dirname(os.path.dirname(f))
if not os.path.islink(jdk): if not os.path.islink(jdk):
java_paths.append(jdk) java_paths.append(jdk)