diff options
author | Aleksey Maksimov <ctpeko3a@gmail.com> | 2014-04-12 21:56:25 +0800 |
---|---|---|
committer | Aleksey Maksimov <ctpeko3a@gmail.com> | 2014-04-12 21:56:25 +0800 |
commit | 61573357e6571cdd5478243d094e76cc6062f299 (patch) | |
tree | f80a41ca87b3a888277926cb2a9958261b42375b | |
parent | 3bdca619ba3f3481326ab60c4dcbf851229e26fa (diff) | |
parent | 59d4e3c5f008acbcd8f768931c3b6280fbca3082 (diff) | |
download | python-jenkinsapi-61573357e6571cdd5478243d094e76cc6062f299.tar.gz python-jenkinsapi-61573357e6571cdd5478243d094e76cc6062f299.tar.bz2 python-jenkinsapi-61573357e6571cdd5478243d094e76cc6062f299.zip |
Merge remote-tracking branch 'upstream/python3_experimental' into python3_experimental
Conflicts:
jenkinsapi/fingerprint.py
33 files changed, 174 insertions, 52 deletions
diff --git a/.travis.yml b/.travis.yml index e1e1eff..64f8ef6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,9 @@ language: python python: + - "2.6" - "2.7" + - "3.3" # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors install: @@ -10,6 +10,11 @@ jenkinsapi .. image:: https://pypip.in/d/jenkinsapi/badge.png :target: https://crate.io/packages/jenkinsapi/ +Experimental Python 3 branch +---------------------------- + +This branch is not yet intended to production use. Some features may or may not work! + About this library ------------------- diff --git a/examples/how_to/create_a_job.py b/examples/how_to/create_a_job.py index 5c7eda6..343685e 100644 --- a/examples/how_to/create_a_job.py +++ b/examples/how_to/create_a_job.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import logging logging.basicConfig() @@ -7,12 +9,12 @@ J = Jenkins('http://localhost:8080') jobName = 'foo_job2' xml = resource_string('examples', 'addjob.xml') -print xml +print(xml) j = J.create_job(jobname=jobName, config=xml) j2 = J[jobName] -print j +print(j) # Delete job J.delete_job(jobName) diff --git a/examples/how_to/create_nested_views.py b/examples/how_to/create_nested_views.py index 1ce245c..b82b28d 100644 --- a/examples/how_to/create_nested_views.py +++ b/examples/how_to/create_nested_views.py @@ -1,5 +1,7 @@ # This example requires NestedViews plugin to be installed in Jenkins # You need to have at least one job in your Jenkins to see views +from __future__ import print_function + import logging from pkg_resources import resource_string @@ -27,7 +29,7 @@ if top_view is None: else: logger.info('View has been created') -print 'top_view.views=', top_view.views.keys() +print('top_view.views=', top_view.views.keys()) logger.info('Attempting to create view inside nested view') sub_view = top_view.views.create('SubView') if sub_view is None: diff --git a/examples/how_to/get_config.py b/examples/how_to/get_config.py index 088dafb..72b6635 100644 --- a/examples/how_to/get_config.py +++ b/examples/how_to/get_config.py @@ -1,10 +1,12 @@ """ An example of how to use JenkinsAPI to fetch the config XML of a job. """ +from __future__ import print_function + from jenkinsapi.jenkins import Jenkins J = Jenkins('http://localhost:8080') jobName = 'create_fwrgmkbbzk' config = J[jobName].get_config() -print config +print(config) diff --git a/examples/how_to/get_version_info_from_last_good_build.py b/examples/how_to/get_version_info_from_last_good_build.py index 575f2bb..3df5f55 100644 --- a/examples/how_to/get_version_info_from_last_good_build.py +++ b/examples/how_to/get_version_info_from_last_good_build.py @@ -1,6 +1,8 @@ """ Extract version information from the latest build. """ +from __future__ import print_function + from jenkinsapi.jenkins import Jenkins @@ -11,4 +13,4 @@ def getSCMInfroFromLatestGoodBuild(url, jobName, username=None, password=None): return lgb.get_revision() if __name__ == '__main__': - print getSCMInfroFromLatestGoodBuild('http://localhost:8080', 'fooJob') + print(getSCMInfroFromLatestGoodBuild('http://localhost:8080', 'fooJob')) diff --git a/examples/how_to/query_a_build.py b/examples/how_to/query_a_build.py index 8272517..16dc569 100644 --- a/examples/how_to/query_a_build.py +++ b/examples/how_to/query_a_build.py @@ -1,11 +1,14 @@ +from __future__ import print_function + from jenkinsapi.view import View from jenkinsapi.jenkins import Jenkins + J = Jenkins('http://localhost:8080') -print J.items() +print(J.items()) j = J['foo'] j = J.get_job("foo") b = j.get_last_build() -print b +print(b) mjn = b.get_master_job_name() print(mjn) diff --git a/examples/how_to/search_artifact_by_regexp.py b/examples/how_to/search_artifact_by_regexp.py index 322b541..7f73562 100644 --- a/examples/how_to/search_artifact_by_regexp.py +++ b/examples/how_to/search_artifact_by_regexp.py @@ -1,3 +1,5 @@ +from __future__ import print_function + from jenkinsapi.api import search_artifact_by_regexp import re diff --git a/examples/how_to/search_artifacts.py b/examples/how_to/search_artifacts.py index cbf3c9b..31d19c6 100644 --- a/examples/how_to/search_artifacts.py +++ b/examples/how_to/search_artifacts.py @@ -1,3 +1,5 @@ +from __future__ import print_function + from jenkinsapi.api import search_artifacts jenkinsurl = "http://localhost:8080/jenkins" diff --git a/examples/low_level/copy_a_job.py b/examples/low_level/copy_a_job.py index 3ee4299..ae0399b 100644 --- a/examples/low_level/copy_a_job.py +++ b/examples/low_level/copy_a_job.py @@ -1,6 +1,7 @@ """ A lower-level implementation of copying a job in Jenkins """ +from __future__ import print_function import requests from jenkinsapi.jenkins import Jenkins @@ -19,4 +20,4 @@ j = J.create_job(jobname=jobName, config=xml) h = {'Content-Type': 'application/x-www-form-urlencoded'} response = requests.post(url, data='dysjsjsjs', headers=h) -print response.text.encode('UTF-8') +print(response.text.encode('UTF-8')) diff --git a/examples/low_level/create_a_view_low_level.py b/examples/low_level/create_a_view_low_level.py index 606941a..21115ca 100644 --- a/examples/low_level/create_a_view_low_level.py +++ b/examples/low_level/create_a_view_low_level.py @@ -2,6 +2,8 @@ A low level example: This is how JenkinsAPI creates views """ +from __future__ import print_function + import requests import json @@ -18,4 +20,4 @@ data = { } # Try 1 result = requests.post(url, params=params, data=data, headers=headers) -print result.text.encode('UTF-8') +print(result.text.encode('UTF-8')) diff --git a/examples/low_level/example_param_build.py b/examples/low_level/example_param_build.py index 987d0f1..d6e8c33 100644 --- a/examples/low_level/example_param_build.py +++ b/examples/low_level/example_param_build.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import json import requests @@ -12,7 +14,7 @@ def foo(): headers = {'Content-Type': 'application/x-www-form-urlencoded'} form = {'json': json.dumps(toJson)} response = requests.post(url, data=form, headers=headers) - print response.text.encode('UTF-8') + print(response.text.encode('UTF-8')) if __name__ == '__main__': foo() diff --git a/examples/low_level/login_with_auth.py b/examples/low_level/login_with_auth.py index c28f670..c11aa9f 100644 --- a/examples/low_level/login_with_auth.py +++ b/examples/low_level/login_with_auth.py @@ -1,6 +1,7 @@ """ A lower level example of how we login with authentication """ +from __future__ import print_function from jenkinsapi import jenkins @@ -8,4 +9,4 @@ from jenkinsapi import jenkins J = jenkins.Jenkins("http://localhost:8080", username="sal", password="foobar") J.poll() -print J.items() +print(J.items()) diff --git a/jenkinsapi/api.py b/jenkinsapi/api.py index 5444442..283f7ad 100644 --- a/jenkinsapi/api.py +++ b/jenkinsapi/api.py @@ -8,7 +8,12 @@ import os import time import logging -from urllib2 import urlparse +try: + from urllib import parse as urlparse +except ImportError: + # Python3 + from urllib2 import urlparse + from jenkinsapi import constants from jenkinsapi.jenkins import Jenkins from jenkinsapi.artifact import Artifact @@ -216,7 +221,13 @@ def search_artifact_by_regexp(jenkinsurl, jobid, artifactRegExp, artifacts = build.get_artifact_dict() - for name, art in artifacts.iteritems(): + try: + it = artifacts.iteritems() + except AttributeError: + # Python3 + it = artifacts.items() + + for name, art in it: md_match = artifactRegExp.search(name) if md_match: diff --git a/jenkinsapi/fingerprint.py b/jenkinsapi/fingerprint.py index 0fa279c..a30a79f 100644 --- a/jenkinsapi/fingerprint.py +++ b/jenkinsapi/fingerprint.py @@ -5,6 +5,11 @@ Module for jenkinsapi Fingerprint from jenkinsapi.jenkinsbase import JenkinsBase from jenkinsapi.custom_exceptions import ArtifactBroken + from urllib2 import HTTPError +except ImportError: + # Python3 + from urllib.error import HTTPError + import re import requests diff --git a/jenkinsapi/jenkins.py b/jenkinsapi/jenkins.py index 9abf2a9..89ca317 100644 --- a/jenkinsapi/jenkins.py +++ b/jenkinsapi/jenkins.py @@ -4,9 +4,16 @@ Module for jenkinsapi Jenkins object import json -import urllib + +try: + import urlparse + from urllib import quote as urlquote, urlencode +except ImportError: + # Python3 + import urllib.parse as urlparse + from urllib.parse import quote as urlquote, urlencode + import logging -import urlparse from jenkinsapi import config from jenkinsapi.executors import Executors @@ -241,7 +248,7 @@ class Jenkins(JenkinsBase): def get_node_url(self, nodename=""): """Return the url for nodes""" - url = urlparse.urljoin(self.base_server_url(), 'computer/%s' % urllib.quote(nodename)) + url = urlparse.urljoin(self.base_server_url(), 'computer/%s' % urlquote(nodename)) return url def get_queue_url(self): @@ -313,7 +320,7 @@ class Jenkins(JenkinsBase): 'launcher': {'stapler-class': 'hudson.slaves.JNLPLauncher'} }) } - url = self.get_node_url() + "doCreateItem?%s" % urllib.urlencode(params) + url = self.get_node_url() + "doCreateItem?%s" % urlencode(params) self.requester.get_and_confirm_status(url) return Node(nodename=name, baseurl=self.get_node_url(nodename=name), jenkins_obj=self) diff --git a/jenkinsapi/job.py b/jenkinsapi/job.py index 586b031..374edc1 100644 --- a/jenkinsapi/job.py +++ b/jenkinsapi/job.py @@ -4,7 +4,13 @@ Module for jenkinsapi Job import json import logging -import urlparse + +try: + import urlparse +except ImportError: + # Python3 + import urllib.parse as urlparse + import xml.etree.ElementTree as ET from collections import defaultdict from time import sleep @@ -139,8 +145,15 @@ class Job(JenkinsBase, MutableJenkinsThing): """ assert isinstance( build_params, dict), 'Build parameters must be a dict' + + try: + it = build_params.iteritems() + except AttributeError: + # Python3 + it = build_params.items() + return {'parameter': [ - {'name': k, 'value': v} for k, v in build_params.iteritems() + {'name': k, 'value': v} for k, v in it ]} @staticmethod @@ -494,8 +507,13 @@ class Job(JenkinsBase, MutableJenkinsThing): Also refresh the ElementTree object since the config has changed """ url = self.get_config_xml_url() - if isinstance(config, unicode): - config = str(config) + try: + if isinstance(config, unicode): # pylint: disable=undefined-variable + config = str(config) + except NameError: + # Python3 already a str + pass + response = self.jenkins.requester.post_url(url, params={}, data=config) self._element_tree = ET.fromstring(config) return response.text diff --git a/jenkinsapi/jobs.py b/jenkinsapi/jobs.py index de87a79..23f1133 100644 --- a/jenkinsapi/jobs.py +++ b/jenkinsapi/jobs.py @@ -90,8 +90,13 @@ class Jobs(object): return self[job_name] params = {'name': job_name} - if isinstance(config, unicode): - config = str(config) + try: + if isinstance(config, unicode): # pylint: disable=undefined-variable + config = str(config) + except NameError: + # Python3 already a str + pass + self.jenkins.requester.post_xml_and_confirm_status( self.jenkins.get_create_url(), data=config, diff --git a/jenkinsapi/node.py b/jenkinsapi/node.py index 78a4afb..7039e38 100644 --- a/jenkinsapi/node.py +++ b/jenkinsapi/node.py @@ -4,7 +4,12 @@ Module for jenkinsapi Node class from jenkinsapi.jenkinsbase import JenkinsBase import logging -import urllib + +try: + from urllib import quote as urlquote +except ImportError: + # Python3 + from urllib.parse import quote as urlquote log = logging.getLogger(__name__) @@ -88,7 +93,7 @@ class Node(JenkinsBase): : param message: optional string can be used to explain why you are taking this node offline """ initial_state = self.is_temporarily_offline() - url = self.baseurl + "/toggleOffline?offlineMessage=" + urllib.quote(message) + url = self.baseurl + "/toggleOffline?offlineMessage=" + urlquote(message) html_result = self.jenkins.requester.get_and_confirm_status(url) self.poll() log.debug(html_result) diff --git a/jenkinsapi/plugins.py b/jenkinsapi/plugins.py index 1cd2ca2..e1a0534 100644 --- a/jenkinsapi/plugins.py +++ b/jenkinsapi/plugins.py @@ -1,6 +1,7 @@ """ jenkinsapi plugins """ +from __future__ import print_function import logging @@ -18,7 +19,7 @@ class Plugins(JenkinsBase): def __init__(self, url, jenkins_obj): self.jenkins_obj = jenkins_obj JenkinsBase.__init__(self, url) - # print 'DEBUG: Plugins._data=', self._data + # print('DEBUG: Plugins._data=', self._data) def get_jenkins_obj(self): return self.jenkins_obj diff --git a/jenkinsapi/utils/requester.py b/jenkinsapi/utils/requester.py index 0460b99..2116c91 100644 --- a/jenkinsapi/utils/requester.py +++ b/jenkinsapi/utils/requester.py @@ -3,7 +3,13 @@ Module for jenkinsapi requester (which is a wrapper around python-requests) """ import requests -import urlparse + +try: + import urlparse +except ImportError: + # Python3 + import urllib.parse as urlparse + from jenkinsapi.custom_exceptions import JenkinsAPIException # import logging diff --git a/jenkinsapi/view.py b/jenkinsapi/view.py index 4351ca5..e06361f 100644 --- a/jenkinsapi/view.py +++ b/jenkinsapi/view.py @@ -1,7 +1,12 @@ """ Module for jenkinsapi views """ -import urllib +try: + from urllib import urlencode +except ImportError: + # Python3 + from urllib.parse import urlencode + import logging from jenkinsapi.jenkinsbase import JenkinsBase @@ -50,7 +55,13 @@ class View(JenkinsBase): return self.get_job_dict().keys() def iteritems(self): - for name, url in self.get_job_dict().iteritems(): + try: + it = self.get_job_dict().iteritems() + except AttributeError: + # Python3 + it = self.get_job_dict().items() + + for name, url in it: api_url = self.python_api_url(url) yield name, Job(api_url, name, self.jenkins_obj) @@ -141,7 +152,7 @@ class View(JenkinsBase): data[job.name] = 'on' data['json'] = data.copy() - data = urllib.urlencode(data) + data = urlencode(data) self.get_jenkins_obj().requester.post_and_confirm_status( '%s/configSubmit' % self.baseurl, data=data) self.poll() diff --git a/jenkinsapi_tests/systests/test_parameterized_builds.py b/jenkinsapi_tests/systests/test_parameterized_builds.py index 680feb4..205fc78 100644 --- a/jenkinsapi_tests/systests/test_parameterized_builds.py +++ b/jenkinsapi_tests/systests/test_parameterized_builds.py @@ -88,7 +88,7 @@ class TestParameterizedBuilds(BaseSystemTest): with self.assertRaises(WillNotBuild) as na: job.invoke(build_params=params) expected_msg = 'A build with these parameters is already queued.' - self.assertEqual(na.exception.message, expected_msg) + self.assertEqual(str(na.exception), expected_msg) if __name__ == '__main__': diff --git a/jenkinsapi_tests/systests/test_scm.py b/jenkinsapi_tests/systests/test_scm.py index dd79836..3147fb0 100644 --- a/jenkinsapi_tests/systests/test_scm.py +++ b/jenkinsapi_tests/systests/test_scm.py @@ -17,7 +17,11 @@ # ii.block(until='completed') # self.assertFalse(ii.is_running()) # b = ii.get_build() -# self.assertIsInstance(b.get_revision(), basestring) +# try: +# self.assertIsInstance(b.get_revision(), basestring) +# except NameError: +# # Python3 +# self.assertIsInstance(b.get_revision(), str) # if __name__ == '__main__': # unittest.main() diff --git a/jenkinsapi_tests/test_utils/random_strings.py b/jenkinsapi_tests/test_utils/random_strings.py index ffcbf57..18f13fa 100644 --- a/jenkinsapi_tests/test_utils/random_strings.py +++ b/jenkinsapi_tests/test_utils/random_strings.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import random import string @@ -6,4 +8,4 @@ def random_string(length=10): return ''.join(random.choice(string.ascii_lowercase) for i in range(length)) if __name__ == '__main__': - print random_string() + print(random_string()) diff --git a/jenkinsapi_tests/unittests/test_build_scm_git.py b/jenkinsapi_tests/unittests/test_build_scm_git.py index cd31855..7983e59 100644 --- a/jenkinsapi_tests/unittests/test_build_scm_git.py +++ b/jenkinsapi_tests/unittests/test_build_scm_git.py @@ -98,7 +98,11 @@ class test_build(unittest.TestCase): """ Can we extract git build revision data from a build object? """ - self.assertIsInstance(self.b.get_revision(), basestring) + try: + self.assertIsInstance(self.b.get_revision(), basestring) + except NameError: + # Python3 + self.assertIsInstance(self.b.get_revision(), str) self.assertEquals(self.b.get_revision(), '7def9ed6e92580f37d00e4980c36c4d36e68f702') diff --git a/jenkinsapi_tests/unittests/test_jenkins.py b/jenkinsapi_tests/unittests/test_jenkins.py index 07634ce..c0bad0a 100644 --- a/jenkinsapi_tests/unittests/test_jenkins.py +++ b/jenkinsapi_tests/unittests/test_jenkins.py @@ -275,7 +275,7 @@ class TestJenkins(unittest.TestCase): with self.assertRaises(JenkinsAPIException) as ar: J.create_job('job_new', None) - self.assertEquals(ar.exception.message, 'Cannot create job job_new') + self.assertEquals(str(ar.exception), 'Cannot create job job_new') @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') diff --git a/jenkinsapi_tests/unittests/test_job.py b/jenkinsapi_tests/unittests/test_job.py index b4f2a28..898461c 100644 --- a/jenkinsapi_tests/unittests/test_job.py +++ b/jenkinsapi_tests/unittests/test_job.py @@ -112,7 +112,7 @@ class TestJob(unittest.TestCase): self.j._mk_json_from_build_parameters(build_params='bad parameter') self.assertEquals( - ar.exception.message, 'Build parameters must be a dict') + str(ar.exception), 'Build parameters must be a dict') def test__mk_json_from_build_parameters(self): params = {'param1': 'value1', 'param2': 'value2'} @@ -126,7 +126,7 @@ class TestJob(unittest.TestCase): self.j.mk_json_from_build_parameters(build_params='bad parameter') self.assertEquals( - ar.exception.message, 'Build parameters must be a dict') + str(ar.exception), 'Build parameters must be a dict') @mock.patch.object(JenkinsBase, 'get_data', fakeGetData) def test_wrong_field__build_id_for_type(self): diff --git a/jenkinsapi_tests/unittests/test_job_multiconf.py b/jenkinsapi_tests/unittests/test_job_multiconf.py index 335f741..b994bdd 100644 --- a/jenkinsapi_tests/unittests/test_job_multiconf.py +++ b/jenkinsapi_tests/unittests/test_job_multiconf.py @@ -111,7 +111,7 @@ # self.j._mk_json_from_build_parameters(build_params='bad parameter') # self.assertEquals( -# ar.exception.message, 'Build parameters must be a dict') +# str(ar.exception), 'Build parameters must be a dict') # def test__mk_json_from_build_parameters(self): # params = {'param1': 'value1', 'param2': 'value2'} @@ -125,7 +125,7 @@ # self.j.mk_json_from_build_parameters(build_params='bad parameter') # self.assertEquals( -# ar.exception.message, 'Build parameters must be a dict') +# str(ar.exception), 'Build parameters must be a dict') # @mock.patch.object(JenkinsBase, 'get_data', fakeGetData) # def test_wrong_field__build_id_for_type(self): diff --git a/jenkinsapi_tests/unittests/test_requester.py b/jenkinsapi_tests/unittests/test_requester.py index c556ae9..521e1df 100644 --- a/jenkinsapi_tests/unittests/test_requester.py +++ b/jenkinsapi_tests/unittests/test_requester.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import mock import unittest @@ -29,7 +31,7 @@ class TestQueue(unittest.TestCase): data=None, headers=None ) - self.assertTrue(na.exception.message == "Params must be a dict, got 'wrong'") + self.assertTrue(str(na.exception) == "Params must be a dict, got 'wrong'") def test_get_request_dict_correct_params(self): req = Requester('foo', 'bar') @@ -53,7 +55,7 @@ class TestQueue(unittest.TestCase): data=None, headers='wrong' ) - self.assertTrue(na.exception.message == "headers must be a dict, got 'wrong'") + self.assertTrue(str(na.exception) == "headers must be a dict, got 'wrong'") def test_get_request_dict_correct_headers(self): req = Requester('foo', 'bar') @@ -78,7 +80,7 @@ class TestQueue(unittest.TestCase): ) self.assertTrue(isinstance(req_return, dict)) - print req_return.get('data') + print(req_return.get('data')) self.assertTrue(req_return.get('data')) self.assertTrue(req_return['data'] == 'some data') @@ -125,7 +127,7 @@ class TestQueue(unittest.TestCase): data=None ) - self.assertTrue(ae.exception.message == "Unexpected type of parameter 'data': <type 'NoneType'>. Expected (str, dict)") + self.assertTrue(str(ae.exception) == "Unexpected type of parameter 'data': <type 'NoneType'>. Expected (str, dict)") @mock.patch.object(requests, 'post') def test_post_xml_and_confirm_status_some_xml(self, _post): @@ -151,7 +153,7 @@ class TestQueue(unittest.TestCase): data=None ) - self.assertTrue(ae.exception.message == "Unexpected type of parameter 'data': <type 'NoneType'>. Expected (str, dict)") + self.assertTrue(str(ae.exception) == "Unexpected type of parameter 'data': <type 'NoneType'>. Expected (str, dict)") @mock.patch.object(requests, 'post') def test_post_and_confirm_status_some_data(self, _post): @@ -180,8 +182,8 @@ class TestQueue(unittest.TestCase): data='some data' ) - print ae.exception.message - self.assertTrue(ae.exception.message == "Operation failed. url=None, data=some data, headers={'Content-Type': 'application/x-www-form-urlencoded'}, status=500, text=") + print(str(ae.exception)) + self.assertTrue(str(ae.exception) == "Operation failed. url=None, data=some data, headers={'Content-Type': 'application/x-www-form-urlencoded'}, status=500, text=") @mock.patch.object(requests, 'get') def test_get_and_confirm_status(self, _get): @@ -208,8 +210,8 @@ class TestQueue(unittest.TestCase): params={'param': 'value'} ) - print ae.exception.message - self.assertTrue(ae.exception.message == "Operation failed. url=None, headers=None, status=500, text=") + print(str(ae.exception)) + self.assertTrue(str(ae.exception) == "Operation failed. url=None, headers=None, status=500, text=") if __name__ == "__main__": unittest.main() diff --git a/jenkinsapi_utils/jenkins_launcher.py b/jenkinsapi_utils/jenkins_launcher.py index f74a1d0..fc4fa51 100644 --- a/jenkinsapi_utils/jenkins_launcher.py +++ b/jenkinsapi_utils/jenkins_launcher.py @@ -1,6 +1,9 @@ import os import time -import Queue +try: + import Queue +except ImportError: + import queue as Queue import random import shutil import logging @@ -75,7 +78,12 @@ class JenkinsLancher(object): config_dest = os.path.join(self.jenkins_home, 'config.xml') config_dest_file = open(config_dest, 'w') config_source = pkg_resources.resource_string('jenkinsapi_tests.systests', 'config.xml') - config_dest_file.write(config_source.encode('UTF-8')) + try: + config_dest_file.write(config_source.encode('UTF-8')) + except AttributeError: + # Python 3.x + config_dest_file.write(config_source.decode('UTF-8')) + def install_plugins(self): for i, url in enumerate(self.plugin_urls): @@ -144,6 +152,9 @@ class JenkinsLancher(object): while True: try: streamName, line = self.q.get(block=True, timeout=timeout) + # Python 3.x + if isinstance(line, bytes): + line = line.decode('UTF-8') except Queue.Empty: log.warn("Input ended unexpectedly") break diff --git a/jenkinsapi_utils/simple_post_logger.py b/jenkinsapi_utils/simple_post_logger.py index 87bf4f0..f5be1ab 100644 --- a/jenkinsapi_utils/simple_post_logger.py +++ b/jenkinsapi_utils/simple_post_logger.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import SimpleHTTPServer import SocketServer import logging @@ -28,5 +30,5 @@ Handler = ServerHandler httpd = SocketServer.TCPServer(("", PORT), Handler) -print "serving at port", PORT +print("serving at port", PORT) httpd.serve_forever() @@ -12,7 +12,7 @@ SHORT_DESCRIPTION = 'A Python API for accessing resources on a Jenkins continuou try: DESCRIPTION = open(os.path.join(PROJECT_ROOT, "README.rst")).read() -except IOError, _: +except IOError: DESCRIPTION = SHORT_DESCRIPTION GLOBAL_ENTRY_POINTS = { |