diff options
author | Alexandru DAMIAN <alexandru.damian@intel.com> | 2014-11-25 16:12:05 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-11-28 14:02:58 +0000 |
commit | 5790337cec89f9c848e706e5c305ee83ac76496c (patch) | |
tree | 945d3e81f053719c6ae6cc379d429c9f7658c709 /bitbake/lib/toaster | |
parent | d9644d49fd72a7489982de551de0d0df73ac6d57 (diff) | |
download | poky-5790337cec89f9c848e706e5c305ee83ac76496c.tar.gz |
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 <alexandru.damian@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster')
-rw-r--r-- | bitbake/lib/toaster/bldcontrol/management/commands/loadconf.py | 42 | ||||
-rw-r--r-- | 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 | |||
5 | 5 | ||
6 | from checksettings import DN | 6 | from checksettings import DN |
7 | 7 | ||
8 | def _reduce_canon_path(path): | ||
9 | components = [] | ||
10 | for c in path.split("/"): | ||
11 | if c == "..": | ||
12 | del components[-1] | ||
13 | elif c == ".": | ||
14 | pass | ||
15 | else: | ||
16 | components.append(c) | ||
17 | if len(components) < 2: | ||
18 | components.append('') | ||
19 | return "/".join(components) | ||
20 | |||
21 | def _get_id_for_sourcetype(s): | ||
22 | for i in LayerSource.SOURCE_TYPE: | ||
23 | if s == i[1]: | ||
24 | return i[0] | ||
25 | raise Exception("Could not find definition for sourcetype " + s) | ||
26 | |||
8 | class Command(BaseCommand): | 27 | class Command(BaseCommand): |
9 | help = "Loads a toasterconf.json file in the database" | 28 | help = "Loads a toasterconf.json file in the database" |
10 | args = "filepath" | 29 | args = "filepath" |
11 | 30 | ||
12 | def _reduce_canon_path(self, path): | ||
13 | components = [] | ||
14 | for c in path.split("/"): | ||
15 | if c == "..": | ||
16 | del components[-1] | ||
17 | elif c == ".": | ||
18 | pass | ||
19 | else: | ||
20 | components.append(c) | ||
21 | return "/".join(components) | ||
22 | 31 | ||
23 | 32 | ||
24 | def _import_layer_config(self, filepath): | 33 | def _import_layer_config(self, filepath): |
@@ -71,16 +80,13 @@ class Command(BaseCommand): | |||
71 | assert 'name' in lsi | 80 | assert 'name' in lsi |
72 | assert 'branches' in lsi | 81 | assert 'branches' in lsi |
73 | 82 | ||
74 | def _get_id_for_sourcetype(s): | ||
75 | for i in LayerSource.SOURCE_TYPE: | ||
76 | if s == i[1]: | ||
77 | return i[0] | ||
78 | raise Exception("Could not find definition for sourcetype " + s) | ||
79 | 83 | ||
80 | if _get_id_for_sourcetype(lsi['sourcetype']) == LayerSource.TYPE_LAYERINDEX or lsi['apiurl'].startswith("/"): | 84 | if _get_id_for_sourcetype(lsi['sourcetype']) == LayerSource.TYPE_LAYERINDEX or lsi['apiurl'].startswith("/"): |
81 | apiurl = lsi['apiurl'] | 85 | apiurl = lsi['apiurl'] |
82 | else: | 86 | else: |
83 | apiurl = self._reduce_canon_path(os.path.join(DN(filepath), lsi['apiurl'])) | 87 | apiurl = _reduce_canon_path(os.path.join(DN(os.path.abspath(filepath)), lsi['apiurl'])) |
88 | |||
89 | assert ((_get_id_for_sourcetype(lsi['sourcetype']) == LayerSource.TYPE_LAYERINDEX) or apiurl.startswith("/")), (lsi['sourcetype'],apiurl) | ||
84 | 90 | ||
85 | try: | 91 | try: |
86 | ls = LayerSource.objects.get(sourcetype = _get_id_for_sourcetype(lsi['sourcetype']), apiurl = apiurl) | 92 | ls = LayerSource.objects.get(sourcetype = _get_id_for_sourcetype(lsi['sourcetype']), apiurl = apiurl) |
@@ -102,7 +108,7 @@ class Command(BaseCommand): | |||
102 | if layerinfo['local_path'].startswith("/"): | 108 | if layerinfo['local_path'].startswith("/"): |
103 | lo.local_path = layerinfo['local_path'] | 109 | lo.local_path = layerinfo['local_path'] |
104 | else: | 110 | else: |
105 | lo.local_path = self._reduce_canon_path(os.path.join(DN(DN(DN(filepath))), layerinfo['local_path'])) | 111 | lo.local_path = _reduce_canon_path(os.path.join(ls.apiurl, layerinfo['local_path'])) |
106 | 112 | ||
107 | if not os.path.exists(lo.local_path): | 113 | if not os.path.exists(lo.local_path): |
108 | raise Exception("Local layer path %s must exists." % lo.local_path) | 114 | raise Exception("Local layer path %s must exists." % lo.local_path) |
@@ -110,6 +116,8 @@ class Command(BaseCommand): | |||
110 | lo.vcs_url = layerinfo['vcs_url'] | 116 | lo.vcs_url = layerinfo['vcs_url'] |
111 | if layerinfo['vcs_url'].startswith("remote:"): | 117 | if layerinfo['vcs_url'].startswith("remote:"): |
112 | lo.vcs_url = _read_git_url_from_local_repository(layerinfo['vcs_url']) | 118 | lo.vcs_url = _read_git_url_from_local_repository(layerinfo['vcs_url']) |
119 | else: | ||
120 | lo.vcs_url = layerinfo['vcs_url'] | ||
113 | 121 | ||
114 | if 'layer_index_url' in layerinfo: | 122 | if 'layer_index_url' in layerinfo: |
115 | lo.layer_index_url = layerinfo['layer_index_url'] | 123 | 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): | |||
141 | self.assertTrue(br.state == BuildRequest.REQ_INPROGRESS, "Request is not updated") | 141 | self.assertTrue(br.state == BuildRequest.REQ_INPROGRESS, "Request is not updated") |
142 | # no more selections possible here | 142 | # no more selections possible here |
143 | self.assertRaises(IndexError, command._selectBuildRequest) | 143 | self.assertRaises(IndexError, command._selectBuildRequest) |
144 | |||
145 | |||
146 | class UtilityTests(TestCase): | ||
147 | def test_reduce_path(self): | ||
148 | from bldcontrol.management.commands.loadconf import _reduce_canon_path, _get_id_for_sourcetype | ||
149 | |||
150 | self.assertTrue( _reduce_canon_path("/") == "/") | ||
151 | self.assertTrue( _reduce_canon_path("/home/..") == "/") | ||
152 | self.assertTrue( _reduce_canon_path("/home/../ana") == "/ana") | ||
153 | self.assertTrue( _reduce_canon_path("/home/../ana/..") == "/") | ||
154 | self.assertTrue( _reduce_canon_path("/home/ana/mihai/../maria") == "/home/ana/maria") | ||
155 | |||
156 | def test_get_id_for_sorucetype(self): | ||
157 | from bldcontrol.management.commands.loadconf import _reduce_canon_path, _get_id_for_sourcetype | ||
158 | self.assertTrue( _get_id_for_sourcetype("layerindex") == 1) | ||
159 | self.assertTrue( _get_id_for_sourcetype("local") == 0) | ||
160 | self.assertTrue( _get_id_for_sourcetype("imported") == 2) | ||
161 | with self.assertRaises(Exception): | ||
162 | _get_id_for_sourcetype("unknown") | ||