summaryrefslogtreecommitdiff
path: root/simplejenkinsapi
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2012-08-11 13:44:25 +0100
committerLars Wirzenius <liw@liw.fi>2012-08-11 13:44:25 +0100
commita1f71c9dd770e244fb4291c9c0bbd848f307be51 (patch)
tree3ddf5c1dab3e0c4f3f6ad8602b5f7db551fa8163 /simplejenkinsapi
parent29879292d46b23df8ef2a59b04f3653b8934a9b2 (diff)
downloadjenkinstool-a1f71c9dd770e244fb4291c9c0bbd848f307be51.tar.gz
Refactor things to reduce duplicated code
Diffstat (limited to 'simplejenkinsapi')
-rw-r--r--simplejenkinsapi/jobconfig.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/simplejenkinsapi/jobconfig.py b/simplejenkinsapi/jobconfig.py
index 1dbf89c..789b894 100644
--- a/simplejenkinsapi/jobconfig.py
+++ b/simplejenkinsapi/jobconfig.py
@@ -53,6 +53,17 @@ class JobConfig(object):
def __init__(self):
self._project = ET.fromstring(empty)
self._tree = ET.ElementTree(self._project)
+ self._param_dicts = []
+
+ def add_param_dict(self, prefix, param_dict):
+ self._param_dicts.append((prefix, param_dict))
+
+ def _get_params(self):
+ unified = {}
+ for prefix, param_dict in self._param_dicts:
+ for key in param_dict:
+ unified['%s.%s' % (prefix, key)] = param_dict[key]
+ return unified
def tostring(self):
f = StringIO.StringIO()
@@ -63,12 +74,21 @@ class JobConfig(object):
def set_description(self, new_description):
description = self._tree.find('description')
description.clear()
- description.text = new_description
+ description.text = new_description % self._get_params()
def add_shell_command(self, shell_text):
builders = self._project.find('builders')
shell = ET.SubElement(builders, 'hudson.tasks.Shell')
- ET.SubElement(shell, 'command').text = shell_text
+ ET.SubElement(shell, 'command').text = shell_text % self._get_params()
+
+ def add_ssh_command(self, shell_text):
+ prefix = '''\
+ssh "%(host.ssh-target)s" sh <<\\END
+set -eux
+cd "%(host.directory)s"
+'''
+ suffix = '\nEND'
+ self.add_shell_command(prefix + shell_text + suffix)
def add_build_trigger(self, job_id):
publishers = self._project.find('publishers')