diff options
author | Javier Jardón <javier.jardon@codethink.co.uk> | 2015-03-12 17:06:17 +0000 |
---|---|---|
committer | Javier Jardón <javier.jardon@codethink.co.uk> | 2015-03-12 17:06:17 +0000 |
commit | 090865ee82a24e8020d68ce9715c9d522faea148 (patch) | |
tree | 1c1f675fee48e5e090a1989c18cc9e907881763b | |
parent | 0761c88989af492ea2c48b9612cb856d53de3992 (diff) | |
download | morph-090865ee82a24e8020d68ce9715c9d522faea148.tar.gz |
morphlib/sourceresolver.py: Fail if morph doesnt support the version of definitions format
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)
-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 387d2e0d..55d11377 100644 --- a/morphlib/sourceresolver.py +++ b/morphlib/sourceresolver.py @@ -32,7 +32,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. @@ -353,13 +353,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, |