diff options
author | Mark Hatle <mark.hatle@windriver.com> | 2018-10-11 17:18:33 -0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-10-18 10:59:26 +0100 |
commit | b33c179aa978b6145c5c73c6ce545f9a68ffca28 (patch) | |
tree | 106e4a5392b52b0e6e9c84872aacdb8d6e1ee511 /bitbake/lib/layerindexlib | |
parent | 64fe513327837d0ac7603b76558c791db28c73f1 (diff) | |
download | poky-b33c179aa978b6145c5c73c6ce545f9a68ffca28.tar.gz |
bitbake: layerindexlib: Fix various type checking errors
In the list_obj function, we can't check if the requested object is 'in',
the index data -- as it's actually an attribute of the object. Move to hasattr.
The remaining items were incorrect usages of 'type' for class type comparison.
Instead move to 'isinstance'. Remaing 'type' comparisons are still valid. The
code was also reordered slightly to avoid a lot of:
if not isinstance(x, y):
...
else:
...
reordering it removes the not and makes the code slightly easier to read.
(Bitbake rev: cddea4282820ef10ad4863d87327891ea9383916)
Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/layerindexlib')
-rw-r--r-- | bitbake/lib/layerindexlib/__init__.py | 51 | ||||
-rw-r--r-- | bitbake/lib/layerindexlib/cooker.py | 19 |
2 files changed, 36 insertions, 34 deletions
diff --git a/bitbake/lib/layerindexlib/__init__.py b/bitbake/lib/layerindexlib/__init__.py index 74f3e2e93e..cb79cb37d7 100644 --- a/bitbake/lib/layerindexlib/__init__.py +++ b/bitbake/lib/layerindexlib/__init__.py | |||
@@ -448,7 +448,7 @@ layerBranches set. If not, they are effectively blank.''' | |||
448 | This function is used to implement debugging and provide the user info. | 448 | This function is used to implement debugging and provide the user info. |
449 | ''' | 449 | ''' |
450 | for lix in self.indexes: | 450 | for lix in self.indexes: |
451 | if object not in lix: | 451 | if not hasattr(lix, object): |
452 | continue | 452 | continue |
453 | 453 | ||
454 | logger.plain ('') | 454 | logger.plain ('') |
@@ -1046,15 +1046,15 @@ class LayerBranch(LayerIndexItemObj): | |||
1046 | self.id = id | 1046 | self.id = id |
1047 | self.collection = collection | 1047 | self.collection = collection |
1048 | self.version = version | 1048 | self.version = version |
1049 | if type(layer) != type(LayerItem): | 1049 | if isinstance(layer, LayerItem): |
1050 | self.layer_id = layer | ||
1051 | else: | ||
1052 | self.layer = layer | 1050 | self.layer = layer |
1053 | |||
1054 | if type(branch) != type(Branch): | ||
1055 | self.branch_id = branch | ||
1056 | else: | 1051 | else: |
1052 | self.layer_id = layer | ||
1053 | |||
1054 | if isinstance(branch, Branch): | ||
1057 | self.branch = branch | 1055 | self.branch = branch |
1056 | else: | ||
1057 | self.branch_id = branch | ||
1058 | 1058 | ||
1059 | self.vcs_subdir = vcs_subdir | 1059 | self.vcs_subdir = vcs_subdir |
1060 | self.vcs_last_fetch = vcs_last_fetch | 1060 | self.vcs_last_fetch = vcs_last_fetch |
@@ -1088,7 +1088,7 @@ class LayerBranch(LayerIndexItemObj): | |||
1088 | 1088 | ||
1089 | @layer.setter | 1089 | @layer.setter |
1090 | def layer(self, value): | 1090 | def layer(self, value): |
1091 | if type(value) != type(LayerItem): | 1091 | if not isinstance(value, LayerItem): |
1092 | raise TypeError('value is not a LayerItem') | 1092 | raise TypeError('value is not a LayerItem') |
1093 | if self.index != value.index: | 1093 | if self.index != value.index: |
1094 | raise AttributeError('Object and value do not share the same index and thus key set.') | 1094 | raise AttributeError('Object and value do not share the same index and thus key set.') |
@@ -1122,7 +1122,7 @@ class LayerBranch(LayerIndexItemObj): | |||
1122 | 1122 | ||
1123 | @branch.setter | 1123 | @branch.setter |
1124 | def branch(self, value): | 1124 | def branch(self, value): |
1125 | if type(value) != type(LayerItem): | 1125 | if not isinstance(value, LayerItem): |
1126 | raise TypeError('value is not a LayerItem') | 1126 | raise TypeError('value is not a LayerItem') |
1127 | if self.index != value.index: | 1127 | if self.index != value.index: |
1128 | raise AttributeError('Object and value do not share the same index and thus key set.') | 1128 | raise AttributeError('Object and value do not share the same index and thus key set.') |
@@ -1181,7 +1181,7 @@ class LayerIndexItemObj_LayerBranch(LayerIndexItemObj): | |||
1181 | 1181 | ||
1182 | @layerbranch.setter | 1182 | @layerbranch.setter |
1183 | def layerbranch(self, value): | 1183 | def layerbranch(self, value): |
1184 | if type(value) != type(LayerBranch): | 1184 | if not isinstance(value, LayerBranch): |
1185 | raise TypeError('value (%s) is not a layerBranch' % type(value)) | 1185 | raise TypeError('value (%s) is not a layerBranch' % type(value)) |
1186 | if self.index != value.index: | 1186 | if self.index != value.index: |
1187 | raise AttributeError('Object and value do not share the same index and thus key set.') | 1187 | raise AttributeError('Object and value do not share the same index and thus key set.') |
@@ -1207,14 +1207,14 @@ class LayerIndexItemObj_LayerBranch(LayerIndexItemObj): | |||
1207 | class LayerDependency(LayerIndexItemObj_LayerBranch): | 1207 | class LayerDependency(LayerIndexItemObj_LayerBranch): |
1208 | def define_data(self, id, layerbranch, dependency, required=True): | 1208 | def define_data(self, id, layerbranch, dependency, required=True): |
1209 | self.id = id | 1209 | self.id = id |
1210 | if type(layerbranch) != type(LayerBranch): | 1210 | if isinstance(layerbranch, LayerBranch): |
1211 | self.layerbranch_id = layerbranch | ||
1212 | else: | ||
1213 | self.layerbranch = layerbranch | 1211 | self.layerbranch = layerbranch |
1214 | if type(dependency) != type(LayerDependency): | ||
1215 | self.dependency_id = dependency | ||
1216 | else: | 1212 | else: |
1213 | self.layerbranch_id = layerbranch | ||
1214 | if isinstance(dependency, LayerDependency): | ||
1217 | self.dependency = dependency | 1215 | self.dependency = dependency |
1216 | else: | ||
1217 | self.dependency_id = dependency | ||
1218 | self.required = required | 1218 | self.required = required |
1219 | 1219 | ||
1220 | @property | 1220 | @property |
@@ -1240,7 +1240,7 @@ class LayerDependency(LayerIndexItemObj_LayerBranch): | |||
1240 | 1240 | ||
1241 | @dependency.setter | 1241 | @dependency.setter |
1242 | def dependency(self, value): | 1242 | def dependency(self, value): |
1243 | if type(value) != type(LayerDependency): | 1243 | if not isinstance(value, LayerDependency): |
1244 | raise TypeError('value (%s) is not a dependency' % type(value)) | 1244 | raise TypeError('value (%s) is not a dependency' % type(value)) |
1245 | if self.index != value.index: | 1245 | if self.index != value.index: |
1246 | raise AttributeError('Object and value do not share the same index and thus key set.') | 1246 | raise AttributeError('Object and value do not share the same index and thus key set.') |
@@ -1288,10 +1288,10 @@ class Recipe(LayerIndexItemObj_LayerBranch): | |||
1288 | self.inherits = inherits | 1288 | self.inherits = inherits |
1289 | self.updated = updated or datetime.datetime.today().isoformat() | 1289 | self.updated = updated or datetime.datetime.today().isoformat() |
1290 | self.blacklisted = blacklisted | 1290 | self.blacklisted = blacklisted |
1291 | if type(layerbranch) != type(LayerBranch): | 1291 | if isinstance(layerbranch, LayerBranch): |
1292 | self.layerbranch_id = layerbranch | ||
1293 | else: | ||
1294 | self.layerbranch = layerbranch | 1292 | self.layerbranch = layerbranch |
1293 | else: | ||
1294 | self.layerbranch_id = layerbranch | ||
1295 | 1295 | ||
1296 | @property | 1296 | @property |
1297 | def fullpath(self): | 1297 | def fullpath(self): |
@@ -1324,10 +1324,10 @@ class Machine(LayerIndexItemObj_LayerBranch): | |||
1324 | self.id = id | 1324 | self.id = id |
1325 | self.name = name | 1325 | self.name = name |
1326 | self.description = description | 1326 | self.description = description |
1327 | if type(layerbranch) != type(LayerBranch): | 1327 | if isinstance(layerbranch, LayerBranch): |
1328 | self.layerbranch_id = layerbranch | ||
1329 | else: | ||
1330 | self.layerbranch = layerbranch | 1328 | self.layerbranch = layerbranch |
1329 | else: | ||
1330 | self.layerbranch_id = layerbranch | ||
1331 | self.updated = updated or datetime.datetime.today().isoformat() | 1331 | self.updated = updated or datetime.datetime.today().isoformat() |
1332 | 1332 | ||
1333 | class Distro(LayerIndexItemObj_LayerBranch): | 1333 | class Distro(LayerIndexItemObj_LayerBranch): |
@@ -1337,13 +1337,12 @@ class Distro(LayerIndexItemObj_LayerBranch): | |||
1337 | self.id = id | 1337 | self.id = id |
1338 | self.name = name | 1338 | self.name = name |
1339 | self.description = description | 1339 | self.description = description |
1340 | if type(layerbranch) != type(LayerBranch): | 1340 | if isinstance(layerbranch, LayerBranch): |
1341 | self.layerbranch_id = layerbranch | ||
1342 | else: | ||
1343 | self.layerbranch = layerbranch | 1341 | self.layerbranch = layerbranch |
1342 | else: | ||
1343 | self.layerbranch_id = layerbranch | ||
1344 | self.updated = updated or datetime.datetime.today().isoformat() | 1344 | self.updated = updated or datetime.datetime.today().isoformat() |
1345 | 1345 | ||
1346 | |||
1347 | # When performing certain actions, we may need to sort the data. | 1346 | # When performing certain actions, we may need to sort the data. |
1348 | # This will allow us to keep it consistent from run to run. | 1347 | # This will allow us to keep it consistent from run to run. |
1349 | def sort_entry(item): | 1348 | def sort_entry(item): |
diff --git a/bitbake/lib/layerindexlib/cooker.py b/bitbake/lib/layerindexlib/cooker.py index 248a597754..848f0e2ee2 100644 --- a/bitbake/lib/layerindexlib/cooker.py +++ b/bitbake/lib/layerindexlib/cooker.py | |||
@@ -136,10 +136,13 @@ class CookerPlugin(layerindexlib.plugin.IndexPlugin): | |||
136 | layerrev = self._run_command('git rev-parse HEAD', layerpath, default="<unknown>") | 136 | layerrev = self._run_command('git rev-parse HEAD', layerpath, default="<unknown>") |
137 | 137 | ||
138 | for remotes in self._run_command('git remote -v', layerpath, default="").split("\n"): | 138 | for remotes in self._run_command('git remote -v', layerpath, default="").split("\n"): |
139 | remote = remotes.split("\t")[1].split(" ")[0] | 139 | if not remotes: |
140 | if "(fetch)" == remotes.split("\t")[1].split(" ")[1]: | 140 | layerurl = self._handle_git_remote(layerpath) |
141 | layerurl = self._handle_git_remote(remote) | 141 | else: |
142 | break | 142 | remote = remotes.split("\t")[1].split(" ")[0] |
143 | if "(fetch)" == remotes.split("\t")[1].split(" ")[1]: | ||
144 | layerurl = self._handle_git_remote(remote) | ||
145 | break | ||
143 | 146 | ||
144 | layerItemId += 1 | 147 | layerItemId += 1 |
145 | index.layerItems[layerItemId] = layerindexlib.LayerItem(index, None) | 148 | index.layerItems[layerItemId] = layerindexlib.LayerItem(index, None) |
@@ -297,7 +300,7 @@ class CookerPlugin(layerindexlib.plugin.IndexPlugin): | |||
297 | 300 | ||
298 | for layerBranchId in index.layerBranches: | 301 | for layerBranchId in index.layerBranches: |
299 | # load_bblayers uses the description to cache the actual path... | 302 | # load_bblayers uses the description to cache the actual path... |
300 | machine_path = index.layerBranches[layerBranchId].getDescription() | 303 | machine_path = index.layerBranches[layerBranchId].layer.description |
301 | machine_path = os.path.join(machine_path, 'conf/machine') | 304 | machine_path = os.path.join(machine_path, 'conf/machine') |
302 | if os.path.isdir(machine_path): | 305 | if os.path.isdir(machine_path): |
303 | for (dirpath, _, filenames) in os.walk(machine_path): | 306 | for (dirpath, _, filenames) in os.walk(machine_path): |
@@ -310,7 +313,7 @@ class CookerPlugin(layerindexlib.plugin.IndexPlugin): | |||
310 | machine = layerindexlib.Machine(index, None) | 313 | machine = layerindexlib.Machine(index, None) |
311 | machine.define_data(id=machineId, name=fname[:-5], | 314 | machine.define_data(id=machineId, name=fname[:-5], |
312 | description=fname[:-5], | 315 | description=fname[:-5], |
313 | layerbranch=collection_layerbranch[entry]) | 316 | layerbranch=index.layerBranches[layerBranchId]) |
314 | 317 | ||
315 | index.add_element("machines", [machine]) | 318 | index.add_element("machines", [machine]) |
316 | 319 | ||
@@ -321,7 +324,7 @@ class CookerPlugin(layerindexlib.plugin.IndexPlugin): | |||
321 | 324 | ||
322 | for layerBranchId in index.layerBranches: | 325 | for layerBranchId in index.layerBranches: |
323 | # load_bblayers uses the description to cache the actual path... | 326 | # load_bblayers uses the description to cache the actual path... |
324 | distro_path = index.layerBranches[layerBranchId].getDescription() | 327 | distro_path = index.layerBranches[layerBranchId].layer.description |
325 | distro_path = os.path.join(distro_path, 'conf/distro') | 328 | distro_path = os.path.join(distro_path, 'conf/distro') |
326 | if os.path.isdir(distro_path): | 329 | if os.path.isdir(distro_path): |
327 | for (dirpath, _, filenames) in os.walk(distro_path): | 330 | for (dirpath, _, filenames) in os.walk(distro_path): |
@@ -334,7 +337,7 @@ class CookerPlugin(layerindexlib.plugin.IndexPlugin): | |||
334 | distro = layerindexlib.Distro(index, None) | 337 | distro = layerindexlib.Distro(index, None) |
335 | distro.define_data(id=distroId, name=fname[:-5], | 338 | distro.define_data(id=distroId, name=fname[:-5], |
336 | description=fname[:-5], | 339 | description=fname[:-5], |
337 | layerbranch=collection_layerbranch[entry]) | 340 | layerbranch=index.layerBranches[layerBranchId]) |
338 | 341 | ||
339 | index.add_element("distros", [distro]) | 342 | index.add_element("distros", [distro]) |
340 | 343 | ||