diff options
author | Javier Jardón <javier.jardon@codethink.co.uk> | 2015-03-12 17:06:17 +0000 |
---|---|---|
committer | Javier Jardón <jjardon@gnome.org> | 2015-03-17 11:24:23 +0000 |
commit | 9987fccdfc113670e323f40a58f22c69328833a7 (patch) | |
tree | 0ac9d09f98d7a7987d73ba53dbba6d3784589f1c | |
parent | cd7fa4119a3850541566b7d20d69515256e0b310 (diff) | |
download | morph-9987fccdfc113670e323f40a58f22c69328833a7.tar.gz |
morphlib/sourceresolver.py: Fail if morph doesnt support the version of definitions formatbaserock-definitions-v1
This patch will add the following restriction:
if VERSION exist
and its a YAML file
and its a dict
and has the key 'version'
and the type stored in the 'version' key is an int
and that int is not in the supported format,
then fail.
So, if someone is using 'version: 4' in VERSION, morph will fail (as
opposed to current morph, that will not fail in the check but will
likely fail when it tries to compile)
Change-Id: I555f7e6018b9bdf18c80039df92a253acbd51c8c
-rw-r--r-- | morphlib/sourceresolver.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/morphlib/sourceresolver.py b/morphlib/sourceresolver.py index d2b47d35..97d3e422 100644 --- a/morphlib/sourceresolver.py +++ b/morphlib/sourceresolver.py @@ -31,7 +31,7 @@ tree_cache_filename = 'trees.cache.pickle' buildsystem_cache_size = 10000 buildsystem_cache_filename = 'detected-chunk-buildsystems.cache.pickle' -not_supported_versions = [] +supported_versions = [0, 1] class PickleCacheManager(object): # pragma: no cover '''Cache manager for PyLRU that reads and writes to Pickle files. @@ -354,13 +354,17 @@ class SourceResolver(object): if version_file is None: return - try: - version = yaml.safe_load(version_file)['version'] - except (yaml.error.YAMLError, KeyError, TypeError): - version = 0 - - if version in not_supported_versions: - raise UnknownVersionError(version) + version = None + yaml_obj = yaml.safe_load(version_file) + if yaml_obj is not None: + if type(yaml_obj) is dict: + if 'version' in yaml_obj.keys(): + if type(yaml_obj['version']) is int: + version = yaml_obj['version'] + + if version is not None: + if version not in supported_versions: + raise UnknownVersionError(version) def _process_definitions_with_children(self, system_filenames, definitions_repo, |