diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-10-02 10:26:45 +0100 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-10-02 10:26:45 +0100 |
commit | 8a4fdf418e9f5c156e1f72bfab56d5f1a41a3c8d (patch) | |
tree | cc07d24dbf8dcf25ee31caf585a81bf35874948f | |
parent | 1d4eba57f93d0ed561bd05053079f3256ed645bd (diff) | |
download | lorry-controller-8a4fdf418e9f5c156e1f72bfab56d5f1a41a3c8d.tar.gz |
Running lorry
-rwxr-xr-x | lorry-controller | 17 | ||||
-rw-r--r-- | lorrycontroller/workingstate.py | 31 |
2 files changed, 47 insertions, 1 deletions
diff --git a/lorry-controller b/lorry-controller index 06dcea1..3ba576f 100755 --- a/lorry-controller +++ b/lorry-controller @@ -33,6 +33,13 @@ class LorryController(cliapp.Application): 'lorry-controller.conf', metavar='CONFNAME', default=defaults['config-name']) + self.settings.boolean(['lorry-verbose'], + 'Whether to pass --verbose to lorry' + default=True) + self.settings.string(['lorry-log'], + 'Log file name for lorry if wanted' + metaval='LORRYLOG', + default=None) def process_args(self, args): logging.info("Starting to control lorry") @@ -53,6 +60,13 @@ class LorryController(cliapp.Application): self.rungit(['reset', '--hard', 'origin/master']) self.rungit(['clean', '-fdx']) + self.lorrycmd=[self.settings['lorry']] + if self.settings['lorry-verbose']: + self.lorrycmd += "--verbose" + if self.settings['lorry-log'] is not None: + self.lorrycmd += "--log" + self.lorrycmd += self.settings['lorry-log'] + if not os.path.exists(os.path.join('git', self.settings['config-name'])): logging.error("Unable to find lorry-controller.conf in git") @@ -119,7 +133,8 @@ class LorryController(cliapp.Application): due = state['next-due'] if now >= due: logging.debug("Running Lorry for: %s" % lorry) - # TODO: Actually run the lorry + with mgr.runner(lorry) as runner: + runner.run_lorry(*self.lorrycmd) while state['next-due'] <= now: state['next-due'] += state['conf']['interval-parsed'] lorried += 1 diff --git a/lorrycontroller/workingstate.py b/lorrycontroller/workingstate.py index 39d0065..acaf55b 100644 --- a/lorrycontroller/workingstate.py +++ b/lorrycontroller/workingstate.py @@ -4,6 +4,35 @@ import json import os import logging +import string + +class LorryFileRunner(object): + def __init__(self, mgr, lorryname): + self.mgr = mgr + self.lorryname = lorryname + self.lorryfile = os.path.join(self.mgr.workdir, + self._esc(lorryname) + ".lorry") + + def _esc(self, name): + valid_chars = string.digits + string.letters + '%_' + transl = lambda x: x if x in valid_chars else '_' + return ''.join([transl(x) for x in name]) + + def __enter__(self): + lorry_obj = { self.lorryname: + self.mgr.lorry_state[self.lorryname]['lorry'] } + with open(self.lorryfile, "w") as fh: + json.dump(lorry_obj, fh) + fh.write("\n") + return self + + def __exit__(self, exctype, excvalue, exctraceback): + os.unlink(self.lorryfile) + + def run_lorry(self, *args): + cmdargs = list(args) + cmdargs.append(self.lorryfile) + self.mgr.app.runcmd(cmdargs) class WorkingStateManager(object): '''Manage the working state of lorry-controller''' @@ -35,3 +64,5 @@ class WorkingStateManager(object): json.dump(self.lorry_state, fh, sort_keys=True, indent=4) fh.write("\n") + def runner(self, lorryname): + return LorryFileRunner(self, lorryname) |