diff --git a/api/examples/create-user b/api/examples/create-user index 6f2a3795ca..2b8b6c92b4 100755 --- a/api/examples/create-user +++ b/api/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/api/examples/edit-message b/api/examples/edit-message index 609f2912cb..d5eef21931 100755 --- a/api/examples/edit-message +++ b/api/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/api/examples/get-public-streams b/api/examples/get-public-streams index 2137d130c5..8ba5405ed7 100755 --- a/api/examples/get-public-streams +++ b/api/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/api/examples/list-members b/api/examples/list-members index 70c1c1b1af..137e66a130 100755 --- a/api/examples/list-members +++ b/api/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/api/examples/list-subscriptions b/api/examples/list-subscriptions index 6223dab727..10678beceb 100755 --- a/api/examples/list-subscriptions +++ b/api/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/api/examples/print-events b/api/examples/print-events index a3d04576b9..aab7535b2c 100755 --- a/api/examples/print-events +++ b/api/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/api/examples/print-messages b/api/examples/print-messages index f1a521e487..f33d4202c3 100755 --- a/api/examples/print-messages +++ b/api/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/api/examples/print-next-message b/api/examples/print-next-message index cf41e3283d..c8358d68b9 100755 --- a/api/examples/print-next-message +++ b/api/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/api/examples/send-message b/api/examples/send-message index f257e5784f..518fe55958 100755 --- a/api/examples/send-message +++ b/api/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/api/examples/subscribe b/api/examples/subscribe index 548a02ed07..a40a82231c 100755 --- a/api/examples/subscribe +++ b/api/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/api/examples/unsubscribe b/api/examples/unsubscribe index 3b72173582..693caaebfe 100755 --- a/api/examples/unsubscribe +++ b/api/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/api/integrations/asana/zulip_asana_mirror b/api/integrations/asana/zulip_asana_mirror index 0a7d2d99e4..f65dc21835 100755 --- a/api/integrations/asana/zulip_asana_mirror +++ b/api/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/api/integrations/codebase/zulip_codebase_mirror b/api/integrations/codebase/zulip_codebase_mirror index f9445d1a85..10c487d1c2 100755 --- a/api/integrations/codebase/zulip_codebase_mirror +++ b/api/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/api/integrations/rss/rss-bot b/api/integrations/rss/rss-bot index 73469f2cfc..07a5808ab1 100755 --- a/api/integrations/rss/rss-bot +++ b/api/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/api/integrations/twitter/twitter-bot b/api/integrations/twitter/twitter-bot index ec3ad033f0..e7ab8b6f21 100755 --- a/api/integrations/twitter/twitter-bot +++ b/api/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/api/integrations/twitter/twitter-search-bot b/api/integrations/twitter/twitter-search-bot index 64938f5575..6e29bc0613 100755 --- a/api/integrations/twitter/twitter-search-bot +++ b/api/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() diff --git a/bin/get-django-setting b/bin/get-django-setting index 675733219a..fe945676bf 100755 --- a/bin/get-django-setting +++ b/bin/get-django-setting @@ -1,5 +1,6 @@ #!/usr/bin/env python2.7 from __future__ import absolute_import +from __future__ import print_function import os import sys @@ -8,4 +9,4 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings' from django.conf import settings -print getattr(settings, sys.argv[1]) +print(getattr(settings, sys.argv[1])) diff --git a/bots/check-mirroring b/bots/check-mirroring index 775c7e8fa4..a0215e8b0f 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 4f4c7ffa7a..c0fcd32d0b 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 ba359f329f..12373c5be6 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 e9673366b1..a4548b80ed 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 449ddeb667..32b509d569 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/frontend_tests/casperjs/bin/casperjs b/frontend_tests/casperjs/bin/casperjs index e914cd6f85..f04ca9e802 100755 --- a/frontend_tests/casperjs/bin/casperjs +++ b/frontend_tests/casperjs/bin/casperjs @@ -1,5 +1,6 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import json import os import subprocess diff --git a/frontend_tests/run-casper b/frontend_tests/run-casper index a38de9afc9..14ed659539 100755 --- a/frontend_tests/run-casper +++ b/frontend_tests/run-casper @@ -1,4 +1,5 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import subprocess import requests import optparse @@ -80,18 +81,18 @@ try: cmd += ' '.join(test_files) else: cmd += 'frontend_tests/casper_tests' - print "Running %s" % (cmd,) + print("Running %s" % (cmd,)) ret = subprocess.call(cmd, shell=True) finally: assert_server_running() server.terminate() if ret != 0: - print >>sys.stderr, """ + print(""" Oops, the frontend tests failed. Tips for debugging: * Check the frontend test server logs at frontend_tests/casper_tests/server.log * Check the screenshots of failed tests at /tmp/casper-failure*.png * Try remote debugging the test web browser as described in docs/testing.rst -""" +""", file=sys.stderr) sys.exit(ret) diff --git a/puppet/zulip/files/nagios_plugins/check_queue_worker_errors b/puppet/zulip/files/nagios_plugins/check_queue_worker_errors index 4c2ffb4d7f..eacef5b54d 100755 --- a/puppet/zulip/files/nagios_plugins/check_queue_worker_errors +++ b/puppet/zulip/files/nagios_plugins/check_queue_worker_errors @@ -3,6 +3,7 @@ """ Nagios plugin to check that none of our queue workers have reported errors. """ +from __future__ import print_function import sys sys.path.append('/home/zulip/deployments/current') diff --git a/puppet/zulip_internal/files/nagios_plugins/check_fts_update_log b/puppet/zulip_internal/files/nagios_plugins/check_fts_update_log index 98bb19fba0..906a001628 100755 --- a/puppet/zulip_internal/files/nagios_plugins/check_fts_update_log +++ b/puppet/zulip_internal/files/nagios_plugins/check_fts_update_log @@ -3,6 +3,7 @@ """ Nagios plugin to check the length of the FTS update log. """ +from __future__ import print_function import psycopg2 @@ -14,7 +15,7 @@ states = { } def report(state, num): - print "%s: %s rows in fts_update_log table" % (state, num) + print("%s: %s rows in fts_update_log table" % (state, num)) exit(states[state]) conn = psycopg2.connect("user=zulip") diff --git a/puppet/zulip_internal/files/nagios_plugins/check_personal_zephyr_mirrors b/puppet/zulip_internal/files/nagios_plugins/check_personal_zephyr_mirrors index cf71099b59..1ea74bd725 100755 --- a/puppet/zulip_internal/files/nagios_plugins/check_personal_zephyr_mirrors +++ b/puppet/zulip_internal/files/nagios_plugins/check_personal_zephyr_mirrors @@ -8,6 +8,7 @@ This script works by just monitoring the files under mirrors when they receive the messages sent every minute by /etc/cron.d/test_zephyr_personal_mirrors """ +from __future__ import print_function import os import time @@ -22,7 +23,7 @@ states = { } def report(state, output): - print "%s\n%s" % (state, output) + print("%s\n%s" % (state, output)) exit(states[state]) output = "" diff --git a/puppet/zulip_internal/files/nagios_plugins/check_pg_replication_lag b/puppet/zulip_internal/files/nagios_plugins/check_pg_replication_lag index ed709986e5..8d755435bf 100755 --- a/puppet/zulip_internal/files/nagios_plugins/check_pg_replication_lag +++ b/puppet/zulip_internal/files/nagios_plugins/check_pg_replication_lag @@ -4,6 +4,7 @@ Nagios plugin to check the difference between the primary and secondary Postgres servers' xlog location. """ +from __future__ import print_function import subprocess import re @@ -16,7 +17,7 @@ states = { } def report(state, msg): - print "%s: %s" % (state, msg) + print("%s: %s" % (state, msg)) exit(states[state]) def get_loc_over_ssh(host, func): diff --git a/puppet/zulip_internal/files/nagios_plugins/check_postgres_backup b/puppet/zulip_internal/files/nagios_plugins/check_postgres_backup index e653e60e90..1c442ae317 100755 --- a/puppet/zulip_internal/files/nagios_plugins/check_postgres_backup +++ b/puppet/zulip_internal/files/nagios_plugins/check_postgres_backup @@ -1,5 +1,6 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import dateutil.parser import pytz import subprocess @@ -13,7 +14,7 @@ states = { } def report(state, msg): - print "%s: %s" % (state, msg) + print("%s: %s" % (state, msg)) exit(states[state]) if subprocess.check_output(['psql', 'postgres', '-t', '-c', diff --git a/puppet/zulip_internal/files/nagios_plugins/check_rabbitmq_consumers b/puppet/zulip_internal/files/nagios_plugins/check_rabbitmq_consumers index f698fec367..7996c64e3d 100755 --- a/puppet/zulip_internal/files/nagios_plugins/check_rabbitmq_consumers +++ b/puppet/zulip_internal/files/nagios_plugins/check_rabbitmq_consumers @@ -8,6 +8,7 @@ which is generated by bots/check-rabbitmq-consumers. It is run by cron and can be found at bots/rabbitmq-numconsumers-crontab """ +from __future__ import print_function import sys @@ -15,12 +16,12 @@ sys.path.append('/home/zulip/deployments/current') from bots.cron_file_helper import nagios_from_file if len(sys.argv) < 2: - print "Please pass the name of the consumer file to check" + print("Please pass the name of the consumer file to check") exit(1) RESULTS_FILE = "/var/lib/nagios_state/check-rabbitmq-consumers-%s" % (sys.argv[1]) ret, result = nagios_from_file(RESULTS_FILE) -print result +print(result) exit(ret) diff --git a/puppet/zulip_internal/files/nagios_plugins/check_rabbitmq_queues b/puppet/zulip_internal/files/nagios_plugins/check_rabbitmq_queues index 5fc052015e..5a16f86ff3 100755 --- a/puppet/zulip_internal/files/nagios_plugins/check_rabbitmq_queues +++ b/puppet/zulip_internal/files/nagios_plugins/check_rabbitmq_queues @@ -9,6 +9,7 @@ which is generated by bots/check-rabbitmq-queue. It is run by cron and can be found at bots/rabbitmq-queuesize-crontab """ +from __future__ import print_function import sys @@ -18,5 +19,5 @@ from bots.cron_file_helper import nagios_from_file RESULTS_FILE = "/var/lib/nagios_state/check-rabbitmq-results" ret, result = nagios_from_file(RESULTS_FILE) -print result +print(result) exit(ret) diff --git a/puppet/zulip_internal/files/nagios_plugins/check_send_receive_time b/puppet/zulip_internal/files/nagios_plugins/check_send_receive_time index 1b7c754abc..54bf1660b0 100755 --- a/puppet/zulip_internal/files/nagios_plugins/check_send_receive_time +++ b/puppet/zulip_internal/files/nagios_plugins/check_send_receive_time @@ -8,6 +8,7 @@ It supports both munin and nagios outputs It must be run on a machine that is using the live database for the Django ORM. """ +from __future__ import print_function import datetime import sys @@ -42,23 +43,22 @@ parser.add_option('--munin', (options, args) = parser.parse_args() if not options.nagios and not options.munin: - print 'No output options specified! Please provide --munin or --nagios' + print('No output options specified! Please provide --munin or --nagios') sys.exit(0) if len(args) > 2: - print usage + print(usage) sys.exit(0) if options.munin: if len(args) and args[0] == 'config': - print \ -"""graph_title Send-Receive times + print("""graph_title Send-Receive times graph_info The number of seconds it takes to send and receive a message from the server graph_args -u 5 -l 0 graph_vlabel RTT (seconds) sendreceive.label Send-receive round trip time sendreceive.warning 3 -sendreceive.critical 5""" +sendreceive.critical 5""") sys.exit(0) sys.path.append('/home/zulip/deployments/current/api') @@ -81,9 +81,9 @@ states = { def report(state, time, msg=None): if msg: - print "%s: %s" % (state, msg) + print("%s: %s" % (state, msg)) else: - print "%s: send time was %s" % (state, time) + print("%s: send time was %s" % (state, time)) exit(states[state]) def send_zulip(sender, message): @@ -148,7 +148,7 @@ while msg_to_send not in msg_content: msg_content = [m['content'] for m in messages] -print zulip_recipient.deregister(queue_id) +print(zulip_recipient.deregister(queue_id)) if options.nagios: if time_diff.seconds > 3: @@ -157,6 +157,6 @@ if options.nagios: report('CRITICAL', time_diff) if options.munin: - print "sendreceive.value %s" % total_seconds(time_diff) + print("sendreceive.value %s" % total_seconds(time_diff)) elif options.nagios: report('OK', time_diff) diff --git a/puppet/zulip_internal/files/nagios_plugins/check_user_zephyr_mirror_liveness b/puppet/zulip_internal/files/nagios_plugins/check_user_zephyr_mirror_liveness index b89efdac3a..ff2bc41a08 100755 --- a/puppet/zulip_internal/files/nagios_plugins/check_user_zephyr_mirror_liveness +++ b/puppet/zulip_internal/files/nagios_plugins/check_user_zephyr_mirror_liveness @@ -6,6 +6,7 @@ Nagios plugin to check that our MIT users' Zephyr mirrors are running. It must be run on a machine that is using the live database for the Django ORM. """ +from __future__ import print_function import datetime import os @@ -37,7 +38,7 @@ def report(state, short_msg, too_old=None): user.last_visit.strftime("%Y-%m-%d %H:%M %Z") ) for user in too_old] ) - print "%s: %s%s" % (state, short_msg, too_old_data) + print("%s: %s%s" % (state, short_msg, too_old_data)) exit(states[state]) diff --git a/puppet/zulip_internal/files/nagios_plugins/check_zephyr_mirror b/puppet/zulip_internal/files/nagios_plugins/check_zephyr_mirror index 6a8f45016d..c769a3d5e3 100755 --- a/puppet/zulip_internal/files/nagios_plugins/check_zephyr_mirror +++ b/puppet/zulip_internal/files/nagios_plugins/check_zephyr_mirror @@ -8,6 +8,7 @@ itself lives in api/bots/check-mirroring and should be run out of cron. See bots/zephyr-mirror-crontab for the crontab details. """ +from __future__ import print_function import os import time @@ -22,9 +23,9 @@ states = { } def report(state, data, last_check): - print "%s: Last test run completed at %s\n%s" % ( + print("%s: Last test run completed at %s\n%s" % ( state, time.strftime("%Y-%m-%d %H:%M %Z", time.gmtime(last_check)), - data) + data)) exit(states[state]) data = file(RESULTS_FILE).read().strip() diff --git a/scripts/lib/unpack-zulip b/scripts/lib/unpack-zulip index 112fd1401f..824c5c7b2c 100755 --- a/scripts/lib/unpack-zulip +++ b/scripts/lib/unpack-zulip @@ -1,4 +1,5 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import os import sys import subprocess @@ -12,7 +13,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), '..', "..")) from zulip_tools import DEPLOYMENTS_DIR, FAIL, ENDC, make_deploy_path if len(sys.argv) != 2: - print FAIL + "Usage: %s " % (sys.argv[0],) + ENDC + print(FAIL + "Usage: %s " % (sys.argv[0],) + ENDC) sys.exit(1) tarball_path = sys.argv[1] @@ -27,5 +28,5 @@ subprocess.check_call(["ln", "-nsf", "/etc/zulip/settings.py", os.path.join(deploy_path, "zproject/local_settings.py")]) subprocess.check_call(["ln", '-nsf', deploy_path, os.path.join(DEPLOYMENTS_DIR, "next")]) -print deploy_path +print(deploy_path) sys.exit(0) diff --git a/scripts/lib/upgrade-zulip b/scripts/lib/upgrade-zulip index 78a8a1f2c7..d6665878d7 100755 --- a/scripts/lib/upgrade-zulip +++ b/scripts/lib/upgrade-zulip @@ -1,4 +1,5 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import os import shutil import sys @@ -20,7 +21,7 @@ if os.getuid() != 0: sys.exit(1) if len(sys.argv) != 2: - print FAIL + "Usage: %s " % (sys.argv[0],) + ENDC + print(FAIL + "Usage: %s " % (sys.argv[0],) + ENDC) sys.exit(1) tarball_path = sys.argv[1] diff --git a/scripts/lib/upgrade-zulip-stage-2 b/scripts/lib/upgrade-zulip-stage-2 index dca7edd147..bacec9a6ba 100755 --- a/scripts/lib/upgrade-zulip-stage-2 +++ b/scripts/lib/upgrade-zulip-stage-2 @@ -4,6 +4,7 @@ # version of Zulip to the new version. upgrade-zulip-stage-2 is # always run from the new version of Zulip, so any bug fixes take # effect on the very next upgrade. +from __future__ import print_function import subprocess import os import sys @@ -22,7 +23,7 @@ if os.getuid() != 0: sys.exit(1) if len(sys.argv) != 2: - print FAIL + "Usage: %s " % (sys.argv[0],) + ENDC + print(FAIL + "Usage: %s " % (sys.argv[0],) + ENDC) sys.exit(1) deploy_path = sys.argv[1] diff --git a/scripts/restart-server b/scripts/restart-server index 7dd2f89fd7..1fe6d65cae 100755 --- a/scripts/restart-server +++ b/scripts/restart-server @@ -1,4 +1,5 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import os import sys import pwd @@ -42,4 +43,4 @@ if using_sso.strip() == 'True': subprocess.check_call(["pkill", "-f", "apache2", "-u", "zulip"]) logging.info("Done!") -print OKGREEN + "Application restarted successfully!" + ENDC +print(OKGREEN + "Application restarted successfully!" + ENDC) diff --git a/tools/compile-handlebars-templates b/tools/compile-handlebars-templates index 544bf729fc..64e7debf57 100755 --- a/tools/compile-handlebars-templates +++ b/tools/compile-handlebars-templates @@ -1,5 +1,6 @@ #!/usr/bin/env python2.7 from __future__ import absolute_import +from __future__ import print_function import os import glob @@ -36,12 +37,12 @@ def run_forever(): changed = True mtimes[fn] = new_mtime if changed: - print 'Recompiling templates' + print('Recompiling templates') try: run() - print 'done' + print('done') except: - print '\n\n\nPLEASE FIX!!\n\n' + print('\n\n\nPLEASE FIX!!\n\n') time.sleep(0.200) if __name__ == '__main__': diff --git a/tools/deprecated/iframe-bot/show-last-messages b/tools/deprecated/iframe-bot/show-last-messages index 8b63af9b56..9adabd3c0c 100755 --- a/tools/deprecated/iframe-bot/show-last-messages +++ b/tools/deprecated/iframe-bot/show-last-messages @@ -8,6 +8,7 @@ ### (to static/third/gemoji/images/) +from __future__ import print_function import sys sys.path.append('zulip') import os @@ -35,7 +36,7 @@ parser.add_option('--count', default=5) 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) client.add_subscriptions([{"name": stream_name} for stream_name in diff --git a/tools/deprecated/inject-messages/inject-messages b/tools/deprecated/inject-messages/inject-messages index a7f3c35edb..52e6c32904 100755 --- a/tools/deprecated/inject-messages/inject-messages +++ b/tools/deprecated/inject-messages/inject-messages @@ -2,6 +2,7 @@ # # This is tool for injecting messages during a usability study. It's # likely useless for other applications. +from __future__ import print_function import sys import os import optparse @@ -68,15 +69,15 @@ def send_message(character, text, subject): 'subject': truncate(subject, 60)} response = client.send_message(request) if response['result'] != 'success': - print "Could not send message (API Key " + characters[character]["api-key"] + "):" - print " Request:", request - print " Response:", response + print("Could not send message (API Key " + characters[character]["api-key"] + "):") + print(" Request:", request) + print(" Response:", response) exit(1) last_character = character num_messages_sent += 1 if num_messages_sent % 100 == 0: - print "Sent %s messages" % (num_messages_sent,) + print("Sent %s messages" % (num_messages_sent,)) def maybe_assign_character(character): global characters @@ -115,4 +116,4 @@ for line in play: send_message(next_character, next_message, subject) next_message = '' -print "Sent %s messages" % (num_messages_sent,) +print("Sent %s messages" % (num_messages_sent,)) diff --git a/tools/deprecated/review b/tools/deprecated/review index 0730b46ee9..1b913376cb 100755 --- a/tools/deprecated/review +++ b/tools/deprecated/review @@ -19,6 +19,7 @@ # Author: Greg Price from __future__ import unicode_literals +from __future__ import print_function ## CC_EMAIL: All review requests will be CC'd here. CC_EMAIL = 'listname@example.com' @@ -172,22 +173,22 @@ def make_header(repo, opts, revs): always=True).split() local_name = unicode(local_name, "utf-8") if local_name == "undefined": - print >>sys.stderr, "ERROR: Can't find this commit in remote or identify local branch!" + print("ERROR: Can't find this commit in remote or identify local branch!", file=sys.stderr) sys.exit(1) email_basename = get_current_user_email(repo).split("@")[0] if local_name.startswith("%s-" % (email_basename,)): # Try to push the local branch to the remote automatically try: - print "Attempting to push %s to remote %s" % (local_name, remote) + print("Attempting to push %s to remote %s" % (local_name, remote)) repo.git.push(remote, local_name) tip_name = '%s (%s)' % (local_name, revs[-1].hexsha[:7]) except git.GitCommandError as e: - print >>sys.stderr, "ERROR: Couldn't push %s to remote" % (local_name,) - print >>sys.stderr, e + print("ERROR: Couldn't push %s to remote" % (local_name,), file=sys.stderr) + print(e, file=sys.stderr) sys.exit(1) else: - print >>sys.stderr, "ERROR: Can't find this commit in remote -- did you push %s?" % (local_name) + print("ERROR: Can't find this commit in remote -- did you push %s?" % (local_name), file=sys.stderr) sys.exit(1) objective_summary = '%d commit(s) to %s' % (len(revs), tip_name) @@ -204,44 +205,44 @@ def make_header(repo, opts, revs): def write_template(target, repo, opts): me = get_current_user(repo) - print >>target, 'Dear %s,' % ", ".join(opts.reviewers) - print >>target - print >>target, 'At your convenience, please review the following commits.' - print >>target + print('Dear %s,' % ", ".join(opts.reviewers), file=target) + print(file=target) + print('At your convenience, please review the following commits.', file=target) + print(file=target) if opts.message: - print >>target, opts.message - print >>target - print >>target, 'Testing:' + print(opts.message, file=target) + print(file=target) + print('Testing:', file=target) if opts.testing: - print >>target, opts.testing + print(opts.testing, file=target) else: - print >>target, '(No formal testing done, or none specified.)' - print >>target - print >>target, 'Thanks,' - print >>target, me + print('(No formal testing done, or none specified.)', file=target) + print(file=target) + print('Thanks,', file=target) + print(me, file=target) def write_commitmsg(target, repo, opts, revs): if opts.format == 'oneline': for r in revs: - print >>target, unicode(repo.git.log('-n1', '--oneline', r), 'utf-8', 'replace') + print(unicode(repo.git.log('-n1', '--oneline', r), 'utf-8', 'replace'), file=target) elif opts.format == 'message' or opts.format is None and len(revs) > 1: for r in revs: if opts.first_parent: - print >>target, unicode(repo.git.log('-n1', r), 'utf-8', 'replace') - print >>target, unicode(repo.git.diff('--stat', str(r)+'^', r), 'utf-8', 'replace') + print(unicode(repo.git.log('-n1', r), 'utf-8', 'replace'), file=target) + print(unicode(repo.git.diff('--stat', str(r)+'^', r), 'utf-8', 'replace'), file=target) else: - print >>target, unicode(repo.git.log('-n1', '--stat', r), 'utf-8', 'replace') - print >>target + print(unicode(repo.git.log('-n1', '--stat', r), 'utf-8', 'replace'), file=target) + print(file=target) elif opts.format == 'patch' or opts.format is None and len(revs) == 1: for r in revs: if opts.first_parent: - print >>target, unicode(repo.git.log('-n1', r), 'utf-8', 'replace') - print >>target, unicode(repo.git.diff('--stat', '-p', str(r)+'^', r), 'utf-8', 'replace') + print(unicode(repo.git.log('-n1', r), 'utf-8', 'replace'), file=target) + print(unicode(repo.git.diff('--stat', '-p', str(r)+'^', r), 'utf-8', 'replace'), file=target) else: - print >>target, unicode(repo.git.log('-n1', '--stat', '-p', r), 'utf-8', 'replace') - print >>target + print(unicode(repo.git.log('-n1', '--stat', '-p', r), 'utf-8', 'replace'), file=target) + print(file=target) else: raise Exception("Bad format option.") @@ -257,15 +258,15 @@ def edit(repo, opts, revs, headers): # Prepare editable buffer. - print >>temp, """# This is an editable review request. All lines beginning with # will -# be ignored. To abort the commit, remove all lines from this buffer.""" - print >>temp, "#" + print("""# This is an editable review request. All lines beginning with # will +# be ignored. To abort the commit, remove all lines from this buffer.""", file=temp) + print("#", file=temp) for (key, value) in headers: - print >>temp, u"# %s: %s" % (key, value) - print >>temp - print >>temp, template.getvalue() + print(u"# %s: %s" % (key, value), file=temp) + print(file=temp) + print(template.getvalue(), file=temp) for line in commitmsg.getvalue().splitlines(): - print >>temp, "# " + line + print("# " + line, file=temp) temp.flush() # Open EDITOR to edit buffer. @@ -276,7 +277,7 @@ def edit(repo, opts, revs, headers): # Check if buffer is empty, and if so abort. if (os.path.getsize(temp.name) == 0): - print >>sys.stderr, "Aborting due to empty buffer." + print("Aborting due to empty buffer.", file=sys.stderr) sys.exit(2) # Reopen temp file, slurp it in, and reconstruct mail. @@ -301,7 +302,7 @@ def edit(repo, opts, revs, headers): return msg def clone_to_tmp(repo, tmp_path, test_existence_only=False): - print "Cloning into", tmp_path + print("Cloning into", tmp_path) assert not os.path.exists(tmp_path), \ 'Path ' + tmp_path + ' exists. Either another test is running there ' \ 'or it was left there so that you could view the testing log. If you are sure ' \ @@ -313,7 +314,7 @@ def clone_to_tmp(repo, tmp_path, test_existence_only=False): return clone def cleanup_tmp(cloned_repo): - print "Cleaning up..." + print("Cleaning up...") assert os.path.exists(cloned_repo.working_tree_dir), "could not find " + cloned_repo.working_tree_dir rmtree(cloned_repo.working_tree_dir) return @@ -337,7 +338,7 @@ def run_test_script(repo, tmp_path): os.environ["PWD"] = os.getcwd() log = open("test.log", 'w') log_path = os.getcwd() + "/" + log.name - print "Testing [log=%s] ..." % (log_path,) + print("Testing [log=%s] ..." % (log_path,)) try: proc = subprocess.Popen(TEST_SCRIPT, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=sys.stdin) # Set the proc.stdout.read() to be non-blocking @@ -358,8 +359,8 @@ def run_test_script(repo, tmp_path): continue sleep(.5) except KeyboardInterrupt as e: - print "\nkilling tests..." - print "You may find the testing log in", log_path + print("\nkilling tests...") + print("You may find the testing log in", log_path) proc.send_signal(SIGINT) sleep(2) proc.send_signal(SIGTERM) @@ -372,8 +373,8 @@ def run_test_script(repo, tmp_path): sys.stdout.write(buf) log.write(buf) if proc.returncode!=0: - print TEST_SCRIPT, "exited with status code", proc.returncode - print "You may find the testing log in", log_path + print(TEST_SCRIPT, "exited with status code", proc.returncode) + print("You may find the testing log in", log_path) else: os.chdir(working_dir) os.environ["PWD"] = os.getcwd() @@ -385,19 +386,19 @@ def main(args): repo = git.Repo() revs = parse_revs(repo, opts, args[1:]) if not revs: - print >>sys.stderr, '%s: no revisions specified' % os.path.basename(args[0]) + print('%s: no revisions specified' % os.path.basename(args[0]), file=sys.stderr) return 2 if not opts.stdout: client = zulip.Client(verbose=True, client="ZulipReview/0.1") if 'staging' in client.base_url: - print ''' + print(''' HEY! You still have your .zuliprc pointing to staging. ABORTING - ''' + ''') sys.exit(1) # Attempt to catch permissions/invalid paths early for tmp_dir @@ -438,15 +439,15 @@ def main(args): if testing_status_code != 0: commit_message_path = opts.tmp_dir + "/commit.msg" open(commit_message_path, 'w').write(msg.get_payload(decode=True)) - print "You may find your commit message at", commit_message_path + print("You may find your commit message at", commit_message_path) - print "Processing review message..." + print("Processing review message...") # Send or print the message, as appropriate. if opts.stdout: for (key, value) in msg.items(): - print >>sys.stdout, u"%s: %s" % (key, value) - print >>sys.stdout - print >>sys.stdout, msg.get_payload(decode=True), + print(u"%s: %s" % (key, value), file=sys.stdout) + print(file=sys.stdout) + print(msg.get_payload(decode=True), end=' ', file=sys.stdout) else: reviewer_usernames = [x.split("@")[0] for x in opts.reviewers] diff --git a/tools/get-handlebar-vars b/tools/get-handlebar-vars index 74490afe15..f551a2d9b0 100755 --- a/tools/get-handlebar-vars +++ b/tools/get-handlebar-vars @@ -1,4 +1,5 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import sys import re import json @@ -98,9 +99,9 @@ def parse_file(fn): if __name__ == '__main__': for fn in sys.argv[1:]: - print '===', fn + print('===', fn) root = parse_file(fn) debug(root) - print + print() diff --git a/tools/lint-all b/tools/lint-all index 3c823bde70..1862f77380 100755 --- a/tools/lint-all +++ b/tools/lint-all @@ -1,4 +1,5 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import os import re import sys @@ -127,10 +128,10 @@ def custom_check_file(fn, rules, skip_rules=[]): try: if re.search(rule['pattern'], line.strip(rule.get('strip', None))): sys.stdout.write(rule['description'] + ' at %s line %s:\n' % (fn, i+1)) - print line + print(line) failed = True except Exception: - print "Exception with %s at %s line %s" % (rule['pattern'], fn, i+1) + print("Exception with %s at %s line %s" % (rule['pattern'], fn, i+1)) traceback.print_exc() return failed diff --git a/tools/minify-js b/tools/minify-js index e9326f6b7e..32aa05c012 100755 --- a/tools/minify-js +++ b/tools/minify-js @@ -3,6 +3,7 @@ # Minifies JavaScripts, creating source maps from __future__ import absolute_import +from __future__ import print_function import os import subprocess @@ -48,7 +49,7 @@ def get_changed_source_files(other_checkout): except subprocess.CalledProcessError: # If git returned an error, assume we can't reuse any files, and # regenerate everything. - print "Warning: git returned an error when comparing to the previous" + print("Warning: git returned an error when comparing to the previous") print ("deploy in %s. Will re-minify JavaScript instead of reusing" % (other_checkout,)) return None @@ -82,8 +83,8 @@ CLOSURE_BINARY = '/usr/bin/closure-compiler' if not os.path.exists(CLOSURE_BINARY): CLOSURE_BINARY = 'tools/closure-compiler/run' if not os.path.exists(CLOSURE_BINARY): - print "closure-compiler not installed; the Vagrant provision.py installs it via apt "\ - "or you can manually unpack http://dl.google.com/closure-compiler/compiler-latest.zip to tools/closure-compiler" + print("closure-compiler not installed; the Vagrant provision.py installs it via apt "\ + "or you can manually unpack http://dl.google.com/closure-compiler/compiler-latest.zip to tools/closure-compiler") sys.exit(1) # Where to put minified JS and source maps diff --git a/tools/post-receive b/tools/post-receive index 40117f2455..3307806e17 100755 --- a/tools/post-receive +++ b/tools/post-receive @@ -28,6 +28,7 @@ # # see contrib/hooks/ for a sample +from __future__ import print_function import os import sys import subprocess @@ -73,6 +74,6 @@ for ln in sys.stdin: commits = subprocess.check_output(["git", "log", "%s..%s" % (oldrev, newrev)]) if '[schema]' in commits: - print - print FAIL + "Schema change detected! Please make the appropriate changes manually." + ENDC - print + print() + print(FAIL + "Schema change detected! Please make the appropriate changes manually." + ENDC) + print() diff --git a/tools/python-proxy b/tools/python-proxy index 27db14d113..36eb77d5c1 100755 --- a/tools/python-proxy +++ b/tools/python-proxy @@ -81,6 +81,7 @@ Qual a diferen São enviados os cabeçalhos HTTP "Proxy-agent" e "HTTP_X_FORWARDED_FOR". """ +from __future__ import print_function import socket, thread, select PORT = 8085 @@ -115,7 +116,7 @@ class ConnectionHandler: return data def method_CONNECT(self): - print 'self.path', self.path + print('self.path', self.path) self._connect_target(self.path) self.client.send(HTTPVER+' 200 Connection established\n'+ 'Proxy-agent: %s\n\n'%VERSION) @@ -123,28 +124,28 @@ class ConnectionHandler: self._read_write() def method_others(self): - print - print '=====================================' - print 'method', self.method - print 'protocol', self.protocol - print 'self.path', self.path - print + print() + print('=====================================') + print('method', self.method) + print('protocol', self.protocol) + print('self.path', self.path) + print() horking = False if horking: if self.path.endswith('.js'): - print 'HORKING JS!!!!!!!' - print + print('HORKING JS!!!!!!!') + print() return if self.path.endswith('.png'): - print 'HORKING PNG!!!!!!!' - print + print('HORKING PNG!!!!!!!') + print() return if self.path.endswith('.css'): - print 'HORKING CSS!!!!!!!' - print + print('HORKING CSS!!!!!!!') + print() return self._connect_target() @@ -160,7 +161,7 @@ class ConnectionHandler: line = line.strip() if not line: continue - print repr(line) + print(repr(line)) field, value = line.split(':', 1) if line.startswith('Host:'): line = line.replace(str(PORT), '9991') @@ -173,10 +174,10 @@ class ConnectionHandler: buf = buf.replace('\n', '\r\n') self.target.send(buf) if rest: - print 'REST' - print repr(self.client_buffer) - print repr(buf) - print repr(rest) + print('REST') + print(repr(self.client_buffer)) + print(repr(buf)) + print(repr(rest)) self.target.send(rest) self.client_buffer = '' @@ -187,9 +188,9 @@ class ConnectionHandler: port = 9991 (soc_family, _, _, _, address) = socket.getaddrinfo(host, port)[0] self.target = socket.socket(soc_family) - print 'Connecting...', host, port + print('Connecting...', host, port) self.target.connect(address) - print 'Connected' + print('Connected') def _read_write(self): time_out_max = self.timeout/3 @@ -207,19 +208,19 @@ class ConnectionHandler: out = self.target else: if data: - print - print 'OUT' - print 'path =', self.path - print len(data) - print repr(data) - print + print() + print('OUT') + print('path =', self.path) + print(len(data)) + print(repr(data)) + print() out = self.client # super hacky and fragile data = data.replace('9991', str(PORT)) if data: if '400 Bad Request' in data: - print 'DONE!' + print('DONE!') import sys; sys.exit(1) out.send(data) count = 0 @@ -235,7 +236,7 @@ def start_server(host='localhost', port=PORT, IPv6=False, timeout=60, soc = socket.socket(soc_type) soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) soc.bind((host, port)) - print "Serving on %s:%d." % (host, port) #debug + print("Serving on %s:%d." % (host, port)) #debug soc.listen(0) while True: thread.start_new_thread(handler, soc.accept()+(timeout,)) diff --git a/tools/test-backend b/tools/test-backend index c169911205..ef04b2e70a 100755 --- a/tools/test-backend +++ b/tools/test-backend @@ -1,5 +1,6 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import optparse import os import sys diff --git a/tools/update-deployment b/tools/update-deployment index 3c2624b43f..a9f5450f2b 100755 --- a/tools/update-deployment +++ b/tools/update-deployment @@ -1,4 +1,5 @@ #!/usr/bin/env python2.7 +from __future__ import print_function import os import sys import subprocess @@ -14,7 +15,7 @@ logging.basicConfig(format="%(asctime)s update-deployment: %(message)s", level=logging.INFO) if len(sys.argv) != 2: - print FAIL + "Usage: update-deployment refname" + ENDC + print(FAIL + "Usage: update-deployment refname" + ENDC) sys.exit(1) refname = sys.argv[1] diff --git a/tools/zulip-export/zulip-export b/tools/zulip-export/zulip-export index e34c000bac..fc2267988c 100755 --- a/tools/zulip-export/zulip-export +++ b/tools/zulip-export/zulip-export @@ -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.path import optparse @@ -48,7 +49,7 @@ parser.add_option('--stream', default='') client = zulip.init_from_options(options) if options.stream == "": - print >>sys.stderr, "Usage:", parser.usage + print("Usage:", parser.usage, file=sys.stderr) sys.exit(1) client.add_subscriptions([{"name": options.stream}]) @@ -56,7 +57,7 @@ queue = client.register(event_types=['message']) client._register('get_old_messages', method='GET', url='messages') max_id = queue['max_message_id'] messages = [] -print "Fetching messages..." +print("Fetching messages...") result = client.get_old_messages({'anchor': 0, 'num_before': 0, 'num_after': max_id, @@ -64,8 +65,8 @@ result = client.get_old_messages({'anchor': 0, 'operand': options.stream}], 'apply_markdown': False}) if result['result'] != 'success': - print "Unfortunately, there was an error fetching some old messages." - print result + print("Unfortunately, there was an error fetching some old messages.") + print(result) sys.exit(1) for msg in result['messages']: if msg['type'] != 'stream': @@ -81,5 +82,5 @@ filename = "zulip-%s.json" % (options.stream,) f = codecs.open(filename, encoding='utf-8', mode="wb") f.write(json.dumps(messages, indent=0, sort_keys=False)) f.close() -print "%d messages exported to %s" % (len(messages), filename,) +print("%d messages exported to %s" % (len(messages), filename,)) sys.exit(0) diff --git a/zerver/lib/cache.py b/zerver/lib/cache.py index 3cf94b07e4..be307fef6b 100644 --- a/zerver/lib/cache.py +++ b/zerver/lib/cache.py @@ -1,4 +1,5 @@ from __future__ import absolute_import +from __future__ import print_function from functools import wraps