diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-10-01 16:20:31 +0100 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-10-01 16:20:31 +0100 |
commit | 3951387f3e8840abc779eb2ec1085b7c195710bc (patch) | |
tree | 11c0ad2b009c54c146943ef037d3ff173c143b54 | |
parent | c1b4d19515b86d3216a6db3cebaf24ff16b2a0bb (diff) | |
download | lorry-controller-3951387f3e8840abc779eb2ec1085b7c195710bc.tar.gz |
Save the lorries for later
-rw-r--r-- | lorrycontroller/confparser.py | 27 |
1 files 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) |