diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-10-02 11:18:13 +0100 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-10-02 11:18:13 +0100 |
commit | 1b82571cf0373ca6928fc1757c626fe9dbc6c77b (patch) | |
tree | 2be017eddcc9a87123bbfde94fbe56dafe906a24 | |
parent | 8a4fdf418e9f5c156e1f72bfab56d5f1a41a3c8d (diff) | |
download | lorry-controller-1b82571cf0373ca6928fc1757c626fe9dbc6c77b.tar.gz |
Add a dry-run support
-rwxr-xr-x | lorry-controller | 23 | ||||
-rw-r--r-- | lorrycontroller/workingstate.py | 7 |
2 files changed, 21 insertions, 9 deletions
diff --git a/lorry-controller b/lorry-controller index 3ba576f..3d30776 100755 --- a/lorry-controller +++ b/lorry-controller @@ -24,6 +24,10 @@ class LorryController(cliapp.Application): 'path to the area for the controller to work in', metavar='PATH', default=defaults['work-area']) + self.settings.boolean(['dry-run'], + "do a dry-run and don't actually do anything " + "beyond updating the git tree", + default=False) self.settings.string(['lorry'], 'path to the lorry binary to use', metavar='LORRY', @@ -34,11 +38,11 @@ class LorryController(cliapp.Application): metavar='CONFNAME', default=defaults['config-name']) self.settings.boolean(['lorry-verbose'], - 'Whether to pass --verbose to lorry' + 'Whether to pass --verbose to lorry', default=True) self.settings.string(['lorry-log'], - 'Log file name for lorry if wanted' - metaval='LORRYLOG', + 'Log file name for lorry if wanted', + metavar='LORRYLOG', default=None) def process_args(self, args): @@ -62,10 +66,9 @@ class LorryController(cliapp.Application): self.lorrycmd=[self.settings['lorry']] if self.settings['lorry-verbose']: - self.lorrycmd += "--verbose" + self.lorrycmd += ["--verbose"] if self.settings['lorry-log'] is not None: - self.lorrycmd += "--log" - self.lorrycmd += self.settings['lorry-log'] + self.lorrycmd += ["--log", self.settings['lorry-log']] if not os.path.exists(os.path.join('git', self.settings['config-name'])): @@ -101,7 +104,8 @@ class LorryController(cliapp.Application): nextdue = self.conf.duetimes[new_lorry] should_create = conf['create'] == "always" if should_create: - logging.debug("TODO: Create in Trove") + self.maybe_runcmd(["ssh", "git@localhost", + "create", new_lorry]) mgr.lorry_state[new_lorry] = { 'conf': conf, 'lorry': lorry, @@ -151,6 +155,11 @@ class LorryController(cliapp.Application): self.runcmd(['git']+args, cwd=os.path.join(self.settings['work-area'], 'git')) + def maybe_runcmd(self, *args, **kwargs): + if not self.settings['dry-run']: + return self.runcmd(*args, **kwargs) + else: + logging.debug("DRY-RUN: Not running %r" % args) if __name__ == '__main__': LorryController(version='1').run() diff --git a/lorrycontroller/workingstate.py b/lorrycontroller/workingstate.py index acaf55b..239ee1f 100644 --- a/lorrycontroller/workingstate.py +++ b/lorrycontroller/workingstate.py @@ -32,7 +32,7 @@ class LorryFileRunner(object): def run_lorry(self, *args): cmdargs = list(args) cmdargs.append(self.lorryfile) - self.mgr.app.runcmd(cmdargs) + self.mgr.app.maybe_runcmd(cmdargs) class WorkingStateManager(object): '''Manage the working state of lorry-controller''' @@ -46,7 +46,10 @@ class WorkingStateManager(object): return self def __exit__(self, exctype, excvalue, exctraceback): - self.save_state() + if not self.app.settings['dry-run']: + self.save_state() + else: + logging.debug("DRY-RUN: Not saving state again") def _load_state(self): self.lorry_state_file = os.path.join(self.workdir, |