From 37365ba5a3215d605b921aeae4818348d3e0fb18 Mon Sep 17 00:00:00 2001 From: Eklavya Sharma Date: Thu, 10 Mar 2016 21:45:34 +0530 Subject: [PATCH] Apply Python 3 futurize transform libfuturize.fixes.fix_print_with_import Refer #256 --- bots/check-mirroring | 3 ++- bots/check-rabbitmq-consumers | 3 ++- bots/check-rabbitmq-queue | 3 ++- bots/gcal-bot | 3 ++- bots/log2zulip | 7 ++++--- examples/create-user | 5 +++-- examples/edit-message | 3 ++- examples/get-public-streams | 3 ++- examples/list-members | 3 ++- examples/list-subscriptions | 3 ++- examples/print-events | 3 ++- examples/print-messages | 3 ++- examples/print-next-message | 3 ++- examples/send-message | 3 ++- examples/subscribe | 7 ++++--- examples/unsubscribe | 5 +++-- integrations/asana/zulip_asana_mirror | 5 +++-- integrations/codebase/zulip_codebase_mirror | 5 +++-- integrations/rss/rss-bot | 3 ++- integrations/twitter/twitter-bot | 5 +++-- integrations/twitter/twitter-search-bot | 7 ++++--- 21 files changed, 53 insertions(+), 32 deletions(-) diff --git a/bots/check-mirroring b/bots/check-mirroring index 775c7e8..a0215e8 100755 --- a/bots/check-mirroring +++ b/bots/check-mirroring @@ -1,4 +1,5 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import sys import time import optparse @@ -100,7 +101,7 @@ def print_status_and_exit(status): # e.g. true success and punting due to a SERVNAK, result in a # non-alert case, so to give us something unambiguous to check in # Nagios, print the exit status. - print status + print(status) sys.exit(status) def send_zulip(message): diff --git a/bots/check-rabbitmq-consumers b/bots/check-rabbitmq-consumers index 4f4c7ff..c0fcd32 100755 --- a/bots/check-rabbitmq-consumers +++ b/bots/check-rabbitmq-consumers @@ -1,5 +1,6 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import sys import time import optparse @@ -15,7 +16,7 @@ states = { } if 'USER' in os.environ and not os.environ['USER'] in ['root', 'rabbitmq']: - print "This script must be run as the root or rabbitmq user" + print("This script must be run as the root or rabbitmq user") usage = """Usage: check-rabbitmq-consumers --queue=[queue-name] --min-threshold=[min-threshold]""" diff --git a/bots/check-rabbitmq-queue b/bots/check-rabbitmq-queue index ba359f3..12373c5 100755 --- a/bots/check-rabbitmq-queue +++ b/bots/check-rabbitmq-queue @@ -1,5 +1,6 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import sys import re import time @@ -30,7 +31,7 @@ max_count = 0 warn_queues = [] if 'USER' in os.environ and not os.environ['USER'] in ['root', 'rabbitmq']: - print "This script must be run as the root or rabbitmq user" + print("This script must be run as the root or rabbitmq user") for line in output.split("\n"): line = line.strip() diff --git a/bots/gcal-bot b/bots/gcal-bot index e967336..a4548b8 100755 --- a/bots/gcal-bot +++ b/bots/gcal-bot @@ -1,4 +1,5 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import sys import time import datetime @@ -99,7 +100,7 @@ def send_reminders(): key = (uid, start) if key not in sent: line = '%s starts at %s' % (title, start.strftime('%H:%M')) - print 'Sending reminder:', line + print('Sending reminder:', line) messages.append(line) keys.add(key) diff --git a/bots/log2zulip b/bots/log2zulip index 449ddeb..32b509d 100755 --- a/bots/log2zulip +++ b/bots/log2zulip @@ -1,4 +1,5 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import subprocess import os import sys @@ -62,7 +63,7 @@ def process_logs(): file_data = last_data.get(log_file, {}) if not os.path.exists(log_file): # If the file doesn't exist, log an error and then move on to the next file - print "Log file does not exist or could not stat log file: %s" % (log_file,) + print("Log file does not exist or could not stat log file: %s" % (log_file,)) continue length = int(subprocess.check_output(["wc", "-l", log_file]).split()[0]) if file_data.get("last") is None: @@ -82,7 +83,7 @@ def process_logs(): if __name__ == "__main__": if os.path.exists(lock_path): - print "Log2zulip lock held; not doing anything" + print("Log2zulip lock held; not doing anything") sys.exit(0) try: @@ -91,7 +92,7 @@ if __name__ == "__main__": try: log_files = ujson.loads(file(control_path, "r").read()) except Exception: - print "Could not load control data from %s" % (control_path,) + print("Could not load control data from %s" % (control_path,)) traceback.print_exc() sys.exit(1) process_logs() diff --git a/examples/create-user b/examples/create-user index 6f2a379..2b8b6c9 100755 --- a/examples/create-user +++ b/examples/create-user @@ -21,6 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import sys from os import path import optparse @@ -46,9 +47,9 @@ parser.add_option('--new-short-name') client = zulip.init_from_options(options) -print client.create_user({ +print(client.create_user({ 'email': options.new_email, 'password': options.new_password, 'full_name': options.new_full_name, 'short_name': options.new_short_name - }) + })) diff --git a/examples/edit-message b/examples/edit-message index 609f291..d5eef21 100755 --- a/examples/edit-message +++ b/examples/edit-message @@ -21,6 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import sys import os import optparse @@ -53,4 +54,4 @@ if options.subject != "": message_data["subject"] = options.subject if options.content != "": message_data["content"] = options.content -print client.update_message(message_data) +print(client.update_message(message_data)) diff --git a/examples/get-public-streams b/examples/get-public-streams index 2137d13..8ba5405 100755 --- a/examples/get-public-streams +++ b/examples/get-public-streams @@ -21,6 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import sys import os import optparse @@ -43,4 +44,4 @@ parser.add_option_group(zulip.generate_option_group(parser)) client = zulip.init_from_options(options) -print client.get_streams(include_public=True, include_subscribed=False) +print(client.get_streams(include_public=True, include_subscribed=False)) diff --git a/examples/list-members b/examples/list-members index 70c1c1b..137e66a 100755 --- a/examples/list-members +++ b/examples/list-members @@ -21,6 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import sys import os import optparse @@ -42,4 +43,4 @@ parser.add_option_group(zulip.generate_option_group(parser)) client = zulip.init_from_options(options) for user in client.get_members()["members"]: - print user["full_name"], user["email"] + print(user["full_name"], user["email"]) diff --git a/examples/list-subscriptions b/examples/list-subscriptions index 6223dab..10678be 100755 --- a/examples/list-subscriptions +++ b/examples/list-subscriptions @@ -21,6 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import sys import os import optparse @@ -42,4 +43,4 @@ parser.add_option_group(zulip.generate_option_group(parser)) client = zulip.init_from_options(options) -print client.list_subscriptions() +print(client.list_subscriptions()) diff --git a/examples/print-events b/examples/print-events index a3d0457..aab7535 100755 --- a/examples/print-events +++ b/examples/print-events @@ -21,6 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import sys import os import optparse @@ -43,7 +44,7 @@ parser.add_option_group(zulip.generate_option_group(parser)) client = zulip.init_from_options(options) def print_event(event): - print event + print(event) # This is a blocking call, and will continuously poll for new events # Note also the filter here is messages to the stream Denmark; if you diff --git a/examples/print-messages b/examples/print-messages index f1a521e..f33d420 100755 --- a/examples/print-messages +++ b/examples/print-messages @@ -21,6 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import sys import os import optparse @@ -43,7 +44,7 @@ parser.add_option_group(zulip.generate_option_group(parser)) client = zulip.init_from_options(options) def print_message(message): - print message + print(message) # This is a blocking call, and will continuously poll for new messages client.call_on_each_message(print_message) diff --git a/examples/print-next-message b/examples/print-next-message index cf41e32..c8358d6 100755 --- a/examples/print-next-message +++ b/examples/print-next-message @@ -21,6 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import sys import os import optparse @@ -42,4 +43,4 @@ parser.add_option_group(zulip.generate_option_group(parser)) client = zulip.init_from_options(options) -print client.get_messages({}) +print(client.get_messages({})) diff --git a/examples/send-message b/examples/send-message index f257e57..518fe55 100755 --- a/examples/send-message +++ b/examples/send-message @@ -21,6 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import sys import os import optparse @@ -54,4 +55,4 @@ message_data = { "subject": options.subject, "to": args, } -print client.send_message(message_data) +print(client.send_message(message_data)) diff --git a/examples/subscribe b/examples/subscribe index 548a02e..a40a822 100755 --- a/examples/subscribe +++ b/examples/subscribe @@ -21,6 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import sys import os import optparse @@ -45,8 +46,8 @@ parser.add_option('--streams', default='') client = zulip.init_from_options(options) if options.streams == "": - print >>sys.stderr, "Usage:", parser.usage + print("Usage:", parser.usage, file=sys.stderr) sys.exit(1) -print client.add_subscriptions([{"name": stream_name} for stream_name in - options.streams.split()]) +print(client.add_subscriptions([{"name": stream_name} for stream_name in + options.streams.split()])) diff --git a/examples/unsubscribe b/examples/unsubscribe index 3b72173..693caae 100755 --- a/examples/unsubscribe +++ b/examples/unsubscribe @@ -21,6 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import sys import os import optparse @@ -45,7 +46,7 @@ parser.add_option('--streams', default='') client = zulip.init_from_options(options) if options.streams == "": - print >>sys.stderr, "Usage:", parser.usage + print("Usage:", parser.usage, file=sys.stderr) sys.exit(1) -print client.remove_subscriptions(options.streams.split()) +print(client.remove_subscriptions(options.streams.split())) diff --git a/integrations/asana/zulip_asana_mirror b/integrations/asana/zulip_asana_mirror index 0a7d2d9..f65dc21 100755 --- a/integrations/asana/zulip_asana_mirror +++ b/integrations/asana/zulip_asana_mirror @@ -30,6 +30,7 @@ # # python-dateutil is a dependency for this script. +from __future__ import print_function import base64 from datetime import datetime, timedelta @@ -45,8 +46,8 @@ try: import dateutil.parser import dateutil.tz except ImportError as e: - print >>sys.stderr, e - print >>sys.stderr, "Please install the python-dateutil package." + print(e, file=sys.stderr) + print("Please install the python-dateutil package.", file=sys.stderr) exit(1) sys.path.insert(0, os.path.dirname(__file__)) diff --git a/integrations/codebase/zulip_codebase_mirror b/integrations/codebase/zulip_codebase_mirror index f9445d1..10c487d 100755 --- a/integrations/codebase/zulip_codebase_mirror +++ b/integrations/codebase/zulip_codebase_mirror @@ -29,6 +29,7 @@ # # python-dateutil is a dependency for this script. +from __future__ import print_function import requests import logging import time @@ -41,8 +42,8 @@ from datetime import datetime, timedelta try: import dateutil.parser except ImportError as e: - print >>sys.stderr, e - print >>sys.stderr, "Please install the python-dateutil package." + print(e, file=sys.stderr) + print("Please install the python-dateutil package.", file=sys.stderr) exit(1) sys.path.insert(0, os.path.dirname(__file__)) diff --git a/integrations/rss/rss-bot b/integrations/rss/rss-bot index 73469f2..07a5808 100755 --- a/integrations/rss/rss-bot +++ b/integrations/rss/rss-bot @@ -23,6 +23,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import calendar import errno import hashlib @@ -97,7 +98,7 @@ try: mkdir_p(opts.data_dir) except OSError: # We can't write to the logfile, so just print and give up. - print >>sys.stderr, "Unable to store RSS data at %s." % (opts.data_dir,) + print("Unable to store RSS data at %s." % (opts.data_dir,), file=sys.stderr) exit(1) log_file = os.path.join(opts.data_dir, "rss-bot.log") diff --git a/integrations/twitter/twitter-bot b/integrations/twitter/twitter-bot index ec3ad03..e7ab8b6 100755 --- a/integrations/twitter/twitter-bot +++ b/integrations/twitter/twitter-bot @@ -23,6 +23,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import os import sys import optparse @@ -112,7 +113,7 @@ api = twitter.Api(consumer_key=consumer_key, user = api.VerifyCredentials() if not user.GetId(): - print "Unable to log in to twitter with supplied credentials. Please double-check and try again" + print("Unable to log in to twitter with supplied credentials. Please double-check and try again") sys.exit() try: @@ -154,7 +155,7 @@ for status in statuses[::-1][:options.limit_tweets]: if ret['result'] == 'error': # If sending failed (e.g. no such stream), abort and retry next time - print "Error sending message to zulip: %s" % ret['msg'] + print("Error sending message to zulip: %s" % ret['msg']) break else: since_id = status.GetId() diff --git a/integrations/twitter/twitter-search-bot b/integrations/twitter/twitter-search-bot index 64938f5..6e29bc0 100755 --- a/integrations/twitter/twitter-search-bot +++ b/integrations/twitter/twitter-search-bot @@ -23,6 +23,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. +from __future__ import print_function import os import sys import optparse @@ -138,8 +139,8 @@ api = twitter.Api(consumer_key=consumer_key, user = api.VerifyCredentials() if not user.GetId(): - print "Unable to log in to Twitter with supplied credentials.\ -Please double-check and try again." + print("Unable to log in to Twitter with supplied credentials.\ +Please double-check and try again.") sys.exit() client = zulip.Client( @@ -182,7 +183,7 @@ for status in statuses[::-1][:opts.limit_tweets]: if ret['result'] == 'error': # If sending failed (e.g. no such stream), abort and retry next time - print "Error sending message to zulip: %s" % ret['msg'] + print("Error sending message to zulip: %s" % ret['msg']) break else: since_id = status.GetId()