From 4f6487323b1d82c1959e805a22698abcb5f0fc5b Mon Sep 17 00:00:00 2001 From: Lars Hupfeldt Date: Thu, 13 Feb 2014 18:47:10 +0100 Subject: [PATCH] Use print() (with 'from __future__ import print_function') --- examples/how_to/create_a_job.py | 6 ++++-- examples/how_to/create_nested_views.py | 4 +++- examples/how_to/get_config.py | 4 +++- examples/how_to/get_version_info_from_last_good_build.py | 4 +++- examples/how_to/query_a_build.py | 7 +++++-- examples/how_to/search_artifact_by_regexp.py | 2 ++ examples/how_to/search_artifacts.py | 2 ++ examples/low_level/copy_a_job.py | 3 ++- examples/low_level/create_a_view_low_level.py | 4 +++- examples/low_level/example_param_build.py | 4 +++- examples/low_level/login_with_auth.py | 3 ++- jenkinsapi/plugins.py | 3 ++- jenkinsapi_tests/test_utils/random_strings.py | 4 +++- jenkinsapi_tests/unittests/test_requester.py | 8 +++++--- jenkinsapi_utils/simple_post_logger.py | 4 +++- 15 files changed, 45 insertions(+), 17 deletions(-) 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/plugins.py b/jenkinsapi/plugins.py index ea38b5d..cad4e59 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_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_requester.py b/jenkinsapi_tests/unittests/test_requester.py index c556ae9..86502b4 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 @@ -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') @@ -180,7 +182,7 @@ class TestQueue(unittest.TestCase): data='some data' ) - print ae.exception.message + 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=") @mock.patch.object(requests, 'get') @@ -208,7 +210,7 @@ class TestQueue(unittest.TestCase): params={'param': 'value'} ) - print ae.exception.message + print(ae.exception.message) self.assertTrue(ae.exception.message == "Operation failed. url=None, headers=None, status=500, text=") if __name__ == "__main__": 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() -- 2.7.4