summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier Jardón <javier.jardon@codethink.co.uk>2015-03-12 14:27:15 +0000
committerJavier Jardón <jjardon@gnome.org>2015-03-17 11:24:39 +0000
commitbae41ec8678ce8217d5f7f09abfe330b3a910a1d (patch)
treef26be7559e7e08cefa754a6a66c066079319f3f7
parent9987fccdfc113670e323f40a58f22c69328833a7 (diff)
downloadmorph-bae41ec8678ce8217d5f7f09abfe330b3a910a1d.tar.gz
morphlib/sourceresolver.py: parse VERSION file in a function
Change-Id: I6e714d1994632875a5a15f840fe8ab3a66dddc77
-rw-r--r--morphlib/sourceresolver.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/morphlib/sourceresolver.py b/morphlib/sourceresolver.py
index 97d3e422..1e64c23a 100644
--- a/morphlib/sourceresolver.py
+++ b/morphlib/sourceresolver.py
@@ -346,15 +346,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:
@@ -362,6 +367,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)