diff options
author | Javier Jardón <javier.jardon@codethink.co.uk> | 2015-03-12 14:27:15 +0000 |
---|---|---|
committer | Javier Jardón <javier.jardon@codethink.co.uk> | 2015-03-12 17:06:22 +0000 |
commit | 50b5ad995225903f5ab9b2b3205660bc4d12dbdf (patch) | |
tree | 7179557d2c87b6a84e70b1ac3899e0f70fc2d2f1 | |
parent | 090865ee82a24e8020d68ce9715c9d522faea148 (diff) | |
download | morph-jjardon/version_check.tar.gz |
morphlib/sourceresolver.py: parse VERSION file in a functionjjardon/version_check
-rw-r--r-- | morphlib/sourceresolver.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/morphlib/sourceresolver.py b/morphlib/sourceresolver.py index 55d11377..8d03fc5e 100644 --- a/morphlib/sourceresolver.py +++ b/morphlib/sourceresolver.py @@ -345,15 +345,20 @@ class SourceResolver(object): loader.set_defaults(morph) return morph - def _check_version_file(self,definitions_repo, - definitions_absref): # pragma: no cover - version_file = self._get_file_contents( - definitions_repo, definitions_absref, 'VERSION') + def _parse_version_file(self, version_file): # pragma : no cover + '''Parse VERSION file and return the version of the format if: - if version_file is None: - return + VERSION is a YAML file + and it's 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 + + otherwise returns None + ''' version = None + yaml_obj = yaml.safe_load(version_file) if yaml_obj is not None: if type(yaml_obj) is dict: @@ -361,6 +366,17 @@ class SourceResolver(object): if type(yaml_obj['version']) is int: version = yaml_obj['version'] + return version + + def _check_version_file(self,definitions_repo, + definitions_absref): # pragma: no cover + version_file = self._get_file_contents( + definitions_repo, definitions_absref, 'VERSION') + + if version_file is None: + return + + version = self._parse_version_file(version_file) if version is not None: if version not in supported_versions: raise UnknownVersionError(version) |