From c2d6bf758845076eca6eb71af09df77165993270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jard=C3=B3n?= Date: Mon, 2 Mar 2015 19:14:57 +0000 Subject: morphlib/sourceresolver.py: Check and parse VERSION file Only fail if: - VERSION file exists - and its a yaml file - and its a dict - and has the key 'version' - and the contents of the key 'version' is an int - and that int is in the list of non_supported_versions (empty at the moment) --- morphlib/sourceresolver.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/morphlib/sourceresolver.py b/morphlib/sourceresolver.py index f571d76b..387d2e0d 100644 --- a/morphlib/sourceresolver.py +++ b/morphlib/sourceresolver.py @@ -21,6 +21,7 @@ import os import pylru import shutil import tempfile +import yaml import cliapp @@ -31,6 +32,7 @@ tree_cache_filename = 'trees.cache.pickle' buildsystem_cache_size = 10000 buildsystem_cache_filename = 'detected-chunk-buildsystems.cache.pickle' +not_supported_versions = [] class PickleCacheManager(object): # pragma: no cover '''Cache manager for PyLRU that reads and writes to Pickle files. @@ -89,6 +91,11 @@ class MorphologyNotFoundError(SourceResolverError): # pragma: no cover SourceResolverError.__init__( self, "Couldn't find morphology: %s" % filename) +class UnknownVersionError(SourceResolverError): # pragma: no cover + def __init__(self, version): + SourceResolverError.__init__( + self, "Definitions format version %s is not supported" % version) + class SourceResolver(object): '''Provides a way of resolving the set of sources for a given system. @@ -338,6 +345,22 @@ 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') + + 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) + def _process_definitions_with_children(self, system_filenames, definitions_repo, definitions_ref, @@ -347,6 +370,8 @@ class SourceResolver(object): definitions_queue = collections.deque(system_filenames) chunk_queue = set() + self._check_version_file(definitions_repo, definitions_absref) + while definitions_queue: filename = definitions_queue.popleft() -- cgit v1.2.1