/usr/lib/python2.7/dist-packages/jenkinsapi/jenkinsbase.py is in python-jenkinsapi 0.2.16-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | """
Module for JenkinsBase class
"""
import ast
import logging
from jenkinsapi import config
from jenkinsapi.custom_exceptions import JenkinsAPIException
log = logging.getLogger(__name__)
class JenkinsBase(object):
"""
This appears to be the base object that all other jenkins objects are inherited from
"""
RETRY_ATTEMPTS = 1
def __repr__(self):
return """<%s.%s %s>""" % (self.__class__.__module__,
self.__class__.__name__,
str(self))
def __str__(self):
raise NotImplementedError
def __init__(self, baseurl, poll=True):
"""
Initialize a jenkins connection
"""
self._data = None
self.baseurl = self.strip_trailing_slash(baseurl)
if poll:
self.poll()
def get_jenkins_obj(self):
raise NotImplementedError('Please implement this method on %s' % self.__class__.__name__)
def __eq__(self, other):
"""
Return true if the other object represents a connection to the same server
"""
if not isinstance(other, self.__class__):
return False
if not other.baseurl == self.baseurl:
return False
return True
@classmethod
def strip_trailing_slash(cls, url):
while url.endswith('/'):
url = url[:-1]
return url
def poll(self):
self._data = self._poll()
def _poll(self):
url = self.python_api_url(self.baseurl)
return self.get_data(url)
def get_data(self, url, params=None):
requester = self.get_jenkins_obj().requester
response = requester.get_url(url, params)
try:
return ast.literal_eval(response.text)
except Exception:
log.exception('Inappropriate content found at %s', url)
raise JenkinsAPIException('Cannot parse %s' % response.content)
@classmethod
def python_api_url(cls, url):
if url.endswith(config.JENKINS_API):
return url
else:
if url.endswith(r"/"):
fmt = "%s%s"
else:
fmt = "%s/%s"
return fmt % (url, config.JENKINS_API)
|