summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-03-31 14:20:53 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-03-31 14:20:53 +0000
commit4e61f9cab2b7a5cbacbc7169027753e01cfc3a54 (patch)
tree2016c795e006c209a967d0b2bda8a062b15b68b6
parentc3c2e577ed7e052b788eab4757b30cdfb80208c2 (diff)
downloadlorry-controller-4e61f9cab2b7a5cbacbc7169027753e01cfc3a54.tar.gz
Use GitanoCommand in giveme job
-rw-r--r--lorrycontroller/givemejob.py59
1 files changed, 14 insertions, 45 deletions
diff --git a/lorrycontroller/givemejob.py b/lorrycontroller/givemejob.py
index e40de5f..a60da88 100644
--- a/lorrycontroller/givemejob.py
+++ b/lorrycontroller/givemejob.py
@@ -25,13 +25,6 @@ import cliapp
import lorrycontroller
-class GitanoCommandFailure(Exception):
-
- def __init__(self, trovehost, command):
- Exception.__init__(
- self, 'Failed to run "%s" on Gitano on %s' % (command, trovehost))
-
-
class GiveMeJob(lorrycontroller.LorryControllerRoute):
http_method = 'POST'
@@ -93,55 +86,31 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute):
assert lorry_info['from_trovehost']
assert lorry_info['from_path']
+ remote = lorrycontroller.GitanoCommand(lorry_info['from_trovehost'])
+ local = lorrycontroller.GitanoCommand('localhost')
+
try:
- remote_config = self.get_gitano_config(
- lorry_info['from_trovehost'], lorry_info['from_path'])
- local_config = self.get_gitano_config('localhost', lorry_info['path'])
+ remote_config = remote.get_gitano_config(lorry_info['from_path'])
+ local_config = local.get_gitano_config(lorry_info['path'])
if remote_config['project.head'] != local_config['project.head']:
- self.set_gitano_config(
- 'localhost', lorry_info['path'],
- 'project.head', remote_config['project.head'])
+ local.set_gitano_config(
+ lorry_info['path'],
+ 'project.head',
+ remote_config['project.head'])
if not local_config['project.description']:
desc = '{host}: {desc}'.format(
host=lorry_info['from_trovehost'],
desc=remote_config['project.description'])
- self.set_gitano_config(
- 'localhost', lorry_info['path'],
- 'project.description', desc)
- except GitanoCommandFailure as e:
+ local.set_gitano_config(
+ lorry_info['path'],
+ 'project.description',
+ desc)
+ except lorrycontroller.GitanoCommandFailure as e:
logging.error('ERROR: %s' % str(e))
bottle.abort(500)
- def get_gitano_config(self, trovehost, repo_path):
- exit, stdout, stderr = cliapp.runcmd_unchecked(
- ['ssh', 'git@%s' % trovehost,
- 'config', cliapp.shell_quote(repo_path), 'show'])
-
- if exit:
- raise GitanoCommandFailure(trovehost, 'config show')
-
- # "config REPO show" outputs a sequence of lines of the form "key: value".
- # Extract those into a collections.defaultdict.
-
- result = collections.defaultdict(str)
- for line in stdout.splitlines():
- m = re.match(r'^([^:])+:\s*(.*)$', line)
- if m:
- result[m.group(0)] = m.group(1).strip()
-
- return result
-
- def set_gitano_config(self, trovehost, repo_path, key, value):
- exit, stdout, stderr = cliapp.runcmd_unchecked(
- ['ssh', 'git@%s' % trovehost,
- 'config', cliapp.shell_quote(repo_path),
- 'set', cliapp.shell_quote(key), cliapp.shell_quote(value)])
-
- if exit:
- raise GitanoCommandFailure(trovehost, 'config set')
-
def give_job_to_minion(self, statedb, lorry_info, now):
path = lorry_info['path']
minion_host = bottle.request.forms.host