Apply Python 3 futurize transform libfuturize.fixes.fix_print_with_import

Refer #256
This commit is contained in:
Eklavya Sharma 2016-03-10 21:45:34 +05:30 committed by Tim Abbott
parent d998bc400a
commit 37365ba5a3
21 changed files with 53 additions and 32 deletions

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
from __future__ import print_function
import sys import sys
import time import time
import optparse 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 # 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 # non-alert case, so to give us something unambiguous to check in
# Nagios, print the exit status. # Nagios, print the exit status.
print status print(status)
sys.exit(status) sys.exit(status)
def send_zulip(message): def send_zulip(message):

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
from __future__ import print_function
import sys import sys
import time import time
import optparse import optparse
@ -15,7 +16,7 @@ states = {
} }
if 'USER' in os.environ and not os.environ['USER'] in ['root', 'rabbitmq']: 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]""" usage = """Usage: check-rabbitmq-consumers --queue=[queue-name] --min-threshold=[min-threshold]"""

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
from __future__ import print_function
import sys import sys
import re import re
import time import time
@ -30,7 +31,7 @@ max_count = 0
warn_queues = [] warn_queues = []
if 'USER' in os.environ and not os.environ['USER'] in ['root', 'rabbitmq']: 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"): for line in output.split("\n"):
line = line.strip() line = line.strip()

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
from __future__ import print_function
import sys import sys
import time import time
import datetime import datetime
@ -99,7 +100,7 @@ def send_reminders():
key = (uid, start) key = (uid, start)
if key not in sent: if key not in sent:
line = '%s starts at %s' % (title, start.strftime('%H:%M')) line = '%s starts at %s' % (title, start.strftime('%H:%M'))
print 'Sending reminder:', line print('Sending reminder:', line)
messages.append(line) messages.append(line)
keys.add(key) keys.add(key)

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
from __future__ import print_function
import subprocess import subprocess
import os import os
import sys import sys
@ -62,7 +63,7 @@ def process_logs():
file_data = last_data.get(log_file, {}) file_data = last_data.get(log_file, {})
if not os.path.exists(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 # 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 continue
length = int(subprocess.check_output(["wc", "-l", log_file]).split()[0]) length = int(subprocess.check_output(["wc", "-l", log_file]).split()[0])
if file_data.get("last") is None: if file_data.get("last") is None:
@ -82,7 +83,7 @@ def process_logs():
if __name__ == "__main__": if __name__ == "__main__":
if os.path.exists(lock_path): if os.path.exists(lock_path):
print "Log2zulip lock held; not doing anything" print("Log2zulip lock held; not doing anything")
sys.exit(0) sys.exit(0)
try: try:
@ -91,7 +92,7 @@ if __name__ == "__main__":
try: try:
log_files = ujson.loads(file(control_path, "r").read()) log_files = ujson.loads(file(control_path, "r").read())
except Exception: 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() traceback.print_exc()
sys.exit(1) sys.exit(1)
process_logs() process_logs()

View file

@ -21,6 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import sys import sys
from os import path from os import path
import optparse import optparse
@ -46,9 +47,9 @@ parser.add_option('--new-short-name')
client = zulip.init_from_options(options) client = zulip.init_from_options(options)
print client.create_user({ print(client.create_user({
'email': options.new_email, 'email': options.new_email,
'password': options.new_password, 'password': options.new_password,
'full_name': options.new_full_name, 'full_name': options.new_full_name,
'short_name': options.new_short_name 'short_name': options.new_short_name
}) }))

View file

@ -21,6 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import sys import sys
import os import os
import optparse import optparse
@ -53,4 +54,4 @@ if options.subject != "":
message_data["subject"] = options.subject message_data["subject"] = options.subject
if options.content != "": if options.content != "":
message_data["content"] = options.content message_data["content"] = options.content
print client.update_message(message_data) print(client.update_message(message_data))

View file

@ -21,6 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import sys import sys
import os import os
import optparse import optparse
@ -43,4 +44,4 @@ parser.add_option_group(zulip.generate_option_group(parser))
client = zulip.init_from_options(options) 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))

View file

@ -21,6 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import sys import sys
import os import os
import optparse import optparse
@ -42,4 +43,4 @@ parser.add_option_group(zulip.generate_option_group(parser))
client = zulip.init_from_options(options) client = zulip.init_from_options(options)
for user in client.get_members()["members"]: for user in client.get_members()["members"]:
print user["full_name"], user["email"] print(user["full_name"], user["email"])

View file

@ -21,6 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import sys import sys
import os import os
import optparse import optparse
@ -42,4 +43,4 @@ parser.add_option_group(zulip.generate_option_group(parser))
client = zulip.init_from_options(options) client = zulip.init_from_options(options)
print client.list_subscriptions() print(client.list_subscriptions())

View file

@ -21,6 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import sys import sys
import os import os
import optparse import optparse
@ -43,7 +44,7 @@ parser.add_option_group(zulip.generate_option_group(parser))
client = zulip.init_from_options(options) client = zulip.init_from_options(options)
def print_event(event): def print_event(event):
print event print(event)
# This is a blocking call, and will continuously poll for new events # 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 # Note also the filter here is messages to the stream Denmark; if you

View file

@ -21,6 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import sys import sys
import os import os
import optparse import optparse
@ -43,7 +44,7 @@ parser.add_option_group(zulip.generate_option_group(parser))
client = zulip.init_from_options(options) client = zulip.init_from_options(options)
def print_message(message): def print_message(message):
print message print(message)
# This is a blocking call, and will continuously poll for new messages # This is a blocking call, and will continuously poll for new messages
client.call_on_each_message(print_message) client.call_on_each_message(print_message)

View file

@ -21,6 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import sys import sys
import os import os
import optparse import optparse
@ -42,4 +43,4 @@ parser.add_option_group(zulip.generate_option_group(parser))
client = zulip.init_from_options(options) client = zulip.init_from_options(options)
print client.get_messages({}) print(client.get_messages({}))

View file

@ -21,6 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import sys import sys
import os import os
import optparse import optparse
@ -54,4 +55,4 @@ message_data = {
"subject": options.subject, "subject": options.subject,
"to": args, "to": args,
} }
print client.send_message(message_data) print(client.send_message(message_data))

View file

@ -21,6 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import sys import sys
import os import os
import optparse import optparse
@ -45,8 +46,8 @@ parser.add_option('--streams', default='')
client = zulip.init_from_options(options) client = zulip.init_from_options(options)
if options.streams == "": if options.streams == "":
print >>sys.stderr, "Usage:", parser.usage print("Usage:", parser.usage, file=sys.stderr)
sys.exit(1) sys.exit(1)
print client.add_subscriptions([{"name": stream_name} for stream_name in print(client.add_subscriptions([{"name": stream_name} for stream_name in
options.streams.split()]) options.streams.split()]))

View file

@ -21,6 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import sys import sys
import os import os
import optparse import optparse
@ -45,7 +46,7 @@ parser.add_option('--streams', default='')
client = zulip.init_from_options(options) client = zulip.init_from_options(options)
if options.streams == "": if options.streams == "":
print >>sys.stderr, "Usage:", parser.usage print("Usage:", parser.usage, file=sys.stderr)
sys.exit(1) sys.exit(1)
print client.remove_subscriptions(options.streams.split()) print(client.remove_subscriptions(options.streams.split()))

View file

@ -30,6 +30,7 @@
# #
# python-dateutil is a dependency for this script. # python-dateutil is a dependency for this script.
from __future__ import print_function
import base64 import base64
from datetime import datetime, timedelta from datetime import datetime, timedelta
@ -45,8 +46,8 @@ try:
import dateutil.parser import dateutil.parser
import dateutil.tz import dateutil.tz
except ImportError as e: except ImportError as e:
print >>sys.stderr, e print(e, file=sys.stderr)
print >>sys.stderr, "Please install the python-dateutil package." print("Please install the python-dateutil package.", file=sys.stderr)
exit(1) exit(1)
sys.path.insert(0, os.path.dirname(__file__)) sys.path.insert(0, os.path.dirname(__file__))

View file

@ -29,6 +29,7 @@
# #
# python-dateutil is a dependency for this script. # python-dateutil is a dependency for this script.
from __future__ import print_function
import requests import requests
import logging import logging
import time import time
@ -41,8 +42,8 @@ from datetime import datetime, timedelta
try: try:
import dateutil.parser import dateutil.parser
except ImportError as e: except ImportError as e:
print >>sys.stderr, e print(e, file=sys.stderr)
print >>sys.stderr, "Please install the python-dateutil package." print("Please install the python-dateutil package.", file=sys.stderr)
exit(1) exit(1)
sys.path.insert(0, os.path.dirname(__file__)) sys.path.insert(0, os.path.dirname(__file__))

View file

@ -23,6 +23,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import calendar import calendar
import errno import errno
import hashlib import hashlib
@ -97,7 +98,7 @@ try:
mkdir_p(opts.data_dir) mkdir_p(opts.data_dir)
except OSError: except OSError:
# We can't write to the logfile, so just print and give up. # 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) exit(1)
log_file = os.path.join(opts.data_dir, "rss-bot.log") log_file = os.path.join(opts.data_dir, "rss-bot.log")

View file

@ -23,6 +23,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import os import os
import sys import sys
import optparse import optparse
@ -112,7 +113,7 @@ api = twitter.Api(consumer_key=consumer_key,
user = api.VerifyCredentials() user = api.VerifyCredentials()
if not user.GetId(): 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() sys.exit()
try: try:
@ -154,7 +155,7 @@ for status in statuses[::-1][:options.limit_tweets]:
if ret['result'] == 'error': if ret['result'] == 'error':
# If sending failed (e.g. no such stream), abort and retry next time # 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 break
else: else:
since_id = status.GetId() since_id = status.GetId()

View file

@ -23,6 +23,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
from __future__ import print_function
import os import os
import sys import sys
import optparse import optparse
@ -138,8 +139,8 @@ api = twitter.Api(consumer_key=consumer_key,
user = api.VerifyCredentials() user = api.VerifyCredentials()
if not user.GetId(): if not user.GetId():
print "Unable to log in to Twitter with supplied credentials.\ print("Unable to log in to Twitter with supplied credentials.\
Please double-check and try again." Please double-check and try again.")
sys.exit() sys.exit()
client = zulip.Client( client = zulip.Client(
@ -182,7 +183,7 @@ for status in statuses[::-1][:opts.limit_tweets]:
if ret['result'] == 'error': if ret['result'] == 'error':
# If sending failed (e.g. no such stream), abort and retry next time # 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 break
else: else:
since_id = status.GetId() since_id = status.GetId()