diff options
Diffstat (limited to 'simplejenkinsapi/api.py')
-rw-r--r-- | simplejenkinsapi/api.py | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/simplejenkinsapi/api.py b/simplejenkinsapi/api.py index 2c43396..9c6c66b 100644 --- a/simplejenkinsapi/api.py +++ b/simplejenkinsapi/api.py @@ -1,17 +1,17 @@ # simplejenkinsapi/api.py -- simple job management in Jenkins # # Copyright 2012 Lars Wirzenius -# +# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. @@ -33,13 +33,13 @@ import urlparse class Jenkins(object): '''Access a running Jenkins server.''' - + def __init__(self, url): # pragma: no cover self._url = url - + def _connect(self): # pragma: no cover '''Connect to HTTP server, return httplib.HTTPConnection.''' - (scheme, netloc, path, params, query, + (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(self._url) assert path == '/' assert params == '' @@ -56,19 +56,19 @@ class Jenkins(object): return httplib.HTTPSConnection(host, port) else: return httplib.HTTPConnection(host, port) - + def _do(self, method, path, body='', headers={}): '''Make an HTTP request, return result. - + If server returned JSON, return it as a Python object. Otherwise, return as string. - + ''' - logging.debug('HTTP method: %s' % repr(method)) - logging.debug('HTTP path: %s' % repr(path)) - logging.debug('HTTP body: %s' % repr(body)) - logging.debug('HTTP headers: %s' % repr(headers)) + logging.debug('HTTP method: %s' % repr(method)) + logging.debug('HTTP path: %s' % repr(path)) + logging.debug('HTTP body: %s' % repr(body)) + logging.debug('HTTP headers: %s' % repr(headers)) conn = self._connect() conn.request(method, path, body, headers) resp = conn.getresponse() @@ -88,7 +88,7 @@ class Jenkins(object): return json.loads(text) else: return text - + def list_jobs(self): '''Return list of job ids on the server.''' @@ -103,10 +103,10 @@ class Jenkins(object): def create_job(self, job_id, config_xml): '''Create a new job. - - ``config_xml`` is a string containing the XML format configuration + + ``config_xml`` is a string containing the XML format configuration of the job. - + ''' self._do('POST', '/createItem?name=%s' % job_id, body=config_xml, @@ -114,18 +114,18 @@ class Jenkins(object): def update_job(self, job_id, config_xml): '''Update the configuration of a new job. - - ``config_xml`` is a string containing the XML format configuration + + ``config_xml`` is a string containing the XML format configuration of the job. - + ''' - + self._do('POST', '/job/%s/config.xml' % job_id, body=config_xml, headers={ 'Content-Type': 'text/xml' }) def get_job_config(self, job_id): '''Return the XML configuration of a job.''' - + return self._do('GET', '/job/%s/config.xml' % job_id) def run_job(self, job_id): # pragma: no cover |