From 3951387f3e8840abc779eb2ec1085b7c195710bc Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Mon, 1 Oct 2012 16:20:31 +0100 Subject: Save the lorries for later --- lorrycontroller/confparser.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lorrycontroller/confparser.py b/lorrycontroller/confparser.py index ebe1316..6f18de6 100644 --- a/lorrycontroller/confparser.py +++ b/lorrycontroller/confparser.py @@ -29,6 +29,7 @@ class LorryControllerConfig(object): def __init__(self, settings, confpath): self.settings = settings + self.lorries = {} confpath = os.path.join(settings['work-area'], confpath) logging.debug("Parsing configuration: %s" % confpath) with open(confpath, "r") as fh: @@ -91,20 +92,34 @@ class LorryControllerConfig(object): '''Validate a 'lorries' stanza.''' if type(entry.get('globs', None)) != list: self._give_up("Lorries stanzas need lists for their 'globs'") - all_lorries = set() + my_lorries = set() git_base = os.path.join(self.settings['work-area'], 'git') for glob_entry in entry['globs']: if type(glob_entry) != unicode: self._give_up("Lorries globs should be strings") fullglob = os.path.join(git_base, glob_entry) - all_lorries = all_lorries.union(set(glob.iglob(fullglob))) - for lorry in all_lorries: + my_lorries = my_lorries.union(set(glob.iglob(fullglob))) + for lorry in my_lorries: if not lorry.startswith(git_base): self._give_up("Glob found %s which is outside the git base") - logging.debug("Expanded globs in entry to %d lorries" % - len(all_lorries)) - entry['lorries'] = all_lorries + logging.debug("Expanded globs in entry to %d lorry files" % + len(my_lorries)) + logging.debug("Loading lorries into memory, please wait...") + + for lorry in my_lorries: + try: + with open(lorry, "r") as fh: + lorry_json = json.load(fh) + for name, content in lorry_json.iteritems(): + if self.lorries.get(name, None) is not None: + self._give_up("Lorry repeated: %s" % name) + self.lorries[name] = content + except Exception, e: + logging.debug("Unable to parse %s, because of %s. Moving on" % + (lorry, e)) + + logging.debug("Now loaded %d lorries" % len(self.lorries.keys())) def _give_up(self, *args, **kwargs): logging.error(*args, **kwargs) -- cgit v1.2.1