From 9b6a6220395daa9b75c855c2dc9e0a0e42d223ec Mon Sep 17 00:00:00 2001 From: Vadim Rutkovsky Date: Oct 20 2017 13:05:11 +0000 Subject: Replace all print statements with print function calls This would simplify transitioning to python 3 --- diff --git a/alembic/env.py b/alembic/env.py index d177918..d00ce8b 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -1,4 +1,4 @@ -from __future__ import with_statement +from __future__ import with_statement, print_function import os @@ -17,7 +17,7 @@ fileConfig(config.config_file_name) if 'PAGURE_CONFIG' not in os.environ \ and os.path.exists('/etc/pagure/pagure.cfg'): - print 'Using configuration file `/etc/pagure/pagure.cfg`' + print('Using configuration file `/etc/pagure/pagure.cfg`') os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg' diff --git a/alembic/versions/26af5c3602a0_add_the_default_hook_to_all_projects.py b/alembic/versions/26af5c3602a0_add_the_default_hook_to_all_projects.py index 0e733d8..4d6cc25 100644 --- a/alembic/versions/26af5c3602a0_add_the_default_hook_to_all_projects.py +++ b/alembic/versions/26af5c3602a0_add_the_default_hook_to_all_projects.py @@ -6,6 +6,8 @@ Create Date: 2016-10-08 12:14:31.155018 """ +from __future__ import print_function + # revision identifiers, used by Alembic. revision = '26af5c3602a0' down_revision = '644ef887bb6f' @@ -36,7 +38,7 @@ def upgrade(): # Update all the existing projects for project in session.query(model.Project).all(): - print 'Installing %s' % project.fullname + print('Installing %s' % project.fullname) # Install the default hook plugin = pagure.lib.plugins.get_plugin('default') dbobj = plugin.db_object() diff --git a/files/api_key_expire_mail.py b/files/api_key_expire_mail.py index 504a758..350c5fd 100644 --- a/files/api_key_expire_mail.py +++ b/files/api_key_expire_mail.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import os import argparse from datetime import datetime, timedelta @@ -9,7 +10,7 @@ from sqlalchemy.exc import SQLAlchemyError if 'PAGURE_CONFIG' not in os.environ \ and os.path.exists('/etc/pagure/pagure.cfg'): - print 'Using configuration file `/etc/pagure/pagure.cfg`' + print('Using configuration file `/etc/pagure/pagure.cfg`') os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg' import pagure @@ -40,9 +41,9 @@ def main(debug=False): Thanks, \nYour Pagure Admin. ''' % (user.fullname, project.name, days_left) msg = pagure.lib.notify.send_email(text, subject, user_email) if debug: - print 'Sent mail to %s' % user.fullname + print('Sent mail to %s' % user.fullname) if debug: - print 'Done' + print('Done') if __name__ == '__main__': diff --git a/files/emoji_clean_json.py b/files/emoji_clean_json.py index 8ffa743..f8e4e20 100644 --- a/files/emoji_clean_json.py +++ b/files/emoji_clean_json.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +from __future__ import print_function import json import os import sys @@ -9,7 +10,7 @@ with open('emoji_strategy.json') as stream: data = json.load(stream) if not data: - print 'Could not load the data from the JSON file' + print('Could not load the data from the JSON file') sys.exit(1) # Retrieve the items we keep in the JSON @@ -24,9 +25,8 @@ for key in data: unicodes = [tokeep[key]['unicode'] for key in tokeep] images = [item.replace('.png', '') for item in os.listdir('png')] -print set(unicodes).symmetric_difference(set(images)) +print(set(unicodes).symmetric_difference(set(images))) with open('emoji_strategy2.json', 'w') as stream: json.dump(tokeep, stream) - diff --git a/pagure-ci/pagure_ci_server.py b/pagure-ci/pagure_ci_server.py index afc4f2a..cd62419 100644 --- a/pagure-ci/pagure_ci_server.py +++ b/pagure-ci/pagure_ci_server.py @@ -16,6 +16,7 @@ receiving end is offline or so. """ +from __future__ import print_function import json import logging import os @@ -29,7 +30,7 @@ _log = logging.getLogger(__name__) if 'PAGURE_CONFIG' not in os.environ \ and os.path.exists('/etc/pagure/pagure.cfg'): - print 'Using configuration file `/etc/pagure/pagure.cfg`' + print('Using configuration file `/etc/pagure/pagure.cfg`') os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg' diff --git a/pagure-loadjson/pagure_loadjson_server.py b/pagure-loadjson/pagure_loadjson_server.py index d10efcd..32b5292 100644 --- a/pagure-loadjson/pagure_loadjson_server.py +++ b/pagure-loadjson/pagure_loadjson_server.py @@ -18,6 +18,7 @@ pagure can be really time-consuming). """ +from __future__ import print_function import json import logging import os @@ -32,7 +33,7 @@ _log = logging.getLogger(__name__) if 'PAGURE_CONFIG' not in os.environ \ and os.path.exists('/etc/pagure/pagure.cfg'): - print 'Using configuration file `/etc/pagure/pagure.cfg`' + print('Using configuration file `/etc/pagure/pagure.cfg`') os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg' diff --git a/pagure-logcom/pagure_logcom_server.py b/pagure-logcom/pagure_logcom_server.py index 0c0ed3c..864a5be 100644 --- a/pagure-logcom/pagure_logcom_server.py +++ b/pagure-logcom/pagure_logcom_server.py @@ -17,6 +17,7 @@ time can be really time-consuming). """ +from __future__ import print_function import json import logging import os @@ -30,7 +31,7 @@ _log = logging.getLogger(__name__) if 'PAGURE_CONFIG' not in os.environ \ and os.path.exists('/etc/pagure/pagure.cfg'): - print 'Using configuration file `/etc/pagure/pagure.cfg`' + print('Using configuration file `/etc/pagure/pagure.cfg`') os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg' diff --git a/pagure-milters/comment_email_milter.py b/pagure-milters/comment_email_milter.py index 533995f..8f27fcb 100644 --- a/pagure-milters/comment_email_milter.py +++ b/pagure-milters/comment_email_milter.py @@ -5,6 +5,7 @@ # Return REJECT,TEMPFAIL,ACCEPT to short circuit processing for a message. # You can also add/del recipients, replacebody, add/del headers, etc. +from __future__ import print_function import base64 import email import hashlib @@ -106,7 +107,7 @@ class PagureMilter(Milter.Base): @Milter.noreply def envrcpt(self, to, *str): rcptinfo = to, Milter.dictfromlist(str) - print rcptinfo + print(rcptinfo) return Milter.CONTINUE @@ -247,9 +248,9 @@ def background(): t = logq.get() if not t: break msg,id,ts = t - print "%s [%d]" % (time.strftime('%Y%b%d %H:%M:%S',time.localtime(ts)),id), + print("%s [%d]" % (time.strftime('%Y%b%d %H:%M:%S',time.localtime(ts)),id),) # 2005Oct13 02:34:11 [1] msg1 msg2 msg3 ... - for i in msg: print i, + for i in msg: print(i,) print @@ -260,12 +261,12 @@ def main(): timeout = 600 # Register to have the Milter factory create instances of your class: Milter.factory = PagureMilter - print "%s pagure milter startup" % time.strftime('%Y%b%d %H:%M:%S') + print("%s pagure milter startup" % time.strftime('%Y%b%d %H:%M:%S')) sys.stdout.flush() Milter.runmilter("paguremilter", socketname, timeout) logq.put(None) bt.join() - print "%s pagure milter shutdown" % time.strftime('%Y%b%d %H:%M:%S') + print("%s pagure milter shutdown" % time.strftime('%Y%b%d %H:%M:%S')) if __name__ == "__main__": diff --git a/pagure-webhook/pagure-webhook-server.py b/pagure-webhook/pagure-webhook-server.py index 7bc66fe..4895481 100644 --- a/pagure-webhook/pagure-webhook-server.py +++ b/pagure-webhook/pagure-webhook-server.py @@ -15,6 +15,7 @@ receiving end is offline or so. """ +from __future__ import print_function import datetime import hashlib import hmac @@ -37,7 +38,7 @@ log = logging.getLogger(__name__) if 'PAGURE_CONFIG' not in os.environ \ and os.path.exists('/etc/pagure/pagure.cfg'): - print 'Using configuration file `/etc/pagure/pagure.cfg`' + print('Using configuration file `/etc/pagure/pagure.cfg`') os.environ['PAGURE_CONFIG'] = '/etc/pagure/pagure.cfg' diff --git a/pagure/api/issue.py b/pagure/api/issue.py index 0adc381..558aa1b 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -8,6 +8,8 @@ """ +from __future__ import print_function + import flask import datetime @@ -1339,7 +1341,7 @@ def api_update_custom_fields( raise pagure.exceptions.APIError( 400, error_code=APIERROR.ENOCODE, error=str(err)) except SQLAlchemyError as err: # pragma: no cover - print err + print(err) SESSION.rollback() raise pagure.exceptions.APIError(400, error_code=APIERROR.EDBERROR) diff --git a/pagure/hooks/files/fedmsg_hook.py b/pagure/hooks/files/fedmsg_hook.py index 434c131..0ebffa1 100755 --- a/pagure/hooks/files/fedmsg_hook.py +++ b/pagure/hooks/files/fedmsg_hook.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +from __future__ import print_function + import os import sys @@ -18,7 +20,7 @@ import pagure.lib.git # noqa: E402 abspath = os.path.abspath(os.environ['GIT_DIR']) -print "Emitting a message to the fedmsg bus." +print("Emitting a message to the fedmsg bus.") config = fedmsg.config.load_config([], None) config['active'] = True config['endpoints']['relay_inbound'] = config['relay_inbound'] @@ -33,11 +35,11 @@ for line in sys.stdin.readlines(): forced = False if set(newrev) == set(['0']): - print "Deleting a reference/branch, so we won't run the "\ - "pagure hook" + print("Deleting a reference/branch, so we won't run the " + "pagure hook") break elif set(oldrev) == set(['0']): - print "New reference/branch" + print("New reference/branch") oldrev = '^%s' % oldrev elif pagure.lib.git.is_forced_push(oldrev, newrev, abspath): forced = True @@ -75,7 +77,7 @@ for line in sys.stdin.readlines(): if revs: revs.reverse() - print "* Publishing information for %i commits" % len(revs) + print("* Publishing information for %i commits" % len(revs)) pagure.lib.notify.log( project=project, topic="git.receive", diff --git a/pagure/hooks/files/pagure_block_unsigned.py b/pagure/hooks/files/pagure_block_unsigned.py index 865c309..85ae56c 100755 --- a/pagure/hooks/files/pagure_block_unsigned.py +++ b/pagure/hooks/files/pagure_block_unsigned.py @@ -5,6 +5,8 @@ statement. """ +from __future__ import print_function + import os import sys @@ -27,27 +29,27 @@ def run_as_pre_receive_hook(): for line in sys.stdin: if pagure.APP.config.get('HOOK_DEBUG', False): - print line + print(line) (oldrev, newrev, refname) = line.strip().split(' ', 2) if pagure.APP.config.get('HOOK_DEBUG', False): - print ' -- Old rev' - print oldrev - print ' -- New rev' - print newrev - print ' -- Ref name' - print refname + print(' -- Old rev') + print(oldrev) + print(' -- New rev') + print(newrev) + print(' -- Ref name') + print(refname) if set(newrev) == set(['0']): - print "Deleting a reference/branch, so we won't run the "\ - "hook to block unsigned commits" + print("Deleting a reference/branch, so we won't run the " + "hook to block unsigned commits") return commits = pagure.lib.git.get_revs_between( oldrev, newrev, abspath, refname) for commit in commits: if pagure.APP.config.get('HOOK_DEBUG', False): - print 'Processing commit: %s' % commit + print('Processing commit: %s' % commit) signed = False for line in pagure.lib.git.read_git_lines( ['log', '--no-walk', commit], abspath): @@ -55,9 +57,9 @@ def run_as_pre_receive_hook(): signed = True break if pagure.APP.config.get('HOOK_DEBUG', False): - print ' - Commit: %s is signed: %s' % (commit, signed) + print(' - Commit: %s is signed: %s' % (commit, signed)) if not signed: - print "Commit %s is not signed" % commit + print("Commit %s is not signed" % commit) sys.exit(1) diff --git a/pagure/hooks/files/pagure_force_commit_hook.py b/pagure/hooks/files/pagure_force_commit_hook.py index 56a273c..d496cfc 100755 --- a/pagure/hooks/files/pagure_force_commit_hook.py +++ b/pagure/hooks/files/pagure_force_commit_hook.py @@ -4,6 +4,8 @@ """Pagure specific hook to block non-fastforward pushes. """ +from __future__ import print_function + import os import sys @@ -27,17 +29,17 @@ def run_as_pre_receive_hook(): namespace = pagure.lib.git.get_repo_namespace(abspath) username = pagure.lib.git.get_username(abspath) if pagure.APP.config.get('HOOK_DEBUG', False): - print 'repo: ', reponame - print 'user: ', username - print 'namspaces:', namespace + print('repo: ', reponame) + print('user: ', username) + print('namspaces:', namespace) repo = pagure.lib._get_project( pagure.SESSION, reponame, user=username, namespace=namespace, case=pagure.APP.config.get('CASE_SENSITIVE', False)) if not repo: - print 'Unknown repo %s of username: %s in namespace %s' % ( - reponame, username, namespace) + print('Unknown repo %s of username: %s in namespace %s' % ( + reponame, username, namespace)) sys.exit(1) plugin = pagure.lib.plugins.get_plugin('Block non fast-forward pushes') @@ -56,24 +58,24 @@ def run_as_pre_receive_hook(): for line in sys.stdin: if pagure.APP.config.get('HOOK_DEBUG', False): - print line + print(line) (oldrev, newrev, refname) = line.strip().split(' ', 2) refname = refname.replace('refs/heads/', '') if refname in branches: if pagure.APP.config.get('HOOK_DEBUG', False): - print ' -- Old rev' - print oldrev - print ' -- New rev' - print newrev - print ' -- Ref name' - print refname + print(' -- Old rev') + print(oldrev) + print(' -- New rev') + print(newrev) + print(' -- Ref name') + print(refname) if set(newrev) == set(['0']): - print "Deletion is forbidden" + print("Deletion is forbidden") sys.exit(1) elif pagure.lib.git.is_forced_push(oldrev, newrev, abspath): - print "Non fast-forward push are forbidden" + print("Non fast-forward push are forbidden") sys.exit(1) diff --git a/pagure/hooks/files/pagure_hook.py b/pagure/hooks/files/pagure_hook.py index e28f5b9..94e8aa5 100755 --- a/pagure/hooks/files/pagure_hook.py +++ b/pagure/hooks/files/pagure_hook.py @@ -5,6 +5,8 @@ relates to an issue. """ +from __future__ import print_function + import logging import os import sys @@ -30,7 +32,7 @@ abspath = os.path.abspath(os.environ['GIT_DIR']) def generate_revision_change_log(new_commits_list): - print 'Detailed log of new commits:\n\n' + print('Detailed log of new commits:\n\n') commitid = None for line in pagure.lib.git.read_git_lines( ['log', '--no-walk'] + new_commits_list + ['--'], abspath): @@ -39,7 +41,7 @@ def generate_revision_change_log(new_commits_list): line = line.strip() - print '*', line + print('*', line) for relation in pagure.lib.link.get_relation( pagure.SESSION, pagure.lib.git.get_repo_name(abspath), @@ -86,7 +88,7 @@ def relates_commit(commitid, issue, app_url=None): ) pagure.SESSION.commit() except pagure.exceptions.PagureException as err: - print err + print(err) except SQLAlchemyError as err: # pragma: no cover pagure.SESSION.rollback() _log.exception(err) @@ -131,7 +133,7 @@ def fixes_relation(commitid, relation, app_url=None): ) pagure.SESSION.commit() except pagure.exceptions.PagureException as err: - print err + print(err) except SQLAlchemyError as err: # pragma: no cover pagure.SESSION.rollback() _log.exception(err) @@ -153,10 +155,10 @@ def fixes_relation(commitid, relation, app_url=None): merged=True) pagure.SESSION.commit() except pagure.exceptions.PagureException as err: - print err + print(err) except SQLAlchemyError as err: # pragma: no cover pagure.SESSION.rollback() - print 'ERROR', err + print('ERROR', err) _log.exception(err) @@ -164,16 +166,16 @@ def run_as_post_receive_hook(): for line in sys.stdin: if pagure.APP.config.get('HOOK_DEBUG', False): - print line + print(line) (oldrev, newrev, refname) = line.strip().split(' ', 2) if pagure.APP.config.get('HOOK_DEBUG', False): - print ' -- Old rev' - print oldrev - print ' -- New rev' - print newrev - print ' -- Ref name' - print refname + print(' -- Old rev') + print(oldrev) + print(' -- New rev') + print(newrev) + print(' -- Ref name') + print(refname) # Retrieve the default branch repo_obj = pygit2.Repository(abspath) @@ -187,16 +189,16 @@ def run_as_post_receive_hook(): continue if set(newrev) == set(['0']): - print "Deleting a reference/branch, so we won't run the "\ - "pagure hook" + print("Deleting a reference/branch, so we won't run the " + "pagure hook") return generate_revision_change_log( pagure.lib.git.get_revs_between(oldrev, newrev, abspath, refname)) if pagure.APP.config.get('HOOK_DEBUG', False): - print 'repo:', pagure.lib.git.get_repo_name(abspath) - print 'user:', pagure.lib.git.get_username(abspath) + print('repo:', pagure.lib.git.get_repo_name(abspath)) + print('user:', pagure.lib.git.get_username(abspath)) def main(args): diff --git a/pagure/hooks/files/pagure_hook_requests.py b/pagure/hooks/files/pagure_hook_requests.py index 31cc5a1..260e4f9 100755 --- a/pagure/hooks/files/pagure_hook_requests.py +++ b/pagure/hooks/files/pagure_hook_requests.py @@ -5,6 +5,8 @@ based on the information pushed in the requests git repository. """ +from __future__ import print_function + import json import os import sys @@ -24,7 +26,7 @@ abspath = os.path.abspath(os.environ['GIT_DIR']) def get_files_to_load(new_commits_list): - print 'Files changed by new commits:\n' + print('Files changed by new commits:\n') file_list = [] new_commits_list.reverse() for commit in new_commits_list: @@ -43,20 +45,20 @@ def run_as_post_receive_hook(): file_list = set() for line in sys.stdin: if pagure.APP.config.get('HOOK_DEBUG', False): - print line + print(line) (oldrev, newrev, refname) = line.strip().split(' ', 2) if pagure.APP.config.get('HOOK_DEBUG', False): - print ' -- Old rev' - print oldrev - print ' -- New rev' - print newrev - print ' -- Ref name' - print refname + print(' -- Old rev') + print(oldrev) + print(' -- New rev') + print(newrev) + print(' -- Ref name') + print(refname) if set(newrev) == set(['0']): - print "Deleting a reference/branch, so we won't run the "\ - "pagure hook" + print("Deleting a reference/branch, so we won't run the " + "pagure hook") return tmp = set(get_files_to_load( @@ -67,10 +69,10 @@ def run_as_post_receive_hook(): username = pagure.lib.git.get_username(abspath) namespace = pagure.lib.git.get_repo_namespace( abspath, gitfolder=pagure.APP.config['REQUESTS_FOLDER']) - print 'repo:', reponame, username, namespace + print('repo:', reponame, username, namespace) for filename in file_list: - print 'To load: %s' % filename + print('To load: %s' % filename) json_data = None data = ''.join( pagure.lib.git.read_git_lines( diff --git a/pagure/hooks/files/rtd_hook.py b/pagure/hooks/files/rtd_hook.py index 56c3dca..dad93d9 100755 --- a/pagure/hooks/files/rtd_hook.py +++ b/pagure/hooks/files/rtd_hook.py @@ -4,6 +4,8 @@ """Pagure specific hook to trigger a build on a readthedocs.org project. """ +from __future__ import print_function + import os import sys @@ -29,14 +31,14 @@ def run_as_post_receive_hook(): username = pagure.lib.git.get_username(abspath) namespace = pagure.lib.git.get_repo_namespace(abspath) if pagure.APP.config.get('HOOK_DEBUG', False): - print 'repo: ', reponame - print 'user: ', username - print 'namespace:', namespace + print('repo: ', reponame) + print('user: ', username) + print('namespace:', namespace) repo = pagure.get_authorized_project( pagure.SESSION, reponame, user=username, namespace=namespace) if not repo: - print 'Unknown repo %s of username: %s' % (reponame, username) + print('Unknown repo %s of username: %s' % (reponame, username)) sys.exit(1) pagure.lib.plugins.get_plugin('Read the Doc') @@ -58,18 +60,18 @@ def run_as_post_receive_hook(): for line in sys.stdin: if pagure.APP.config.get('HOOK_DEBUG', False): - print line + print(line) (oldrev, newrev, refname) = line.strip().split(' ', 2) refname = refname.replace('refs/heads/', '') if branches: if refname in branches: - print 'Starting RTD build for %s' % ( - repo.rtd_hook.project_name.strip()) + print('Starting RTD build for %s' % ( + repo.rtd_hook.project_name.strip())) requests.post(url) else: - print 'Starting RTD build for %s' % ( - repo.rtd_hook.project_name.strip()) + print('Starting RTD build for %s' % ( + repo.rtd_hook.project_name.strip())) requests.post(url)