diff options
author | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-10-02 11:32:44 +0100 |
---|---|---|
committer | Daniel Silverstone <daniel.silverstone@codethink.co.uk> | 2012-10-02 11:32:44 +0100 |
commit | 76aaa8ec8794d26af3c66de3d8956e5f90f9ec74 (patch) | |
tree | f45e0ded6cbbbcddc5bbf3a568b99f6453707763 | |
parent | 1b82571cf0373ca6928fc1757c626fe9dbc6c77b (diff) | |
download | lorry-controller-76aaa8ec8794d26af3c66de3d8956e5f90f9ec74.tar.gz |
Add dry-run capability
-rwxr-xr-x | lorry-controller | 27 | ||||
-rw-r--r-- | lorrycontroller/workingstate.py | 6 |
2 files changed, 23 insertions, 10 deletions
diff --git a/lorry-controller b/lorry-controller index 3d30776..9d96b9a 100755 --- a/lorry-controller +++ b/lorry-controller @@ -39,7 +39,7 @@ class LorryController(cliapp.Application): default=defaults['config-name']) self.settings.boolean(['lorry-verbose'], 'Whether to pass --verbose to lorry', - default=True) + default=False) self.settings.string(['lorry-log'], 'Log file name for lorry if wanted', metavar='LORRYLOG', @@ -103,14 +103,22 @@ class LorryController(cliapp.Application): lorry = self.conf.lorries[new_lorry] nextdue = self.conf.duetimes[new_lorry] should_create = conf['create'] == "always" + store_state = True if should_create: - self.maybe_runcmd(["ssh", "git@localhost", - "create", new_lorry]) - mgr.lorry_state[new_lorry] = { - 'conf': conf, - 'lorry': lorry, - 'next-due': nextdue, - } + exit, out, err = self.maybe_runcmd(["ssh", "git@localhost", + "create", new_lorry]) + if exit != 0: + logging.info("Unable to create repo %s" % new_lorry) + store_state = False + if store_state: + mgr.lorry_state[new_lorry] = { + 'conf': conf, + 'lorry': lorry, + 'next-due': nextdue, + } + else: + # Remove this from cur_lorries so we don't run it + cur_lorries.remove(new_lorry) # 3. For every lorry we have, update the settings if necessary. # and reset the next-due as appropriate. @@ -157,9 +165,10 @@ class LorryController(cliapp.Application): def maybe_runcmd(self, *args, **kwargs): if not self.settings['dry-run']: - return self.runcmd(*args, **kwargs) + return self.runcmd_unchecked(*args, **kwargs) else: logging.debug("DRY-RUN: Not running %r" % args) + return 0, 'DRY-RUN', 'DRY-RUN' if __name__ == '__main__': LorryController(version='1').run() diff --git a/lorrycontroller/workingstate.py b/lorrycontroller/workingstate.py index 239ee1f..2064005 100644 --- a/lorrycontroller/workingstate.py +++ b/lorrycontroller/workingstate.py @@ -32,7 +32,11 @@ class LorryFileRunner(object): def run_lorry(self, *args): cmdargs = list(args) cmdargs.append(self.lorryfile) - self.mgr.app.maybe_runcmd(cmdargs) + exit, out, err = self.mgr.app.maybe_runcmd(cmdargs) + if exit == 0: + logging.info("Lorry of %s succeeded: %s" % (self.lorryname, out)) + else: + logging.warn("Lorry of %s failed: %s" % (self.lorryname, err)) class WorkingStateManager(object): '''Manage the working state of lorry-controller''' |