summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-04-22 14:33:13 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2014-04-22 14:33:13 +0000
commit9cf8249d8cf06ee9be78cd89bb483ac05bdf66b6 (patch)
tree44166498e7f80a57ce0fa5026e6f1f20d26326a2
parent6d9e9fc255662707442bd16ac696c5804ff08a85 (diff)
downloadlorry-controller-9cf8249d8cf06ee9be78cd89bb483ac05bdf66b6.tar.gz
Move new_gitano_command to a function; add LocalTroveGitanoCommand
This clean up the code a bit, by not making LorryControllerRoute have less code in it that is unrelated to routing web requests.
-rw-r--r--lorrycontroller/__init__.py6
-rw-r--r--lorrycontroller/gitano.py23
-rw-r--r--lorrycontroller/givemejob.py6
-rw-r--r--lorrycontroller/lstroves.py2
-rw-r--r--lorrycontroller/route.py8
5 files changed, 32 insertions, 13 deletions
diff --git a/lorrycontroller/__init__.py b/lorrycontroller/__init__.py
index 9dd6496..bc51b88 100644
--- a/lorrycontroller/__init__.py
+++ b/lorrycontroller/__init__.py
@@ -36,7 +36,11 @@ from removejob import RemoveJob
from lstroves import LsTroves, ForceLsTrove
from pretendtime import PretendTime
from maxjobs import GetMaxJobs, SetMaxJobs
-from gitano import GitanoCommand, GitanoCommandFailure
+from gitano import (
+ GitanoCommand,
+ LocalTroveGitanoCommand,
+ GitanoCommandFailure,
+ new_gitano_command)
from static import StaticFile
from proxy import setup_proxy
diff --git a/lorrycontroller/gitano.py b/lorrycontroller/gitano.py
index b2c9123..2de291c 100644
--- a/lorrycontroller/gitano.py
+++ b/lorrycontroller/gitano.py
@@ -128,3 +128,26 @@ class GitanoCommand(object):
self.trovehost, ' '.join(gitano_args), str(e))
return response.read()
+
+
+class LocalTroveGitanoCommand(GitanoCommand):
+
+ '''Run commands on the local Trove's Gitano.
+
+ This is a version of the GitanoCommand class specifically for
+ accessing the local Trove's Gitano.
+
+ '''
+
+ def __init__(self):
+ GitanoCommand.__init__(self, 'localhost', 'ssh', '', '')
+
+
+
+def new_gitano_command(statedb, trovehost):
+ trove_info = statedb.get_trove_info(trovehost)
+ return lorrycontroller.GitanoCommand(
+ trovehost,
+ trove_info['protocol'],
+ trove_info['username'],
+ trove_info['password'])
diff --git a/lorrycontroller/givemejob.py b/lorrycontroller/givemejob.py
index 43abcc8..067f3c3 100644
--- a/lorrycontroller/givemejob.py
+++ b/lorrycontroller/givemejob.py
@@ -73,7 +73,7 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute):
# it failed because the repository already existed, and
# ignore the failure (but log message).
- local = lorrycontroller.GitanoCommand('localhost', 'ssh', None, None)
+ local = lorrycontroller.LocalTroveGitanoCommand()
try:
local.create(lorry_info['path'])
except lorrycontroller.GitanoCommandFailure as e:
@@ -89,8 +89,8 @@ class GiveMeJob(lorrycontroller.LorryControllerRoute):
assert lorry_info['from_trovehost']
assert lorry_info['from_path']
- remote = self.new_gitano_command(statedb, lorry_info['from_trovehost'])
- local = lorrycontroller.GitanoCommand('localhost', 'ssh', None, None)
+ remote = lorrycontroller.new_gitano_command(statedb, lorry_info['from_trovehost'])
+ local = lorrycontroller.LocalTroveGitanoCommand()
try:
remote_config = remote.get_gitano_config(lorry_info['from_path'])
diff --git a/lorrycontroller/lstroves.py b/lorrycontroller/lstroves.py
index 1f10209..10062ab 100644
--- a/lorrycontroller/lstroves.py
+++ b/lorrycontroller/lstroves.py
@@ -70,7 +70,7 @@ class TroveRepositoryLister(object):
return None
def get_real_ls_output(self, statedb, trove_info):
- gitano = self.route.new_gitano_command(statedb, trove_info['trovehost'])
+ gitano = lorrycontroller.new_gitano_command(statedb, trove_info['trovehost'])
output = gitano.ls()
return self.parse_ls_output(output)
diff --git a/lorrycontroller/route.py b/lorrycontroller/route.py
index 1eb4e5b..91a406e 100644
--- a/lorrycontroller/route.py
+++ b/lorrycontroller/route.py
@@ -41,13 +41,5 @@ class LorryControllerRoute(object):
def open_statedb(self):
return lorrycontroller.StateDB(self.app_settings['statedb'])
- def new_gitano_command(self, statedb, trovehost):
- trove_info = statedb.get_trove_info(trovehost)
- return lorrycontroller.GitanoCommand(
- trovehost,
- trove_info['protocol'],
- trove_info['username'],
- trove_info['password'])
-
def run(self, **kwargs):
raise NotImplementedError()