From 5790337cec89f9c848e706e5c305ee83ac76496c Mon Sep 17 00:00:00 2001 From: Alexandru DAMIAN Date: Tue, 25 Nov 2014 16:12:05 +0000 Subject: bitbake: toaster: fix loadconf path calculation Fixing the path calculation for local layer sources, as the path need to be absolute. Added tests for pieces of code. (Bitbake rev: e764834f3c7c7da9356fa11b62e1fa8f643986fc) Signed-off-by: Alexandru DAMIAN Signed-off-by: Richard Purdie --- .../bldcontrol/management/commands/loadconf.py | 42 +++++++++++++--------- bitbake/lib/toaster/bldcontrol/tests.py | 19 ++++++++++ 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py b/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py index 6e1f97a9f9..2257a7143b 100644 --- a/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py +++ b/bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py @@ -5,20 +5,29 @@ import os from checksettings import DN +def _reduce_canon_path(path): + components = [] + for c in path.split("/"): + if c == "..": + del components[-1] + elif c == ".": + pass + else: + components.append(c) + if len(components) < 2: + components.append('') + return "/".join(components) + +def _get_id_for_sourcetype(s): + for i in LayerSource.SOURCE_TYPE: + if s == i[1]: + return i[0] + raise Exception("Could not find definition for sourcetype " + s) + class Command(BaseCommand): help = "Loads a toasterconf.json file in the database" args = "filepath" - def _reduce_canon_path(self, path): - components = [] - for c in path.split("/"): - if c == "..": - del components[-1] - elif c == ".": - pass - else: - components.append(c) - return "/".join(components) def _import_layer_config(self, filepath): @@ -71,16 +80,13 @@ class Command(BaseCommand): assert 'name' in lsi assert 'branches' in lsi - def _get_id_for_sourcetype(s): - for i in LayerSource.SOURCE_TYPE: - if s == i[1]: - return i[0] - raise Exception("Could not find definition for sourcetype " + s) if _get_id_for_sourcetype(lsi['sourcetype']) == LayerSource.TYPE_LAYERINDEX or lsi['apiurl'].startswith("/"): apiurl = lsi['apiurl'] else: - apiurl = self._reduce_canon_path(os.path.join(DN(filepath), lsi['apiurl'])) + apiurl = _reduce_canon_path(os.path.join(DN(os.path.abspath(filepath)), lsi['apiurl'])) + + assert ((_get_id_for_sourcetype(lsi['sourcetype']) == LayerSource.TYPE_LAYERINDEX) or apiurl.startswith("/")), (lsi['sourcetype'],apiurl) try: ls = LayerSource.objects.get(sourcetype = _get_id_for_sourcetype(lsi['sourcetype']), apiurl = apiurl) @@ -102,7 +108,7 @@ class Command(BaseCommand): if layerinfo['local_path'].startswith("/"): lo.local_path = layerinfo['local_path'] else: - lo.local_path = self._reduce_canon_path(os.path.join(DN(DN(DN(filepath))), layerinfo['local_path'])) + lo.local_path = _reduce_canon_path(os.path.join(ls.apiurl, layerinfo['local_path'])) if not os.path.exists(lo.local_path): raise Exception("Local layer path %s must exists." % lo.local_path) @@ -110,6 +116,8 @@ class Command(BaseCommand): lo.vcs_url = layerinfo['vcs_url'] if layerinfo['vcs_url'].startswith("remote:"): lo.vcs_url = _read_git_url_from_local_repository(layerinfo['vcs_url']) + else: + lo.vcs_url = layerinfo['vcs_url'] if 'layer_index_url' in layerinfo: lo.layer_index_url = layerinfo['layer_index_url'] diff --git a/bitbake/lib/toaster/bldcontrol/tests.py b/bitbake/lib/toaster/bldcontrol/tests.py index 37d6524c36..5a9d1df37a 100644 --- a/bitbake/lib/toaster/bldcontrol/tests.py +++ b/bitbake/lib/toaster/bldcontrol/tests.py @@ -141,3 +141,22 @@ class RunBuildsCommandTests(TestCase): self.assertTrue(br.state == BuildRequest.REQ_INPROGRESS, "Request is not updated") # no more selections possible here self.assertRaises(IndexError, command._selectBuildRequest) + + +class UtilityTests(TestCase): + def test_reduce_path(self): + from bldcontrol.management.commands.loadconf import _reduce_canon_path, _get_id_for_sourcetype + + self.assertTrue( _reduce_canon_path("/") == "/") + self.assertTrue( _reduce_canon_path("/home/..") == "/") + self.assertTrue( _reduce_canon_path("/home/../ana") == "/ana") + self.assertTrue( _reduce_canon_path("/home/../ana/..") == "/") + self.assertTrue( _reduce_canon_path("/home/ana/mihai/../maria") == "/home/ana/maria") + + def test_get_id_for_sorucetype(self): + from bldcontrol.management.commands.loadconf import _reduce_canon_path, _get_id_for_sourcetype + self.assertTrue( _get_id_for_sourcetype("layerindex") == 1) + self.assertTrue( _get_id_for_sourcetype("local") == 0) + self.assertTrue( _get_id_for_sourcetype("imported") == 2) + with self.assertRaises(Exception): + _get_id_for_sourcetype("unknown") -- cgit v1.2.3-54-g00ecf