diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-07-30 17:18:56 +0000 |
---|---|---|
committer | Baserock Gerrit <gerrit@baserock.org> | 2015-08-18 13:22:01 +0000 |
commit | 12cb150d6b66ee6b23c81c36ad34a35e9c9cbdd5 (patch) | |
tree | fb4348357d3e96334a59389de1751b06de855dd4 /morphlib/sourceresolver.py | |
parent | c34838b5d7c613b6be24480de6104ee1270404f3 (diff) | |
download | morph-12cb150d6b66ee6b23c81c36ad34a35e9c9cbdd5.tar.gz |
Move definitions VERSION parsing code into its own definitions_version module
I need to use this outside of the 'sourceresolver' module. Also, the
'sourceresolver' module is too big.
Change-Id: I523bcc9555193b7369768441b72f1059e6adde5c
Diffstat (limited to 'morphlib/sourceresolver.py')
-rw-r--r-- | morphlib/sourceresolver.py | 50 |
1 files changed, 3 insertions, 47 deletions
diff --git a/morphlib/sourceresolver.py b/morphlib/sourceresolver.py index 3bfe5bfa..cbab0f7f 100644 --- a/morphlib/sourceresolver.py +++ b/morphlib/sourceresolver.py @@ -28,12 +28,12 @@ import cliapp import morphlib from morphlib.util import sanitise_morphology_path + tree_cache_size = 10000 tree_cache_filename = 'trees.cache.pickle' buildsystem_cache_size = 10000 buildsystem_cache_filename = 'detected-chunk-buildsystems.cache.pickle' -supported_versions = [3, 4, 5, 6] class PickleCacheManager(object): # pragma: no cover '''Cache manager for PyLRU that reads and writes to Pickle files. @@ -111,17 +111,6 @@ class MorphologyReferenceNotFoundError(SourceResolverError): # pragma: no cover % (filename, reference_file)) -class UnknownVersionError(SourceResolverError): # pragma: no cover - def __init__(self, version): - SourceResolverError.__init__( - self, "Definitions format version %s is not supported" % version) - - -class InvalidVersionFileError(SourceResolverError): #pragma: no cover - def __init__(self): - SourceResolverError.__init__(self, "invalid VERSION file") - - # Callers may want to give the user a special error message if we hit an # InvalidRefError in the definitions.git repo. Currently a separate exception # type seems the easiest way to do that, but adding enough detail to the @@ -294,44 +283,11 @@ class SourceResolver(object): return text - @staticmethod - def _parse_version_file(version_file): # pragma : no cover - '''Parse VERSION file and return the version of the format if: - - 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 - - otherwise returns None - - ''' - - yaml_obj = yaml.safe_load(version_file) - - return (yaml_obj['version'] if yaml_obj is not None - and isinstance(yaml_obj, dict) - and 'version' in yaml_obj - and isinstance(yaml_obj['version'], int) - - else None) - def _check_version_file(self, definitions_checkout_dir): # pragma: no cover - version_file = self._get_file_contents_from_definitions( + version_text = self._get_file_contents_from_definitions( definitions_checkout_dir, 'VERSION') - if version_file == None: - raise InvalidVersionFileError() - - version = self._parse_version_file(version_file) - - if version == None: - raise InvalidVersionFileError() - - if version not in supported_versions: - raise UnknownVersionError(version) - - return version + return morphlib.definitions_version.check_version_file(version_text) def _get_morphology(self, resolved_morphologies, definitions_checkout_dir, definitions_repo, definitions_absref, morph_loader, |