Apply Python 3 futurize transform libfuturize.fixes.fix_print_with_import.

This commit is contained in:
Tim Abbott 2015-11-01 08:11:06 -08:00
parent f97649b35c
commit f3783fb4a1
69 changed files with 451 additions and 382 deletions

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
import datetime import datetime
import pytz import pytz
@ -19,6 +20,6 @@ class Command(BaseCommand):
date = datetime.datetime.now() - datetime.timedelta(days=1) date = datetime.datetime.now() - datetime.timedelta(days=1)
else: else:
date = datetime.datetime.strptime(options["date"], "%Y-%m-%d") date = datetime.datetime.strptime(options["date"], "%Y-%m-%d")
print "Activity data for", date print("Activity data for", date)
print activity_averages_during_day(date) print(activity_averages_during_day(date))
print "Please note that the total registered user count is a total for today" print("Please note that the total registered user count is a total for today")

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -63,7 +64,7 @@ def compute_stats(log_level):
logging.info("Top %6s | %s%%" % (size, round(top_percents[size], 1))) logging.info("Top %6s | %s%%" % (size, round(top_percents[size], 1)))
grand_total = sum(total_counts.values()) grand_total = sum(total_counts.values())
print grand_total print(grand_total)
logging.info("%15s | %s" % ("Client", "Percentage")) logging.info("%15s | %s" % ("Client", "Percentage"))
for client in total_counts.keys(): for client in total_counts.keys():
logging.info("%15s | %s%%" % (client, round(100. * total_counts[client] / grand_total, 1))) logging.info("%15s | %s%%" % (client, round(100. * total_counts[client] / grand_total, 1)))

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from zerver.lib.statistics import seconds_usage_between from zerver.lib.statistics import seconds_usage_between
@ -16,7 +17,7 @@ def analyze_activity(options):
if options["realm"]: if options["realm"]:
user_profile_query = user_profile_query.filter(realm__domain=options["realm"]) user_profile_query = user_profile_query.filter(realm__domain=options["realm"])
print "Per-user online duration:\n" print("Per-user online duration:\n")
total_duration = datetime.timedelta(0) total_duration = datetime.timedelta(0)
for user_profile in user_profile_query: for user_profile in user_profile_query:
duration = seconds_usage_between(user_profile, day_start, day_end) duration = seconds_usage_between(user_profile, day_start, day_end)
@ -25,11 +26,11 @@ def analyze_activity(options):
continue continue
total_duration += duration total_duration += duration
print "%-*s%s" % (37, user_profile.email, duration, ) print("%-*s%s" % (37, user_profile.email, duration, ))
print "\nTotal Duration: %s" % (total_duration,) print("\nTotal Duration: %s" % (total_duration,))
print "\nTotal Duration in minutes: %s" % (total_duration.total_seconds() / 60.,) print("\nTotal Duration in minutes: %s" % (total_duration.total_seconds() / 60.,))
print "Total Duration amortized to a month: %s" % (total_duration.total_seconds() * 30. / 60.,) print("Total Duration amortized to a month: %s" % (total_duration.total_seconds() * 30. / 60.,))
class Command(BaseCommand): class Command(BaseCommand):
help = """Report analytics of user activity on a per-user and realm basis. help = """Report analytics of user activity on a per-user and realm basis.

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.db.models import Count from django.db.models import Count
@ -48,8 +49,8 @@ python2.7 manage.py client_activity jesstess@zulip.com"""
counts.sort() counts.sort()
for count in counts: for count in counts:
print "%25s %15d" % (count[1], count[0]) print("%25s %15d" % (count[1], count[0]))
print "Total:", total print("Total:", total)
def handle(self, *args, **options): def handle(self, *args, **options):
@ -70,5 +71,5 @@ python2.7 manage.py client_activity jesstess@zulip.com"""
self.compute_activity(UserActivity.objects.filter( self.compute_activity(UserActivity.objects.filter(
user_profile__realm=realm)) user_profile__realm=realm))
except Realm.DoesNotExist: except Realm.DoesNotExist:
print "Unknown user or domain %s" % (arg,) print("Unknown user or domain %s" % (arg,))
exit(1) exit(1)

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
import datetime import datetime
import pytz import pytz
@ -65,45 +66,45 @@ class Command(BaseCommand):
fraction = 0.0 fraction = 0.0
else: else:
fraction = numerator / float(denominator) fraction = numerator / float(denominator)
print "%.2f%% of" % (fraction * 100,), text print("%.2f%% of" % (fraction * 100,), text)
def handle(self, *args, **options): def handle(self, *args, **options):
if options['realms']: if options['realms']:
try: try:
realms = [get_realm(domain) for domain in options['realms']] realms = [get_realm(domain) for domain in options['realms']]
except Realm.DoesNotExist as e: except Realm.DoesNotExist as e:
print e print(e)
exit(1) exit(1)
else: else:
realms = Realm.objects.all() realms = Realm.objects.all()
for realm in realms: for realm in realms:
print realm.domain print(realm.domain)
user_profiles = UserProfile.objects.filter(realm=realm, is_active=True) user_profiles = UserProfile.objects.filter(realm=realm, is_active=True)
active_users = self.active_users(realm) active_users = self.active_users(realm)
num_active = len(active_users) num_active = len(active_users)
print "%d active users (%d total)" % (num_active, len(user_profiles)) print("%d active users (%d total)" % (num_active, len(user_profiles)))
streams = Stream.objects.filter(realm=realm).extra( streams = Stream.objects.filter(realm=realm).extra(
tables=['zerver_subscription', 'zerver_recipient'], tables=['zerver_subscription', 'zerver_recipient'],
where=['zerver_subscription.recipient_id = zerver_recipient.id', where=['zerver_subscription.recipient_id = zerver_recipient.id',
'zerver_recipient.type = 2', 'zerver_recipient.type = 2',
'zerver_recipient.type_id = zerver_stream.id', 'zerver_recipient.type_id = zerver_stream.id',
'zerver_subscription.active = true']).annotate(count=Count("name")) 'zerver_subscription.active = true']).annotate(count=Count("name"))
print "%d streams" % (streams.count(),) print("%d streams" % (streams.count(),))
for days_ago in (1, 7, 30): for days_ago in (1, 7, 30):
print "In last %d days, users sent:" % (days_ago,) print("In last %d days, users sent:" % (days_ago,))
sender_quantities = [self.messages_sent_by(user, days_ago) for user in user_profiles] sender_quantities = [self.messages_sent_by(user, days_ago) for user in user_profiles]
for quantity in sorted(sender_quantities, reverse=True): for quantity in sorted(sender_quantities, reverse=True):
print quantity, print(quantity, end=' ')
print "" print("")
print "%d stream messages" % (self.stream_messages(realm, days_ago),) print("%d stream messages" % (self.stream_messages(realm, days_ago),))
print "%d one-on-one private messages" % (self.private_messages(realm, days_ago),) print("%d one-on-one private messages" % (self.private_messages(realm, days_ago),))
print "%d messages sent via the API" % (self.api_messages(realm, days_ago),) print("%d messages sent via the API" % (self.api_messages(realm, days_ago),))
print "%d group private messages" % (self.group_private_messages(realm, days_ago),) print("%d group private messages" % (self.group_private_messages(realm, days_ago),))
num_notifications_enabled = len(filter(lambda x: x.enable_desktop_notifications == True, num_notifications_enabled = len(filter(lambda x: x.enable_desktop_notifications == True,
active_users)) active_users))
@ -124,8 +125,8 @@ class Command(BaseCommand):
starrers = UserMessage.objects.filter(user_profile__in=user_profiles, starrers = UserMessage.objects.filter(user_profile__in=user_profiles,
flags=UserMessage.flags.starred).values( flags=UserMessage.flags.starred).values(
"user_profile").annotate(count=Count("user_profile")) "user_profile").annotate(count=Count("user_profile"))
print "%d users have starred %d messages" % ( print("%d users have starred %d messages" % (
len(starrers), sum([elt["count"] for elt in starrers])) len(starrers), sum([elt["count"] for elt in starrers])))
active_user_subs = Subscription.objects.filter( active_user_subs = Subscription.objects.filter(
user_profile__in=user_profiles, active=True) user_profile__in=user_profiles, active=True)
@ -133,20 +134,20 @@ class Command(BaseCommand):
# Streams not in home view # Streams not in home view
non_home_view = active_user_subs.filter(in_home_view=False).values( non_home_view = active_user_subs.filter(in_home_view=False).values(
"user_profile").annotate(count=Count("user_profile")) "user_profile").annotate(count=Count("user_profile"))
print "%d users have %d streams not in home view" % ( print("%d users have %d streams not in home view" % (
len(non_home_view), sum([elt["count"] for elt in non_home_view])) len(non_home_view), sum([elt["count"] for elt in non_home_view])))
# Code block markup # Code block markup
markup_messages = human_messages.filter( markup_messages = human_messages.filter(
sender__realm=realm, content__contains="~~~").values( sender__realm=realm, content__contains="~~~").values(
"sender").annotate(count=Count("sender")) "sender").annotate(count=Count("sender"))
print "%d users have used code block markup on %s messages" % ( print("%d users have used code block markup on %s messages" % (
len(markup_messages), sum([elt["count"] for elt in markup_messages])) len(markup_messages), sum([elt["count"] for elt in markup_messages])))
# Notifications for stream messages # Notifications for stream messages
notifications = active_user_subs.filter(notifications=True).values( notifications = active_user_subs.filter(notifications=True).values(
"user_profile").annotate(count=Count("user_profile")) "user_profile").annotate(count=Count("user_profile"))
print "%d users receive desktop notifications for %d streams" % ( print("%d users receive desktop notifications for %d streams" % (
len(notifications), sum([elt["count"] for elt in notifications])) len(notifications), sum([elt["count"] for elt in notifications])))
print "" print("")

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.db.models import Q from django.db.models import Q
@ -16,25 +17,25 @@ class Command(BaseCommand):
try: try:
realms = [get_realm(domain) for domain in options['realms']] realms = [get_realm(domain) for domain in options['realms']]
except Realm.DoesNotExist as e: except Realm.DoesNotExist as e:
print e print(e)
exit(1) exit(1)
else: else:
realms = Realm.objects.all() realms = Realm.objects.all()
for realm in realms: for realm in realms:
print realm.domain print(realm.domain)
print "------------" print("------------")
print "%25s %15s %10s" % ("stream", "subscribers", "messages") print("%25s %15s %10s" % ("stream", "subscribers", "messages"))
streams = Stream.objects.filter(realm=realm).exclude(Q(name__istartswith="tutorial-")) streams = Stream.objects.filter(realm=realm).exclude(Q(name__istartswith="tutorial-"))
invite_only_count = 0 invite_only_count = 0
for stream in streams: for stream in streams:
if stream.invite_only: if stream.invite_only:
invite_only_count += 1 invite_only_count += 1
continue continue
print "%25s" % (stream.name,), print("%25s" % (stream.name,), end=' ')
recipient = Recipient.objects.filter(type=Recipient.STREAM, type_id=stream.id) recipient = Recipient.objects.filter(type=Recipient.STREAM, type_id=stream.id)
print "%10d" % (len(Subscription.objects.filter(recipient=recipient, active=True)),), print("%10d" % (len(Subscription.objects.filter(recipient=recipient, active=True)),), end=' ')
num_messages = len(Message.objects.filter(recipient=recipient)) num_messages = len(Message.objects.filter(recipient=recipient))
print "%12d" % (num_messages,) print("%12d" % (num_messages,))
print "%d invite-only streams" % (invite_only_count,) print("%d invite-only streams" % (invite_only_count,))
print "" print("")

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
import datetime import datetime
import pytz import pytz
@ -23,19 +24,19 @@ class Command(BaseCommand):
try: try:
realms = [get_realm(domain) for domain in options['realms']] realms = [get_realm(domain) for domain in options['realms']]
except Realm.DoesNotExist as e: except Realm.DoesNotExist as e:
print e print(e)
exit(1) exit(1)
else: else:
realms = Realm.objects.all() realms = Realm.objects.all()
for realm in realms: for realm in realms:
print realm.domain print(realm.domain)
user_profiles = UserProfile.objects.filter(realm=realm, is_active=True) user_profiles = UserProfile.objects.filter(realm=realm, is_active=True)
print "%d users" % (len(user_profiles),) print("%d users" % (len(user_profiles),))
print "%d streams" % (len(Stream.objects.filter(realm=realm)),) print("%d streams" % (len(Stream.objects.filter(realm=realm)),))
for user_profile in user_profiles: for user_profile in user_profiles:
print "%35s" % (user_profile.email,), print("%35s" % (user_profile.email,), end=' ')
for week in range(10): for week in range(10):
print "%5d" % (self.messages_sent_by(user_profile, week)), print("%5d" % (self.messages_sent_by(user_profile, week)), end=' ')
print "" print("")

View File

@ -7,6 +7,7 @@
# 2007 Trolltech ASA # 2007 Trolltech ASA
# License: MIT <http://www.opensource.org/licenses/mit-license.php> # License: MIT <http://www.opensource.org/licenses/mit-license.php>
# #
from __future__ import print_function
import sys import sys
if sys.hexversion < 0x02040000: if sys.hexversion < 0x02040000:
# The limiter is the subprocess module # The limiter is the subprocess module
@ -693,7 +694,7 @@ def createOrUpdateBranchesFromOrigin(localRefPrefix = "refs/remotes/p4/", silent
update = False update = False
if not gitBranchExists(remoteHead): if not gitBranchExists(remoteHead):
if verbose: if verbose:
print "creating %s" % remoteHead print("creating %s" % remoteHead)
update = True update = True
else: else:
settings = extractSettingsGitLog(extractLogMessageFromGitCommit(remoteHead)) settings = extractSettingsGitLog(extractLogMessageFromGitCommit(remoteHead))
@ -895,9 +896,9 @@ class P4Debug(Command):
def run(self, args): def run(self, args):
j = 0 j = 0
for output in p4CmdList(args): for output in p4CmdList(args):
print 'Element: %d' % j print('Element: %d' % j)
j += 1 j += 1
print output print(output)
return True return True
class P4RollBack(Command): class P4RollBack(Command):
@ -938,14 +939,14 @@ class P4RollBack(Command):
if len(p4Cmd("changes -m 1 " + ' '.join (['%s...@%s' % (p, maxChange) if len(p4Cmd("changes -m 1 " + ' '.join (['%s...@%s' % (p, maxChange)
for p in depotPaths]))) == 0: for p in depotPaths]))) == 0:
print "Branch %s did not exist at change %s, deleting." % (ref, maxChange) print("Branch %s did not exist at change %s, deleting." % (ref, maxChange))
system("git update-ref -d %s `git rev-parse %s`" % (ref, ref)) system("git update-ref -d %s `git rev-parse %s`" % (ref, ref))
continue continue
while change and int(change) > maxChange: while change and int(change) > maxChange:
changed = True changed = True
if self.verbose: if self.verbose:
print "%s is at %s ; rewinding towards %s" % (ref, change, maxChange) print("%s is at %s ; rewinding towards %s" % (ref, change, maxChange))
system("git update-ref %s \"%s^\"" % (ref, ref)) system("git update-ref %s \"%s^\"" % (ref, ref))
log = extractLogMessageFromGitCommit(ref) log = extractLogMessageFromGitCommit(ref)
settings = extractSettingsGitLog(log) settings = extractSettingsGitLog(log)
@ -955,7 +956,7 @@ class P4RollBack(Command):
change = settings['change'] change = settings['change']
if changed: if changed:
print "%s rewound to %s" % (ref, change) print("%s rewound to %s" % (ref, change))
return True return True
@ -1069,10 +1070,10 @@ class P4Submit(Command, P4UserMap):
except: except:
# cleanup our temporary file # cleanup our temporary file
os.unlink(outFileName) os.unlink(outFileName)
print "Failed to strip RCS keywords in %s" % file print("Failed to strip RCS keywords in %s" % file)
raise raise
print "Patched up RCS keywords in %s" % file print("Patched up RCS keywords in %s" % file)
def p4UserForCommit(self, id): def p4UserForCommit(self, id):
# Return the tuple (perforce user,git email) for a given git commit id # Return the tuple (perforce user,git email) for a given git commit id
@ -1092,7 +1093,7 @@ class P4Submit(Command, P4UserMap):
if not user: if not user:
msg = "Cannot find p4 user for email %s in commit %s." % (email, id) msg = "Cannot find p4 user for email %s in commit %s." % (email, id)
if gitConfigBool("git-p4.allowMissingP4Users"): if gitConfigBool("git-p4.allowMissingP4Users"):
print "%s" % msg print("%s" % msg)
else: else:
die("Error: %s\nSet git-p4.allowMissingP4Users to true to allow this." % msg) die("Error: %s\nSet git-p4.allowMissingP4Users to true to allow this." % msg)
@ -1219,8 +1220,8 @@ class P4Submit(Command, P4UserMap):
def applyCommit(self, id): def applyCommit(self, id):
"""Apply one commit, return True if it succeeded.""" """Apply one commit, return True if it succeeded."""
print "Applying", read_pipe(["git", "show", "-s", print("Applying", read_pipe(["git", "show", "-s",
"--format=format:%h %s", id]) "--format=format:%h %s", id]))
(p4User, gitEmail) = self.p4UserForCommit(id) (p4User, gitEmail) = self.p4UserForCommit(id)
@ -1298,7 +1299,7 @@ class P4Submit(Command, P4UserMap):
if os.system(tryPatchCmd) != 0: if os.system(tryPatchCmd) != 0:
fixed_rcs_keywords = False fixed_rcs_keywords = False
patch_succeeded = False patch_succeeded = False
print "Unfortunately applying the change failed!" print("Unfortunately applying the change failed!")
# Patch failed, maybe it's just RCS keyword woes. Look through # Patch failed, maybe it's just RCS keyword woes. Look through
# the patch to see if that's possible. # the patch to see if that's possible.
@ -1316,13 +1317,13 @@ class P4Submit(Command, P4UserMap):
for line in read_pipe_lines(["git", "diff", "%s^..%s" % (id, id), file]): for line in read_pipe_lines(["git", "diff", "%s^..%s" % (id, id), file]):
if regexp.search(line): if regexp.search(line):
if verbose: if verbose:
print "got keyword match on %s in %s in %s" % (pattern, line, file) print("got keyword match on %s in %s in %s" % (pattern, line, file))
kwfiles[file] = pattern kwfiles[file] = pattern
break break
for file in kwfiles: for file in kwfiles:
if verbose: if verbose:
print "zapping %s with %s" % (line, pattern) print("zapping %s with %s" % (line, pattern))
# File is being deleted, so not open in p4. Must # File is being deleted, so not open in p4. Must
# disable the read-only bit on windows. # disable the read-only bit on windows.
if self.isWindows and file not in editedFiles: if self.isWindows and file not in editedFiles:
@ -1331,7 +1332,7 @@ class P4Submit(Command, P4UserMap):
fixed_rcs_keywords = True fixed_rcs_keywords = True
if fixed_rcs_keywords: if fixed_rcs_keywords:
print "Retrying the patch with RCS keywords cleaned up" print("Retrying the patch with RCS keywords cleaned up")
if os.system(tryPatchCmd) == 0: if os.system(tryPatchCmd) == 0:
patch_succeeded = True patch_succeeded = True
@ -1411,34 +1412,34 @@ class P4Submit(Command, P4UserMap):
# Leave the p4 tree prepared, and the submit template around # Leave the p4 tree prepared, and the submit template around
# and let the user decide what to do next # and let the user decide what to do next
# #
print print()
print "P4 workspace prepared for submission." print("P4 workspace prepared for submission.")
print "To submit or revert, go to client workspace" print("To submit or revert, go to client workspace")
print " " + self.clientPath print(" " + self.clientPath)
print print()
print "To submit, use \"p4 submit\" to write a new description," print("To submit, use \"p4 submit\" to write a new description,")
print "or \"p4 submit -i %s\" to use the one prepared by" \ print("or \"p4 submit -i %s\" to use the one prepared by" \
" \"git p4\"." % fileName " \"git p4\"." % fileName)
print "You can delete the file \"%s\" when finished." % fileName print("You can delete the file \"%s\" when finished." % fileName)
if self.preserveUser and p4User and not self.p4UserIsMe(p4User): if self.preserveUser and p4User and not self.p4UserIsMe(p4User):
print "To preserve change ownership by user %s, you must\n" \ print("To preserve change ownership by user %s, you must\n" \
"do \"p4 change -f <change>\" after submitting and\n" \ "do \"p4 change -f <change>\" after submitting and\n" \
"edit the User field." "edit the User field.")
if pureRenameCopy: if pureRenameCopy:
print "After submitting, renamed files must be re-synced." print("After submitting, renamed files must be re-synced.")
print "Invoke \"p4 sync -f\" on each of these files:" print("Invoke \"p4 sync -f\" on each of these files:")
for f in pureRenameCopy: for f in pureRenameCopy:
print " " + f print(" " + f)
print print()
print "To revert the changes, use \"p4 revert ...\", and delete" print("To revert the changes, use \"p4 revert ...\", and delete")
print "the submit template file \"%s\"" % fileName print("the submit template file \"%s\"" % fileName)
if filesToAdd: if filesToAdd:
print "Since the commit adds new files, they must be deleted:" print("Since the commit adds new files, they must be deleted:")
for f in filesToAdd: for f in filesToAdd:
print " " + f print(" " + f)
print print()
return True return True
# #
@ -1471,7 +1472,7 @@ class P4Submit(Command, P4UserMap):
else: else:
# skip this patch # skip this patch
ret = False ret = False
print "Submission cancelled, undoing p4 changes." print("Submission cancelled, undoing p4 changes.")
for f in editedFiles: for f in editedFiles:
p4_revert(f) p4_revert(f)
for f in filesToAdd: for f in filesToAdd:
@ -1495,7 +1496,7 @@ class P4Submit(Command, P4UserMap):
if not m.match(name): if not m.match(name):
if verbose: if verbose:
print "tag %s does not match regexp %s" % (name, validLabelRegexp) print("tag %s does not match regexp %s" % (name, validLabelRegexp))
continue continue
# Get the p4 commit this corresponds to # Get the p4 commit this corresponds to
@ -1505,7 +1506,7 @@ class P4Submit(Command, P4UserMap):
if 'change' not in values: if 'change' not in values:
# a tag pointing to something not sent to p4; ignore # a tag pointing to something not sent to p4; ignore
if verbose: if verbose:
print "git tag %s does not give a p4 commit" % name print("git tag %s does not give a p4 commit" % name)
continue continue
else: else:
changelist = values['change'] changelist = values['change']
@ -1540,10 +1541,10 @@ class P4Submit(Command, P4UserMap):
labelTemplate += "\t%s\n" % depot_side labelTemplate += "\t%s\n" % depot_side
if self.dry_run: if self.dry_run:
print "Would create p4 label %s for tag" % name print("Would create p4 label %s for tag" % name)
elif self.prepare_p4_only: elif self.prepare_p4_only:
print "Not creating p4 label %s for tag due to option" \ print("Not creating p4 label %s for tag due to option" \
" --prepare-p4-only" % name " --prepare-p4-only" % name)
else: else:
p4_write_pipe(["label", "-i"], labelTemplate) p4_write_pipe(["label", "-i"], labelTemplate)
@ -1552,7 +1553,7 @@ class P4Submit(Command, P4UserMap):
["%s@%s" % (depot_side, changelist) for depot_side in clientSpec.mappings]) ["%s@%s" % (depot_side, changelist) for depot_side in clientSpec.mappings])
if verbose: if verbose:
print "created p4 label for tag %s" % name print("created p4 label for tag %s" % name)
def run(self, args): def run(self, args):
if len(args) == 0: if len(args) == 0:
@ -1590,10 +1591,10 @@ class P4Submit(Command, P4UserMap):
self.conflict_behavior = val self.conflict_behavior = val
if self.verbose: if self.verbose:
print "Origin branch is " + self.origin print("Origin branch is " + self.origin)
if len(self.depotPath) == 0: if len(self.depotPath) == 0:
print "Internal error: cannot locate perforce depot path from existing branches" print("Internal error: cannot locate perforce depot path from existing branches")
sys.exit(128) sys.exit(128)
self.useClientSpec = False self.useClientSpec = False
@ -1611,7 +1612,7 @@ class P4Submit(Command, P4UserMap):
if self.clientPath == "": if self.clientPath == "":
die("Error: Cannot locate perforce checkout of %s in client view" % self.depotPath) die("Error: Cannot locate perforce checkout of %s in client view" % self.depotPath)
print "Perforce checkout for depot path %s located at %s" % (self.depotPath, self.clientPath) print("Perforce checkout for depot path %s located at %s" % (self.depotPath, self.clientPath))
self.oldWorkingDirectory = os.getcwd() self.oldWorkingDirectory = os.getcwd()
# ensure the clientPath exists # ensure the clientPath exists
@ -1622,9 +1623,9 @@ class P4Submit(Command, P4UserMap):
chdir(self.clientPath, is_client_path=True) chdir(self.clientPath, is_client_path=True)
if self.dry_run: if self.dry_run:
print "Would synchronize p4 checkout in %s" % self.clientPath print("Would synchronize p4 checkout in %s" % self.clientPath)
else: else:
print "Synchronizing p4 checkout..." print("Synchronizing p4 checkout...")
if new_client_dir: if new_client_dir:
# old one was destroyed, and maybe nobody told p4 # old one was destroyed, and maybe nobody told p4
p4_sync("...", "-f") p4_sync("...", "-f")
@ -1681,13 +1682,13 @@ class P4Submit(Command, P4UserMap):
# continue to try the rest of the patches, or quit. # continue to try the rest of the patches, or quit.
# #
if self.dry_run: if self.dry_run:
print "Would apply" print("Would apply")
applied = [] applied = []
last = len(commits) - 1 last = len(commits) - 1
for i, commit in enumerate(commits): for i, commit in enumerate(commits):
if self.dry_run: if self.dry_run:
print " ", read_pipe(["git", "show", "-s", print(" ", read_pipe(["git", "show", "-s",
"--format=format:%h %s", commit]) "--format=format:%h %s", commit]))
ok = True ok = True
else: else:
ok = self.applyCommit(commit) ok = self.applyCommit(commit)
@ -1695,15 +1696,15 @@ class P4Submit(Command, P4UserMap):
applied.append(commit) applied.append(commit)
else: else:
if self.prepare_p4_only and i < last: if self.prepare_p4_only and i < last:
print "Processing only the first commit due to option" \ print("Processing only the first commit due to option" \
" --prepare-p4-only" " --prepare-p4-only")
break break
if i < last: if i < last:
quit = False quit = False
while True: while True:
# prompt for what to do, or use the option/variable # prompt for what to do, or use the option/variable
if self.conflict_behavior == "ask": if self.conflict_behavior == "ask":
print "What do you want to do?" print("What do you want to do?")
response = raw_input("[s]kip this commit but apply" response = raw_input("[s]kip this commit but apply"
" the rest, or [q]uit? ") " the rest, or [q]uit? ")
if not response: if not response:
@ -1717,10 +1718,10 @@ class P4Submit(Command, P4UserMap):
self.conflict_behavior) self.conflict_behavior)
if response[0] == "s": if response[0] == "s":
print "Skipping this commit, but applying the rest" print("Skipping this commit, but applying the rest")
break break
if response[0] == "q": if response[0] == "q":
print "Quitting" print("Quitting")
quit = True quit = True
break break
if quit: if quit:
@ -1733,7 +1734,7 @@ class P4Submit(Command, P4UserMap):
elif self.prepare_p4_only: elif self.prepare_p4_only:
pass pass
elif len(commits) == len(applied): elif len(commits) == len(applied):
print "All commits applied!" print("All commits applied!")
sync = P4Sync() sync = P4Sync()
if self.branch: if self.branch:
@ -1745,17 +1746,17 @@ class P4Submit(Command, P4UserMap):
else: else:
if len(applied) == 0: if len(applied) == 0:
print "No commits applied." print("No commits applied.")
else: else:
print "Applied only the commits marked with '*':" print("Applied only the commits marked with '*':")
for c in commits: for c in commits:
if c in applied: if c in applied:
star = "*" star = "*"
else: else:
star = " " star = " "
print star, read_pipe(["git", "show", "-s", print(star, read_pipe(["git", "show", "-s",
"--format=format:%h %s", c]) "--format=format:%h %s", c]))
print "You will have to do 'git p4 sync' and rebase." print("You will have to do 'git p4 sync' and rebase.")
if gitConfigBool("git-p4.exportLabels"): if gitConfigBool("git-p4.exportLabels"):
self.exportLabels = True self.exportLabels = True
@ -1931,7 +1932,7 @@ class P4Sync(Command, P4UserMap):
self.gitStream.write("progress checkpoint\n\n") self.gitStream.write("progress checkpoint\n\n")
out = self.gitOutput.readline() out = self.gitOutput.readline()
if self.verbose: if self.verbose:
print "checkpoint finished: " + out print("checkpoint finished: " + out)
def extractFilesFromCommit(self, commit): def extractFilesFromCommit(self, commit):
self.cloneExclude = [re.sub(r"\.\.\.$", "", path) self.cloneExclude = [re.sub(r"\.\.\.$", "", path)
@ -2084,7 +2085,7 @@ class P4Sync(Command, P4UserMap):
# Ideally, someday, this script can learn how to generate # Ideally, someday, this script can learn how to generate
# appledouble files directly and import those to git, but # appledouble files directly and import those to git, but
# non-mac machines can never find a use for apple filetype. # non-mac machines can never find a use for apple filetype.
print "\nIgnoring apple filetype file %s" % file['depotFile'] print("\nIgnoring apple filetype file %s" % file['depotFile'])
return return
# Note that we do not try to de-mangle keywords on utf16 files, # Note that we do not try to de-mangle keywords on utf16 files,
@ -2208,7 +2209,7 @@ class P4Sync(Command, P4UserMap):
# Stream a p4 tag # Stream a p4 tag
def streamTag(self, gitStream, labelName, labelDetails, commit, epoch): def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
if verbose: if verbose:
print "writing tag %s for commit %s" % (labelName, commit) print("writing tag %s for commit %s" % (labelName, commit))
gitStream.write("tag %s\n" % labelName) gitStream.write("tag %s\n" % labelName)
gitStream.write("from %s\n" % commit) gitStream.write("from %s\n" % commit)
@ -2227,7 +2228,7 @@ class P4Sync(Command, P4UserMap):
gitStream.write("tagger %s\n" % tagger) gitStream.write("tagger %s\n" % tagger)
print "labelDetails=", labelDetails print("labelDetails=", labelDetails)
if 'Description' in labelDetails: if 'Description' in labelDetails:
description = labelDetails['Description'] description = labelDetails['Description']
else: else:
@ -2242,7 +2243,7 @@ class P4Sync(Command, P4UserMap):
author = details["user"] author = details["user"]
if self.verbose: if self.verbose:
print "commit into %s" % branch print("commit into %s" % branch)
# start with reading files; if that fails, we should not # start with reading files; if that fails, we should not
# create a commit. # create a commit.
@ -2276,7 +2277,7 @@ class P4Sync(Command, P4UserMap):
if len(parent) > 0: if len(parent) > 0:
if self.verbose: if self.verbose:
print "parent %s" % parent print("parent %s" % parent)
self.gitStream.write("from %s\n" % parent) self.gitStream.write("from %s\n" % parent)
self.streamP4Files(new_files) self.streamP4Files(new_files)
@ -2289,7 +2290,7 @@ class P4Sync(Command, P4UserMap):
labelDetails = label[0] labelDetails = label[0]
labelRevisions = label[1] labelRevisions = label[1]
if self.verbose: if self.verbose:
print "Change %s is labelled %s" % (change, labelDetails) print("Change %s is labelled %s" % (change, labelDetails))
files = p4CmdList(["files"] + ["%s...@%s" % (p, change) files = p4CmdList(["files"] + ["%s...@%s" % (p, change)
for p in self.branchPrefixes]) for p in self.branchPrefixes])
@ -2321,14 +2322,14 @@ class P4Sync(Command, P4UserMap):
l = p4CmdList(["labels"] + ["%s..." % p for p in self.depotPaths]) l = p4CmdList(["labels"] + ["%s..." % p for p in self.depotPaths])
if len(l) > 0 and not self.silent: if len(l) > 0 and not self.silent:
print "Finding files belonging to labels in %s" % repr(self.depotPaths) print("Finding files belonging to labels in %s" % repr(self.depotPaths))
for output in l: for output in l:
label = output["label"] label = output["label"]
revisions = {} revisions = {}
newestChange = 0 newestChange = 0
if self.verbose: if self.verbose:
print "Querying files for label %s" % label print("Querying files for label %s" % label)
for file in p4CmdList(["files"] + for file in p4CmdList(["files"] +
["%s...@%s" % (p, label) ["%s...@%s" % (p, label)
for p in self.depotPaths]): for p in self.depotPaths]):
@ -2340,7 +2341,7 @@ class P4Sync(Command, P4UserMap):
self.labels[newestChange] = [output, revisions] self.labels[newestChange] = [output, revisions]
if self.verbose: if self.verbose:
print "Label changes: %s" % self.labels.keys() print("Label changes: %s" % self.labels.keys())
# Import p4 labels as git tags. A direct mapping does not # Import p4 labels as git tags. A direct mapping does not
# exist, so assume that if all the files are at the same revision # exist, so assume that if all the files are at the same revision
@ -2348,7 +2349,7 @@ class P4Sync(Command, P4UserMap):
# just ignore. # just ignore.
def importP4Labels(self, stream, p4Labels): def importP4Labels(self, stream, p4Labels):
if verbose: if verbose:
print "import p4 labels: " + ' '.join(p4Labels) print("import p4 labels: " + ' '.join(p4Labels))
ignoredP4Labels = gitConfigList("git-p4.ignoredP4Labels") ignoredP4Labels = gitConfigList("git-p4.ignoredP4Labels")
validLabelRegexp = gitConfig("git-p4.labelImportRegexp") validLabelRegexp = gitConfig("git-p4.labelImportRegexp")
@ -2361,7 +2362,7 @@ class P4Sync(Command, P4UserMap):
if not m.match(name): if not m.match(name):
if verbose: if verbose:
print "label %s does not match regexp %s" % (name, validLabelRegexp) print("label %s does not match regexp %s" % (name, validLabelRegexp))
continue continue
if name in ignoredP4Labels: if name in ignoredP4Labels:
@ -2379,7 +2380,7 @@ class P4Sync(Command, P4UserMap):
gitCommit = read_pipe(["git", "rev-list", "--max-count=1", gitCommit = read_pipe(["git", "rev-list", "--max-count=1",
"--reverse", ":/\[git-p4:.*change = %d\]" % changelist]) "--reverse", ":/\[git-p4:.*change = %d\]" % changelist])
if len(gitCommit) == 0: if len(gitCommit) == 0:
print "could not find git commit for changelist %d" % changelist print("could not find git commit for changelist %d" % changelist)
else: else:
gitCommit = gitCommit.strip() gitCommit = gitCommit.strip()
commitFound = True commitFound = True
@ -2387,16 +2388,16 @@ class P4Sync(Command, P4UserMap):
try: try:
tmwhen = time.strptime(labelDetails['Update'], "%Y/%m/%d %H:%M:%S") tmwhen = time.strptime(labelDetails['Update'], "%Y/%m/%d %H:%M:%S")
except ValueError: except ValueError:
print "Could not convert label time %s" % labelDetails['Update'] print("Could not convert label time %s" % labelDetails['Update'])
tmwhen = 1 tmwhen = 1
when = int(time.mktime(tmwhen)) when = int(time.mktime(tmwhen))
self.streamTag(stream, name, labelDetails, gitCommit, when) self.streamTag(stream, name, labelDetails, gitCommit, when)
if verbose: if verbose:
print "p4 label %s mapped to git commit %s" % (name, gitCommit) print("p4 label %s mapped to git commit %s" % (name, gitCommit))
else: else:
if verbose: if verbose:
print "Label %s has no changelists - possibly deleted?" % name print("Label %s has no changelists - possibly deleted?" % name)
if not commitFound: if not commitFound:
# We can't import this label; don't try again as it will get very # We can't import this label; don't try again as it will get very
@ -2441,8 +2442,8 @@ class P4Sync(Command, P4UserMap):
if destination in self.knownBranches: if destination in self.knownBranches:
if not self.silent: if not self.silent:
print "p4 branch %s defines a mapping from %s to %s" % (info["branch"], source, destination) print("p4 branch %s defines a mapping from %s to %s" % (info["branch"], source, destination))
print "but there exists another mapping from %s to %s already!" % (self.knownBranches[destination], destination) print("but there exists another mapping from %s to %s already!" % (self.knownBranches[destination], destination))
continue continue
self.knownBranches[destination] = source self.knownBranches[destination] = source
@ -2506,28 +2507,28 @@ class P4Sync(Command, P4UserMap):
def gitCommitByP4Change(self, ref, change): def gitCommitByP4Change(self, ref, change):
if self.verbose: if self.verbose:
print "looking in ref " + ref + " for change %s using bisect..." % change print("looking in ref " + ref + " for change %s using bisect..." % change)
earliestCommit = "" earliestCommit = ""
latestCommit = parseRevision(ref) latestCommit = parseRevision(ref)
while True: while True:
if self.verbose: if self.verbose:
print "trying: earliest %s latest %s" % (earliestCommit, latestCommit) print("trying: earliest %s latest %s" % (earliestCommit, latestCommit))
next = read_pipe("git rev-list --bisect %s %s" % (latestCommit, earliestCommit)).strip() next = read_pipe("git rev-list --bisect %s %s" % (latestCommit, earliestCommit)).strip()
if len(next) == 0: if len(next) == 0:
if self.verbose: if self.verbose:
print "argh" print("argh")
return "" return ""
log = extractLogMessageFromGitCommit(next) log = extractLogMessageFromGitCommit(next)
settings = extractSettingsGitLog(log) settings = extractSettingsGitLog(log)
currentChange = int(settings['change']) currentChange = int(settings['change'])
if self.verbose: if self.verbose:
print "current change %s" % currentChange print("current change %s" % currentChange)
if currentChange == change: if currentChange == change:
if self.verbose: if self.verbose:
print "found %s" % next print("found %s" % next)
return next return next
if currentChange < change: if currentChange < change:
@ -2573,7 +2574,7 @@ class P4Sync(Command, P4UserMap):
if len(read_pipe(["git", "diff-tree", blob, target])) == 0: if len(read_pipe(["git", "diff-tree", blob, target])) == 0:
parentFound = True parentFound = True
if self.verbose: if self.verbose:
print "Found parent of %s in commit %s" % (branch, blob) print("Found parent of %s in commit %s" % (branch, blob))
break break
if parentFound: if parentFound:
return blob return blob
@ -2604,7 +2605,7 @@ class P4Sync(Command, P4UserMap):
filesForCommit = branches[branch] filesForCommit = branches[branch]
if self.verbose: if self.verbose:
print "branch is %s" % branch print("branch is %s" % branch)
self.updatedBranches.add(branch) self.updatedBranches.add(branch)
@ -2625,13 +2626,13 @@ class P4Sync(Command, P4UserMap):
print("\n Resuming with change %s" % change); print("\n Resuming with change %s" % change);
if self.verbose: if self.verbose:
print "parent determined through known branches: %s" % parent print("parent determined through known branches: %s" % parent)
branch = self.gitRefForBranch(branch) branch = self.gitRefForBranch(branch)
parent = self.gitRefForBranch(parent) parent = self.gitRefForBranch(parent)
if self.verbose: if self.verbose:
print "looking for initial parent for %s; current parent is %s" % (branch, parent) print("looking for initial parent for %s; current parent is %s" % (branch, parent))
if len(parent) == 0 and branch in self.initialParents: if len(parent) == 0 and branch in self.initialParents:
parent = self.initialParents[branch] parent = self.initialParents[branch]
@ -2641,7 +2642,7 @@ class P4Sync(Command, P4UserMap):
if len(parent) > 0: if len(parent) > 0:
tempBranch = "%s/%d" % (self.tempBranchLocation, change) tempBranch = "%s/%d" % (self.tempBranchLocation, change)
if self.verbose: if self.verbose:
print "Creating temporary branch: " + tempBranch print("Creating temporary branch: " + tempBranch)
self.commit(description, filesForCommit, tempBranch) self.commit(description, filesForCommit, tempBranch)
self.tempBranches.append(tempBranch) self.tempBranches.append(tempBranch)
self.checkpoint() self.checkpoint()
@ -2650,7 +2651,7 @@ class P4Sync(Command, P4UserMap):
self.commit(description, filesForCommit, branch, blob) self.commit(description, filesForCommit, branch, blob)
else: else:
if self.verbose: if self.verbose:
print "Parent of %s not found. Committing into head of %s" % (branch, parent) print("Parent of %s not found. Committing into head of %s" % (branch, parent))
self.commit(description, filesForCommit, branch, parent) self.commit(description, filesForCommit, branch, parent)
else: else:
files = self.extractFilesFromCommit(description) files = self.extractFilesFromCommit(description)
@ -2659,11 +2660,11 @@ class P4Sync(Command, P4UserMap):
# only needed once, to connect to the previous commit # only needed once, to connect to the previous commit
self.initialParent = "" self.initialParent = ""
except IOError: except IOError:
print self.gitError.read() print(self.gitError.read())
sys.exit(1) sys.exit(1)
def importHeadRevision(self, revision): def importHeadRevision(self, revision):
print "Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch) print("Doing initial import of %s from revision %s into %s" % (' '.join(self.depotPaths), revision, self.branch))
details = {} details = {}
details["user"] = "git perforce import user" details["user"] = "git perforce import user"
@ -2715,8 +2716,8 @@ class P4Sync(Command, P4UserMap):
try: try:
self.commit(details, self.extractFilesFromCommit(details), self.branch) self.commit(details, self.extractFilesFromCommit(details), self.branch)
except IOError: except IOError:
print "IO error with git fast-import. Is your git version recent enough?" print("IO error with git fast-import. Is your git version recent enough?")
print self.gitError.read() print(self.gitError.read())
def run(self, args): def run(self, args):
@ -2738,7 +2739,7 @@ class P4Sync(Command, P4UserMap):
self.hasOrigin = originP4BranchesExist() self.hasOrigin = originP4BranchesExist()
if self.hasOrigin: if self.hasOrigin:
if not self.silent: if not self.silent:
print 'Syncing with origin first, using "git fetch origin"' print('Syncing with origin first, using "git fetch origin"')
system("git fetch origin") system("git fetch origin")
branch_arg_given = bool(self.branch) branch_arg_given = bool(self.branch)
@ -2777,14 +2778,14 @@ class P4Sync(Command, P4UserMap):
if len(self.p4BranchesInGit) > 1: if len(self.p4BranchesInGit) > 1:
if not self.silent: if not self.silent:
print "Importing from/into multiple branches" print("Importing from/into multiple branches")
self.detectBranches = True self.detectBranches = True
for branch in branches.keys(): for branch in branches.keys():
self.initialParents[self.refPrefix + branch] = \ self.initialParents[self.refPrefix + branch] = \
branches[branch] branches[branch]
if self.verbose: if self.verbose:
print "branches: %s" % self.p4BranchesInGit print("branches: %s" % self.p4BranchesInGit)
p4Change = 0 p4Change = 0
for branch in self.p4BranchesInGit: for branch in self.p4BranchesInGit:
@ -2819,7 +2820,7 @@ class P4Sync(Command, P4UserMap):
self.depotPaths = sorted(self.previousDepotPaths) self.depotPaths = sorted(self.previousDepotPaths)
self.changeRange = "@%s,#head" % p4Change self.changeRange = "@%s,#head" % p4Change
if not self.silent and not self.detectBranches: if not self.silent and not self.detectBranches:
print "Performing incremental import into %s git branch" % self.branch print("Performing incremental import into %s git branch" % self.branch)
# accept multiple ref name abbreviations: # accept multiple ref name abbreviations:
# refs/foo/bar/branch -> use it exactly # refs/foo/bar/branch -> use it exactly
@ -2836,7 +2837,7 @@ class P4Sync(Command, P4UserMap):
if len(args) == 0 and self.depotPaths: if len(args) == 0 and self.depotPaths:
if not self.silent: if not self.silent:
print "Depot paths: %s" % ' '.join(self.depotPaths) print("Depot paths: %s" % ' '.join(self.depotPaths))
else: else:
if self.depotPaths and self.depotPaths != args: if self.depotPaths and self.depotPaths != args:
print ("previous import used depot path %s and now %s was specified. " print ("previous import used depot path %s and now %s was specified. "
@ -2906,8 +2907,8 @@ class P4Sync(Command, P4UserMap):
else: else:
self.getBranchMapping() self.getBranchMapping()
if self.verbose: if self.verbose:
print "p4-git branches: %s" % self.p4BranchesInGit print("p4-git branches: %s" % self.p4BranchesInGit)
print "initial parents: %s" % self.initialParents print("initial parents: %s" % self.initialParents)
for b in self.p4BranchesInGit: for b in self.p4BranchesInGit:
if b != "master": if b != "master":
@ -2959,8 +2960,8 @@ class P4Sync(Command, P4UserMap):
self.branch) self.branch)
if self.verbose: if self.verbose:
print "Getting p4 changes for %s...%s" % (', '.join(self.depotPaths), print("Getting p4 changes for %s...%s" % (', '.join(self.depotPaths),
self.changeRange) self.changeRange))
changes = p4ChangesForPaths(self.depotPaths, self.changeRange) changes = p4ChangesForPaths(self.depotPaths, self.changeRange)
if len(self.maxChanges) > 0: if len(self.maxChanges) > 0:
@ -2968,10 +2969,10 @@ class P4Sync(Command, P4UserMap):
if len(changes) == 0: if len(changes) == 0:
if not self.silent: if not self.silent:
print "No changes to import!" print("No changes to import!")
else: else:
if not self.silent and not self.detectBranches: if not self.silent and not self.detectBranches:
print "Import destination: %s" % self.branch print("Import destination: %s" % self.branch)
self.updatedBranches = set() self.updatedBranches = set()
@ -2986,7 +2987,7 @@ class P4Sync(Command, P4UserMap):
self.importChanges(changes) self.importChanges(changes)
if not self.silent: if not self.silent:
print "" print("")
if len(self.updatedBranches) > 0: if len(self.updatedBranches) > 0:
sys.stdout.write("Updated branches: ") sys.stdout.write("Updated branches: ")
for b in self.updatedBranches: for b in self.updatedBranches:
@ -3054,7 +3055,7 @@ class P4Rebase(Command):
# the branchpoint may be p4/foo~3, so strip off the parent # the branchpoint may be p4/foo~3, so strip off the parent
upstream = re.sub("~[0-9]+$", "", upstream) upstream = re.sub("~[0-9]+$", "", upstream)
print "Rebasing the current branch onto %s" % upstream print("Rebasing the current branch onto %s" % upstream)
oldHead = read_pipe("git rev-parse HEAD").strip() oldHead = read_pipe("git rev-parse HEAD").strip()
system("git rebase %s" % upstream) system("git rebase %s" % upstream)
system("git diff-tree --stat --summary -M %s HEAD" % oldHead) system("git diff-tree --stat --summary -M %s HEAD" % oldHead)
@ -3117,7 +3118,7 @@ class P4Clone(P4Sync):
if not self.cloneDestination: if not self.cloneDestination:
self.cloneDestination = self.defaultDestination(args) self.cloneDestination = self.defaultDestination(args)
print "Importing from %s into %s" % (', '.join(depotPaths), self.cloneDestination) print("Importing from %s into %s" % (', '.join(depotPaths), self.cloneDestination))
if not os.path.exists(self.cloneDestination): if not os.path.exists(self.cloneDestination):
os.makedirs(self.cloneDestination) os.makedirs(self.cloneDestination)
@ -3139,8 +3140,8 @@ class P4Clone(P4Sync):
if not self.cloneBare: if not self.cloneBare:
system([ "git", "checkout", "-f" ]) system([ "git", "checkout", "-f" ])
else: else:
print 'Not checking out any branch, use ' \ print('Not checking out any branch, use ' \
'"git checkout -q -b master <branch>"' '"git checkout -q -b master <branch>"')
# auto-set this variable if invoked with --use-client-spec # auto-set this variable if invoked with --use-client-spec
if self.useClientSpec_from_options: if self.useClientSpec_from_options:
@ -3173,7 +3174,7 @@ class P4Branches(Command):
log = extractLogMessageFromGitCommit("refs/remotes/%s" % branch) log = extractLogMessageFromGitCommit("refs/remotes/%s" % branch)
settings = extractSettingsGitLog(log) settings = extractSettingsGitLog(log)
print "%s <= %s (%s)" % (branch, ",".join(settings["depot-paths"]), settings["change"]) print("%s <= %s (%s)" % (branch, ",".join(settings["depot-paths"]), settings["change"]))
return True return True
class HelpFormatter(optparse.IndentedHelpFormatter): class HelpFormatter(optparse.IndentedHelpFormatter):
@ -3187,12 +3188,12 @@ class HelpFormatter(optparse.IndentedHelpFormatter):
return "" return ""
def printUsage(commands): def printUsage(commands):
print "usage: %s <command> [options]" % sys.argv[0] print("usage: %s <command> [options]" % sys.argv[0])
print "" print("")
print "valid commands: %s" % ", ".join(commands) print("valid commands: %s" % ", ".join(commands))
print "" print("")
print "Try %s <command> --help for command specific help." % sys.argv[0] print("Try %s <command> --help for command specific help." % sys.argv[0])
print "" print("")
commands = { commands = {
"debug" : P4Debug, "debug" : P4Debug,
@ -3216,8 +3217,8 @@ def main():
klass = commands[cmdName] klass = commands[cmdName]
cmd = klass() cmd = klass()
except KeyError: except KeyError:
print "unknown command %s" % cmdName print("unknown command %s" % cmdName)
print "" print("")
printUsage(commands.keys()) printUsage(commands.keys())
sys.exit(2) sys.exit(2)

View File

@ -33,6 +33,7 @@ For example:
1234 //depot/security/src/ 1234 //depot/security/src/
''' '''
from __future__ import print_function
import os import os
import sys import sys
@ -59,12 +60,12 @@ try:
changelist = int(sys.argv[1]) changelist = int(sys.argv[1])
changeroot = sys.argv[2] changeroot = sys.argv[2]
except IndexError: except IndexError:
print >> sys.stderr, "Wrong number of arguments.\n\n", print("Wrong number of arguments.\n\n", end=' ', file=sys.stderr)
print >> sys.stderr, __doc__ print(__doc__, file=sys.stderr)
sys.exit(-1) sys.exit(-1)
except ValueError: except ValueError:
print >> sys.stderr, "First argument must be an integer.\n\n", print("First argument must be an integer.\n\n", end=' ', file=sys.stderr)
print >> sys.stderr, __doc__ print(__doc__, file=sys.stderr)
sys.exit(-1) sys.exit(-1)
metadata = git_p4.p4_describe(changelist) metadata = git_p4.p4_describe(changelist)

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import print_function
import os import os
import sys import sys
@ -60,13 +61,13 @@ except ImportError:
try: try:
import simplejson import simplejson
except ImportError: except ImportError:
print >>sys.stderr, "simplejson is not installed" print("simplejson is not installed", file=sys.stderr)
sys.exit(1) sys.exit(1)
try: try:
import requests import requests
assert(LooseVersion(requests.__version__) >= LooseVersion('0.12.1')) assert(LooseVersion(requests.__version__) >= LooseVersion('0.12.1'))
except (ImportError, AssertionError): except (ImportError, AssertionError):
print >>sys.stderr, "requests >=0.12.1 is not installed" print("requests >=0.12.1 is not installed", file=sys.stderr)
sys.exit(1) sys.exit(1)

View File

@ -20,6 +20,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 simplejson import simplejson
import requests import requests
import time import time
@ -87,7 +88,7 @@ class RandomExponentialBackoff(CountingBackoff):
try: try:
logger.warning(message) logger.warning(message)
except NameError: except NameError:
print message print(message)
time.sleep(delay) time.sleep(delay)
def _default_client(): def _default_client():
@ -273,9 +274,9 @@ class Client(object):
def end_error_retry(succeeded): def end_error_retry(succeeded):
if query_state["had_error_retry"] and self.verbose: if query_state["had_error_retry"] and self.verbose:
if succeeded: if succeeded:
print "Success!" print("Success!")
else: else:
print "Failed!" print("Failed!")
while True: while True:
try: try:
@ -364,7 +365,7 @@ class Client(object):
if 'error' in res.get('result'): if 'error' in res.get('result'):
if self.verbose: if self.verbose:
print "Server returned error:\n%s" % res['msg'] print("Server returned error:\n%s" % res['msg'])
time.sleep(1) time.sleep(1)
else: else:
return (res['queue_id'], res['last_event_id']) return (res['queue_id'], res['last_event_id'])
@ -378,13 +379,13 @@ class Client(object):
if 'error' in res.get('result'): if 'error' in res.get('result'):
if res["result"] == "http-error": if res["result"] == "http-error":
if self.verbose: if self.verbose:
print "HTTP error fetching events -- probably a server restart" print("HTTP error fetching events -- probably a server restart")
elif res["result"] == "connection-error": elif res["result"] == "connection-error":
if self.verbose: if self.verbose:
print "Connection error fetching events -- probably server is temporarily down?" print("Connection error fetching events -- probably server is temporarily down?")
else: else:
if self.verbose: if self.verbose:
print "Server returned error:\n%s" % res["msg"] print("Server returned error:\n%s" % res["msg"])
if res["msg"].startswith("Bad event queue id:"): if res["msg"].startswith("Bad event queue id:"):
# Our event queue went away, probably because # Our event queue went away, probably because
# we were asleep or the server restarted # we were asleep or the server restarted

View File

@ -6,6 +6,7 @@
# Setup: First, you need to install python-irc version 8.5.3 # Setup: First, you need to install python-irc version 8.5.3
# (https://bitbucket.org/jaraco/irc) # (https://bitbucket.org/jaraco/irc)
from __future__ import print_function
import irc.bot import irc.bot
import irc.strings import irc.strings
from irc.client import ip_numstr_to_quad, ip_quad_to_numstr from irc.client import ip_numstr_to_quad, ip_quad_to_numstr
@ -53,12 +54,12 @@ class IRCBot(irc.bot.SingleServerIRCBot):
return return
# Forward the PM to Zulip # Forward the PM to Zulip
print zulip_client.send_message({ print(zulip_client.send_message({
"sender": sender, "sender": sender,
"type": "private", "type": "private",
"to": "username@example.com", "to": "username@example.com",
"content": content, "content": content,
}) }))
def on_pubmsg(self, c, e): def on_pubmsg(self, c, e):
content = e.arguments[0] content = e.arguments[0]
@ -68,14 +69,14 @@ class IRCBot(irc.bot.SingleServerIRCBot):
return return
# Forward the stream message to Zulip # Forward the stream message to Zulip
print zulip_client.send_message({ print(zulip_client.send_message({
"forged": "yes", "forged": "yes",
"sender": sender, "sender": sender,
"type": "stream", "type": "stream",
"to": stream, "to": stream,
"subject": "IRC", "subject": "IRC",
"content": content, "content": content,
}) }))
def on_dccmsg(self, c, e): def on_dccmsg(self, c, e):
c.privmsg("You said: " + e.arguments[0]) c.privmsg("You said: " + e.arguments[0])

View File

@ -21,6 +21,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE. # SOFTWARE.
from __future__ import print_function
import sys import sys
import subprocess import subprocess
import os import os
@ -39,7 +40,7 @@ args.extend(sys.argv[1:])
backoff = RandomExponentialBackoff(timeout_success_equivalent=300) backoff = RandomExponentialBackoff(timeout_success_equivalent=300)
while backoff.keep_going(): while backoff.keep_going():
print "Starting Jabber mirroring bot" print("Starting Jabber mirroring bot")
try: try:
ret = subprocess.call(args) ret = subprocess.call(args)
except: except:
@ -51,9 +52,9 @@ while backoff.keep_going():
backoff.fail() backoff.fail()
print "" print("")
print "" print("")
print "ERROR: The Jabber mirroring bot is unable to continue mirroring Jabber." print("ERROR: The Jabber mirroring bot is unable to continue mirroring Jabber.")
print "Please contact zulip-devel@googlegroups.com if you need assistance." print("Please contact zulip-devel@googlegroups.com if you need assistance.")
print "" print("")
sys.exit(1) sys.exit(1)

View File

@ -1,3 +1,4 @@
from __future__ import print_function
# This is hacky code to analyze data on our support stream. The main # This is hacky code to analyze data on our support stream. The main
# reusable bits are get_recent_messages and get_words. # reusable bits are get_recent_messages and get_words.
@ -31,7 +32,7 @@ def analyze_messages(msgs, word_count, email_count):
if False: if False:
if ' ack' in msg['content']: if ' ack' in msg['content']:
name = msg['sender_full_name'].split()[0] name = msg['sender_full_name'].split()[0]
print 'ACK', name print('ACK', name)
m = re.search('ticket (Z....).*email: (\S+).*~~~(.*)', msg['content'], re.M | re.S) m = re.search('ticket (Z....).*email: (\S+).*~~~(.*)', msg['content'], re.M | re.S)
if m: if m:
ticket, email, req = m.groups() ticket, email, req = m.groups()
@ -40,9 +41,9 @@ def analyze_messages(msgs, word_count, email_count):
word_count[word] += 1 word_count[word] += 1
email_count[email] += 1 email_count[email] += 1
if False: if False:
print print()
for k, v in msg.items(): for k, v in msg.items():
print '%-20s: %s' % (k, v) print('%-20s: %s' % (k, v))
def generate_support_stats(): def generate_support_stats():
client = zulip.Client() client = zulip.Client()
@ -68,12 +69,12 @@ def generate_support_stats():
words = filter(lambda w: len(w) >= 5, words) words = filter(lambda w: len(w) >= 5, words)
words = sorted(words, key=lambda w: word_count[w], reverse=True) words = sorted(words, key=lambda w: word_count[w], reverse=True)
for word in words: for word in words:
print word, word_count[word] print(word, word_count[word])
if False: if False:
emails = email_count.keys() emails = email_count.keys()
emails = sorted(emails, key=lambda w: email_count[w], reverse=True) emails = sorted(emails, key=lambda w: email_count[w], reverse=True)
for email in emails: for email in emails:
print email, email_count[email] print(email, email_count[email])
generate_support_stats() generate_support_stats()

View File

@ -22,6 +22,7 @@
# SOFTWARE. # SOFTWARE.
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
import sys import sys
import subprocess import subprocess
import os import os
@ -53,30 +54,30 @@ if options.forward_class_messages and not options.noshard:
if options.on_startup_command is not None: if options.on_startup_command is not None:
subprocess.call([options.on_startup_command]) subprocess.call([options.on_startup_command])
from zerver.lib.parallel import run_parallel from zerver.lib.parallel import run_parallel
print "Starting parallel zephyr class mirroring bot" print("Starting parallel zephyr class mirroring bot")
jobs = list("0123456789abcdef") jobs = list("0123456789abcdef")
def run_job(shard): def run_job(shard):
subprocess.call(args + ["--shard=%s" % (shard,)]) subprocess.call(args + ["--shard=%s" % (shard,)])
return 0 return 0
for (status, job) in run_parallel(run_job, jobs, threads=16): for (status, job) in run_parallel(run_job, jobs, threads=16):
print "A mirroring shard died!" print("A mirroring shard died!")
pass pass
sys.exit(0) sys.exit(0)
backoff = RandomExponentialBackoff(timeout_success_equivalent=300) backoff = RandomExponentialBackoff(timeout_success_equivalent=300)
while backoff.keep_going(): while backoff.keep_going():
print "Starting zephyr mirroring bot" print("Starting zephyr mirroring bot")
try: try:
subprocess.call(args) subprocess.call(args)
except: except:
traceback.print_exc() traceback.print_exc()
backoff.fail() backoff.fail()
print "" print("")
print "" print("")
print "ERROR: The Zephyr mirroring bot is unable to continue mirroring Zephyrs." print("ERROR: The Zephyr mirroring bot is unable to continue mirroring Zephyrs.")
print "This is often caused by failing to maintain unexpired Kerberos tickets" print("This is often caused by failing to maintain unexpired Kerberos tickets")
print "or AFS tokens. See https://zulip.com/zephyr for documentation on how to" print("or AFS tokens. See https://zulip.com/zephyr for documentation on how to")
print "maintain unexpired Kerberos tickets and AFS tokens." print("maintain unexpired Kerberos tickets and AFS tokens.")
print "" print("")
sys.exit(1) sys.exit(1)

View File

@ -1,3 +1,4 @@
from __future__ import print_function
import os import os
import sys import sys
import logging import logging
@ -53,9 +54,9 @@ VENV_PATH="/srv/zulip-venv"
ZULIP_PATH="/srv/zulip" ZULIP_PATH="/srv/zulip"
if not os.path.exists(os.path.join(os.path.dirname(__file__), ".git")): if not os.path.exists(os.path.join(os.path.dirname(__file__), ".git")):
print "Error: No Zulip git repository present at /srv/zulip!" print("Error: No Zulip git repository present at /srv/zulip!")
print "To setup the Zulip development environment, you should clone the code" print("To setup the Zulip development environment, you should clone the code")
print "from GitHub, rather than using a Zulip production release tarball." print("from GitHub, rather than using a Zulip production release tarball.")
sys.exit(1) sys.exit(1)
# TODO: Parse arguments properly # TODO: Parse arguments properly

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
from __future__ import print_function
import subprocess import subprocess
import sys import sys
import logging import logging
@ -12,7 +13,7 @@ logger = logging.getLogger(__name__)
def run(args, dry_run=False): def run(args, dry_run=False):
if dry_run: if dry_run:
print "Would have run: " + " ".join(args) print("Would have run: " + " ".join(args))
return "" return ""
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
# This tools generates local_settings_generated.py using the template # This tools generates local_settings_generated.py using the template
from __future__ import print_function
import sys, os, os.path import sys, os, os.path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
@ -23,7 +24,7 @@ CAMO_KEY=%s
""" % (camo_key,) """ % (camo_key,)
with open(CAMO_CONFIG_FILENAME, 'w') as camo_file: with open(CAMO_CONFIG_FILENAME, 'w') as camo_file:
camo_file.write(camo_config) camo_file.write(camo_config)
print "Generated Camo config file %s" % (CAMO_CONFIG_FILENAME,) print("Generated Camo config file %s" % (CAMO_CONFIG_FILENAME,))
def generate_django_secretkey(): def generate_django_secretkey():
# Secret key generation taken from Django's startproject.py # Secret key generation taken from Django's startproject.py
@ -55,7 +56,7 @@ def generate_secrets(development=False):
out.write("".join(lines)) out.write("".join(lines))
out.close() out.close()
print "Generated %s with auto-generated secrets!" % (OUTPUT_SETTINGS_FILENAME,) print("Generated %s with auto-generated secrets!" % (OUTPUT_SETTINGS_FILENAME,))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
from __future__ import print_function
import datetime import datetime
import monthdelta import monthdelta
@ -26,7 +27,7 @@ class Company(object):
delta = flow.cashflow(start_date, end_date, (end_date - start_date).days) delta = flow.cashflow(start_date, end_date, (end_date - start_date).days)
cash += delta cash += delta
if self.verbose: if self.verbose:
print flow.name, round(delta, 2) print(flow.name, round(delta, 2))
return round(cash, 2) return round(cash, 2)
def cash_at_date(self, start, end): def cash_at_date(self, start, end):
@ -39,10 +40,10 @@ class Company(object):
cur_date = parse_date(start) cur_date = parse_date(start)
end_date = parse_date(end) end_date = parse_date(end)
while cur_date <= end_date: while cur_date <= end_date:
print cur_date, self.cash_at_date_internal(start_date, cur_date) print(cur_date, self.cash_at_date_internal(start_date, cur_date))
cur_date += monthdelta.MonthDelta(1) cur_date += monthdelta.MonthDelta(1)
if self.verbose: if self.verbose:
print print()
# CashFlow objects fundamentally just provide a function that says how # CashFlow objects fundamentally just provide a function that says how
# much cash has been spent by that source at each time # much cash has been spent by that source at each time
@ -208,5 +209,5 @@ if __name__ == "__main__":
assert(c.cash_at_date("2012-01-01", "2012-02-15") == 499207.33) assert(c.cash_at_date("2012-01-01", "2012-02-15") == 499207.33)
c.add_flow(SemiMonthlyWages("Payroll", -4000, "2012-01-01")) c.add_flow(SemiMonthlyWages("Payroll", -4000, "2012-01-01"))
print c print(c)
c.cash_monthly_summary("2012-01-01", "2012-07-01") c.cash_monthly_summary("2012-01-01", "2012-07-01")

View File

@ -2,6 +2,7 @@
# #
# Generates % delta activity metrics from graphite/statsd data # Generates % delta activity metrics from graphite/statsd data
# #
from __future__ import print_function
import os, sys import os, sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
@ -43,7 +44,7 @@ def get_data(url, username, pw):
res = requests.get(url, auth=HTTPDigestAuth(username, pw), verify=False) res = requests.get(url, auth=HTTPDigestAuth(username, pw), verify=False)
if res.status_code != 200: if res.status_code != 200:
print "Failed to fetch data url: %s" % (res.error,) print("Failed to fetch data url: %s" % (res.error,))
return [] return []
return extract_json_response(res) return extract_json_response(res)
@ -98,8 +99,8 @@ def parse_data(data, today):
percent = percent_diff(best_last_time, best) percent = percent_diff(best_last_time, best)
if best is not None: if best is not None:
print "Last %s, %s %s ago:\t%.01f\t\t%s" \ print("Last %s, %s %s ago:\t%.01f\t\t%s" \
% (day.strftime("%A"), i, "days", best, percent) % (day.strftime("%A"), i, "days", best, percent))
best_last_time = best best_last_time = best
for metric in data: for metric in data:
@ -108,12 +109,12 @@ def parse_data(data, today):
metric['datapoints'].sort(key=lambda p: p[1]) metric['datapoints'].sort(key=lambda p: p[1])
best_today = best_during_day(metric['datapoints'], today) best_today = best_during_day(metric['datapoints'], today)
print "Date\t\t\t\tUsers\t\tChange from then to today" print("Date\t\t\t\tUsers\t\tChange from then to today")
print "Today, 0 days ago:\t\t%.01f" % (best_today,) print("Today, 0 days ago:\t\t%.01f" % (best_today,))
print_results(xrange(1, 1000), [0, 1, 2, 3, 4, 7]) print_results(xrange(1, 1000), [0, 1, 2, 3, 4, 7])
print "\n\nWeekly Wednesday results" print("\n\nWeekly Wednesday results")
print "Date\t\t\t\tUsers\t\tDelta from previous week" print("Date\t\t\t\tUsers\t\tDelta from previous week")
print_results(reversed(xrange(1, 1000)), [2], True) print_results(reversed(xrange(1, 1000)), [2], True)
@ -151,7 +152,7 @@ if __name__ == '__main__':
startfrom = noon_of(day=datetime.now()) startfrom = noon_of(day=datetime.now())
if options.start_from != 'today': if options.start_from != 'today':
startfrom = noon_of(day=datetime.fromtimestamp(int(options.start_from))) startfrom = noon_of(day=datetime.fromtimestamp(int(options.start_from)))
print "Using baseline of today as %s" % (startfrom,) print("Using baseline of today as %s" % (startfrom,))
realm_key = statsd_key(options.realm, True) realm_key = statsd_key(options.realm, True)
buckets = [options.bucket] buckets = [options.bucket]

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
from __future__ import print_function
import os import os
import shutil import shutil
import subprocess import subprocess
@ -66,13 +67,13 @@ for name, code_point in emoji_map.items():
try: try:
bw_font(name, code_point) bw_font(name, code_point)
except Exception as e: except Exception as e:
print e print(e)
print 'Missing {}, {}'.format(name, code_point) print('Missing {}, {}'.format(name, code_point))
failed = True failed = True
continue continue
os.symlink('unicode/{}.png'.format(code_point), 'out/{}.png'.format(name)) os.symlink('unicode/{}.png'.format(code_point), 'out/{}.png'.format(name))
if failed: if failed:
print "Errors dumping emoji!" print("Errors dumping emoji!")
sys.exit(1) sys.exit(1)

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 pstats import pstats
@ -12,10 +13,10 @@ can find more advanced tools for showing profiler results.
try: try:
fn = sys.argv[1] fn = sys.argv[1]
except: except:
print ''' print('''
Please supply a filename. (If you use the profiled decorator, Please supply a filename. (If you use the profiled decorator,
the file will have a suffix of ".profile".) the file will have a suffix of ".profile".)
''' ''')
sys.exit(1) sys.exit(1)
p = pstats.Stats(fn) p = pstats.Stats(fn)

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
from __future__ import print_function
import re import re
from collections import defaultdict from collections import defaultdict
import os import os
@ -15,19 +16,19 @@ for line in file(user_agents_path).readlines():
line = line.strip() line = line.strip()
match = re.match('^(?P<count>[0-9]+) "(?P<user_agent>.*)"$', line) match = re.match('^(?P<count>[0-9]+) "(?P<user_agent>.*)"$', line)
if match is None: if match is None:
print line print(line)
continue continue
groupdict = match.groupdict() groupdict = match.groupdict()
count = groupdict["count"] count = groupdict["count"]
user_agent = groupdict["user_agent"] user_agent = groupdict["user_agent"]
ret = parse_user_agent(user_agent) ret = parse_user_agent(user_agent)
if ret is None: if ret is None:
print "parse error", line print("parse error", line)
parse_errors += 1 parse_errors += 1
continue continue
user_agents_parsed[ret["name"]] += int(count) user_agents_parsed[ret["name"]] += int(count)
for key in user_agents_parsed: for key in user_agents_parsed:
print " ", key, user_agents_parsed[key] print(" ", key, user_agents_parsed[key])
print "%s parse errors!" % (parse_errors,) print("%s parse errors!" % (parse_errors,))

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.conf import settings from django.conf import settings
from django.core import validators from django.core import validators

View File

@ -1,14 +1,15 @@
from __future__ import print_function
import re import re
import time import time
def timed_ddl(db, stmt): def timed_ddl(db, stmt):
print print()
print time.asctime() print(time.asctime())
print stmt print(stmt)
t = time.time() t = time.time()
db.execute(stmt) db.execute(stmt)
delay = time.time() - t delay = time.time() - t
print 'Took %.2fs' % (delay,) print('Took %.2fs' % (delay,))
def validate(sql_thingy): def validate(sql_thingy):
# Do basic validation that table/col name is safe. # Do basic validation that table/col name is safe.
@ -24,16 +25,16 @@ def do_batch_update(db, table, cols, vals, batch_size=10000, sleep=0.1):
SET (%s) = (%s) SET (%s) = (%s)
WHERE id >= %%s AND id < %%s WHERE id >= %%s AND id < %%s
''' % (table, ', '.join(cols), ', '.join(['%s'] * len(cols))) ''' % (table, ', '.join(cols), ', '.join(['%s'] * len(cols)))
print stmt print(stmt)
(min_id, max_id) = db.execute("SELECT MIN(id), MAX(id) FROM %s" % (table,))[0] (min_id, max_id) = db.execute("SELECT MIN(id), MAX(id) FROM %s" % (table,))[0]
if min_id is None: if min_id is None:
return return
print "%s rows need updating" % (max_id - min_id,) print("%s rows need updating" % (max_id - min_id,))
while min_id <= max_id: while min_id <= max_id:
lower = min_id lower = min_id
upper = min_id + batch_size upper = min_id + batch_size
print '%s about to update range [%s,%s)' % (time.asctime(), lower, upper) print('%s about to update range [%s,%s)' % (time.asctime(), lower, upper))
db.start_transaction() db.start_transaction()
params = list(vals) + [lower, upper] params = list(vals) + [lower, upper]
db.execute(stmt, params=params) db.execute(stmt, params=params)
@ -73,7 +74,7 @@ def create_index_if_nonexistant(db, table, col, index):
test = """SELECT relname FROM pg_class test = """SELECT relname FROM pg_class
WHERE relname = %s""" WHERE relname = %s"""
if len(db.execute(test, params=[index])) != 0: if len(db.execute(test, params=[index])) != 0:
print "Not creating index '%s' because it already exists" % (index,) print("Not creating index '%s' because it already exists" % (index,))
else: else:
stmt = "CREATE INDEX %s ON %s (%s)" % (index, table, col) stmt = "CREATE INDEX %s ON %s (%s)" % (index, table, col)
timed_ddl(db, stmt) timed_ddl(db, stmt)
@ -88,13 +89,13 @@ def act_on_message_ranges(db, orm, tasks, batch_size=5000, sleep=0.5):
try: try:
min_id = all_objects.all().order_by('id')[0].id min_id = all_objects.all().order_by('id')[0].id
except IndexError: except IndexError:
print 'There is no work to do' print('There is no work to do')
return return
max_id = all_objects.all().order_by('-id')[0].id max_id = all_objects.all().order_by('-id')[0].id
print "max_id = %d" % (max_id,) print("max_id = %d" % (max_id,))
overhead = int((max_id + 1 - min_id)/ batch_size * sleep / 60) overhead = int((max_id + 1 - min_id)/ batch_size * sleep / 60)
print "Expect this to take at least %d minutes, just due to sleeps alone." % (overhead,) print("Expect this to take at least %d minutes, just due to sleeps alone." % (overhead,))
while min_id <= max_id: while min_id <= max_id:
lower = min_id lower = min_id
@ -102,7 +103,7 @@ def act_on_message_ranges(db, orm, tasks, batch_size=5000, sleep=0.5):
if upper > max_id: if upper > max_id:
upper = max_id upper = max_id
print '%s about to update range %s to %s' % (time.asctime(), lower, upper) print('%s about to update range %s to %s' % (time.asctime(), lower, upper))
db.start_transaction() db.start_transaction()
for filterer, action in tasks: for filterer, action in tasks:

View File

@ -1,3 +1,4 @@
from __future__ import print_function
from confirmation.models import Confirmation from confirmation.models import Confirmation
from django.conf import settings from django.conf import settings
from django.core.mail import EmailMultiAlternatives from django.core.mail import EmailMultiAlternatives
@ -381,7 +382,7 @@ def clear_followup_emails_queue(email, mail_client=None):
for email in mail_client.messages.list_scheduled(to=email): for email in mail_client.messages.list_scheduled(to=email):
result = mail_client.messages.cancel_scheduled(id=email["_id"]) result = mail_client.messages.cancel_scheduled(id=email["_id"])
if result.get("status") == "error": if result.get("status") == "error":
print result.get("name"), result.get("error") print(result.get("name"), result.get("error"))
return return
def log_digest_event(msg): def log_digest_event(msg):

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
import os import os
import pty import pty
@ -62,10 +63,10 @@ if __name__ == "__main__":
for (status, job) in run_parallel(wait_and_print, jobs): for (status, job) in run_parallel(wait_and_print, jobs):
output.append(job) output.append(job)
if output == expected_output: if output == expected_output:
print "Successfully passed test!" print("Successfully passed test!")
else: else:
print "Failed test!" print("Failed test!")
print jobs print(jobs)
print expected_output print(expected_output)
print output print(output)

View File

@ -1,3 +1,4 @@
from __future__ import print_function
from django.test.runner import DiscoverRunner from django.test.runner import DiscoverRunner
from zerver.lib.cache import bounce_key_prefix_for_testing from zerver.lib.cache import bounce_key_prefix_for_testing
@ -46,7 +47,7 @@ def enforce_timely_test_completion(test_method, test_name, delay):
max_delay = max_delay * 3 max_delay = max_delay * 3
if delay > max_delay: if delay > max_delay:
print 'Test is TOO slow: %s (%.3f s)' % (test_name, delay) print('Test is TOO slow: %s (%.3f s)' % (test_name, delay))
def fast_tests_only(): def fast_tests_only():
return os.environ.get('FAST_TESTS_ONLY', False) return os.environ.get('FAST_TESTS_ONLY', False)
@ -61,10 +62,10 @@ def run_test(test):
bounce_key_prefix_for_testing(test_name) bounce_key_prefix_for_testing(test_name)
print 'Running', test_name print('Running', test_name)
if not hasattr(test, "_pre_setup"): if not hasattr(test, "_pre_setup"):
print "somehow the test doesn't have _pre_setup; it may be an import fail." print("somehow the test doesn't have _pre_setup; it may be an import fail.")
print "Here's a debugger. Good luck!" print("Here's a debugger. Good luck!")
import pdb; pdb.set_trace() import pdb; pdb.set_trace()
test._pre_setup() test._pre_setup()
@ -99,5 +100,5 @@ class Runner(DiscoverRunner):
get_sqlalchemy_connection() get_sqlalchemy_connection()
self.run_suite(suite) self.run_suite(suite)
self.teardown_test_environment() self.teardown_test_environment()
print 'DONE!' print('DONE!')
print print()

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from optparse import make_option from optparse import make_option
@ -51,6 +52,6 @@ class Command(BaseCommand):
for user_profile in user_profiles: for user_profile in user_profiles:
stream, _ = create_stream_if_needed(user_profile.realm, stream_name) stream, _ = create_stream_if_needed(user_profile.realm, stream_name)
did_subscribe = do_add_subscription(user_profile, stream) did_subscribe = do_add_subscription(user_profile, stream)
print "%s %s to %s" % ( print("%s %s to %s" % (
"Subscribed" if did_subscribe else "Already subscribed", "Subscribed" if did_subscribe else "Already subscribed",
user_profile.email, stream_name) user_profile.email, stream_name))

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -17,7 +18,7 @@ class Command(BaseCommand):
try: try:
user_profile = get_user_profile_by_email(email) user_profile = get_user_profile_by_email(email)
except UserProfile.DoesNotExist: except UserProfile.DoesNotExist:
print "e-mail %s doesn't exist in the system, skipping" % (email,) print("e-mail %s doesn't exist in the system, skipping" % (email,))
continue continue
do_update_message_flags(user_profile, "add", "read", None, True) do_update_message_flags(user_profile, "add", "read", None, True)
@ -29,6 +30,6 @@ class Command(BaseCommand):
new_pointer = messages[0].id new_pointer = messages[0].id
user_profile.pointer = new_pointer user_profile.pointer = new_pointer
user_profile.save(update_fields=["pointer"]) user_profile.save(update_fields=["pointer"])
print "%s: %d => %d" % (email, old_pointer, new_pointer) print("%s: %d => %d" % (email, old_pointer, new_pointer))
else: else:
print "%s has no messages, can't bankrupt!" % (email,) print("%s has no messages, can't bankrupt!" % (email,))

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -21,7 +22,7 @@ class Command(BaseCommand):
try: try:
user_profile = get_user_profile_by_email(email) user_profile = get_user_profile_by_email(email)
old_name = user_profile.full_name old_name = user_profile.full_name
print "%s: %s -> %s" % (email, old_name, new_name) print("%s: %s -> %s" % (email, old_name, new_name))
do_change_full_name(user_profile, new_name) do_change_full_name(user_profile, new_name)
except UserProfile.DoesNotExist: except UserProfile.DoesNotExist:
print "* E-mail %s doesn't exist in the system, skipping." % (email,) print("* E-mail %s doesn't exist in the system, skipping." % (email,))

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -20,7 +21,7 @@ class Command(BaseCommand):
try: try:
user_profile = get_user_profile_by_email(old_email) user_profile = get_user_profile_by_email(old_email)
except UserProfile.DoesNotExist: except UserProfile.DoesNotExist:
print "Old e-mail doesn't exist in the system." print("Old e-mail doesn't exist in the system.")
exit(1) exit(1)
do_change_user_email(user_profile, new_email) do_change_user_email(user_profile, new_email)

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from zerver.models import get_user_profile_by_id from zerver.models import get_user_profile_by_id
from zerver.lib.rate_limiter import client, max_api_calls, max_api_window from zerver.lib.rate_limiter import client, max_api_calls, max_api_window
@ -44,7 +45,7 @@ than max_api_calls! (trying to trim) %s %s" % (key, count))
def handle(self, *args, **options): def handle(self, *args, **options):
if not settings.RATE_LIMITING: if not settings.RATE_LIMITING:
print "This machine is not using redis or rate limiting, aborting" print("This machine is not using redis or rate limiting, aborting")
exit(1) exit(1)
# Find all keys, and make sure they're all within size constraints # Find all keys, and make sure they're all within size constraints

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from optparse import make_option from optparse import make_option
@ -18,5 +19,5 @@ class Command(BaseCommand):
except AttributeError: except AttributeError:
pass pass
print "Error: You must set %s in /etc/zulip/settings.py." % (setting_name,) print("Error: You must set %s in /etc/zulip/settings.py." % (setting_name,))
sys.exit(1) sys.exit(1)

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from optparse import make_option from optparse import make_option
from django.conf import settings from django.conf import settings
@ -55,16 +56,16 @@ Usage: python2.7 manage.py create_realm --domain=foo.com --name='Foo, Inc.'"""
def handle(self, *args, **options): def handle(self, *args, **options):
if options["domain"] is None or options["name"] is None: if options["domain"] is None or options["name"] is None:
print >>sys.stderr, "\033[1;31mPlease provide both a domain and name.\033[0m\n" print("\033[1;31mPlease provide both a domain and name.\033[0m\n", file=sys.stderr)
self.print_help("python2.7 manage.py", "create_realm") self.print_help("python2.7 manage.py", "create_realm")
exit(1) exit(1)
if options["open_realm"] and options["deployment_id"] is not None: if options["open_realm"] and options["deployment_id"] is not None:
print >>sys.stderr, "\033[1;31mExternal deployments cannot be open realms.\033[0m\n" print("\033[1;31mExternal deployments cannot be open realms.\033[0m\n", file=sys.stderr)
self.print_help("python2.7 manage.py", "create_realm") self.print_help("python2.7 manage.py", "create_realm")
exit(1) exit(1)
if options["deployment_id"] is not None and settings.VOYAGER: if options["deployment_id"] is not None and settings.VOYAGER:
print >>sys.stderr, "\033[1;31mExternal deployments are not supported on voyager deployments.\033[0m\n" print("\033[1;31mExternal deployments are not supported on voyager deployments.\033[0m\n", file=sys.stderr)
exit(1) exit(1)
domain = options["domain"] domain = options["domain"]
@ -75,12 +76,12 @@ Usage: python2.7 manage.py create_realm --domain=foo.com --name='Foo, Inc.'"""
realm, created = do_create_realm( realm, created = do_create_realm(
domain, name, restricted_to_domain=not options["open_realm"]) domain, name, restricted_to_domain=not options["open_realm"])
if created: if created:
print domain, "created." print(domain, "created.")
if options["deployment_id"] is not None: if options["deployment_id"] is not None:
deployment = Deployment.objects.get(id=options["deployment_id"]) deployment = Deployment.objects.get(id=options["deployment_id"])
deployment.realms.add(realm) deployment.realms.add(realm)
deployment.save() deployment.save()
print "Added to deployment", str(deployment.id) print("Added to deployment", str(deployment.id))
elif settings.ZULIP_COM: elif settings.ZULIP_COM:
deployment = Deployment.objects.get(base_site_url="https://zulip.com/") deployment = Deployment.objects.get(base_site_url="https://zulip.com/")
deployment.realms.add(realm) deployment.realms.add(realm)
@ -89,6 +90,6 @@ Usage: python2.7 manage.py create_realm --domain=foo.com --name='Foo, Inc.'"""
set_default_streams(realm, ["social", "engineering"]) set_default_streams(realm, ["social", "engineering"])
print "\033[1;36mDefault streams set to social,engineering,zulip!\033[0m" print("\033[1;36mDefault streams set to social,engineering,zulip!\033[0m")
else: else:
print domain, "already exists." print(domain, "already exists.")

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -27,7 +28,7 @@ the command."""
try: try:
realm = get_realm(domain) realm = get_realm(domain)
except Realm.DoesNotExist: except Realm.DoesNotExist:
print "Unknown domain %s" % (domain,) print("Unknown domain %s" % (domain,))
exit(1) exit(1)
do_create_stream(realm, stream_name.decode(encoding)) do_create_stream(realm, stream_name.decode(encoding))

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
import sys import sys
import argparse import argparse
@ -68,7 +69,7 @@ parameters, or specify no parameters for interactive user creation.""")
validators.validate_email(email) validators.validate_email(email)
break break
except ValidationError: except ValidationError:
print >> sys.stderr, "Invalid email address." print("Invalid email address.", file=sys.stderr)
full_name = raw_input("Full name: ") full_name = raw_input("Full name: ")
try: try:

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -13,6 +14,6 @@ class Command(BaseCommand):
help='domain of realm to deactivate') help='domain of realm to deactivate')
def handle(self, *args, **options): def handle(self, *args, **options):
print "Deactivating", options["domain"] print("Deactivating", options["domain"])
do_deactivate_realm(get_realm(options["domain"])) do_deactivate_realm(get_realm(options["domain"]))
print "Done!" print("Done!")

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from optparse import make_option from optparse import make_option
@ -22,23 +23,23 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
user_profile = get_user_profile_by_email(options['email']) user_profile = get_user_profile_by_email(options['email'])
print "Deactivating %s (%s) - %s" % (user_profile.full_name, print("Deactivating %s (%s) - %s" % (user_profile.full_name,
user_profile.email, user_profile.email,
user_profile.realm.domain) user_profile.realm.domain))
print "%s has the following active sessions:" % (user_profile.email,) print("%s has the following active sessions:" % (user_profile.email,))
for session in user_sessions(user_profile): for session in user_sessions(user_profile):
print session.expire_date, session.get_decoded() print(session.expire_date, session.get_decoded())
print "" print("")
print "%s has %s active bots that will also be deactivated." % ( print("%s has %s active bots that will also be deactivated." % (
user_profile.email, user_profile.email,
UserProfile.objects.filter( UserProfile.objects.filter(
is_bot=True, is_active=True, bot_owner=user_profile is_bot=True, is_active=True, bot_owner=user_profile
).count() ).count()
) ))
if not options["for_real"]: if not options["for_real"]:
print "This was a dry run. Pass -f to actually deactivate." print("This was a dry run. Pass -f to actually deactivate.")
exit(1) exit(1)
do_deactivate_user(user_profile) do_deactivate_user(user_profile)
print "Sessions deleted, user deactivated." print("Sessions deleted, user deactivated.")

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -31,4 +32,4 @@ class Command(BaseCommand):
messages = Message.objects.filter(pub_date__gt=cutoff, recipient__in=recipients) messages = Message.objects.filter(pub_date__gt=cutoff, recipient__in=recipients)
for message in messages: for message in messages:
print message.to_dict(False) print(message.to_dict(False))

View File

@ -34,6 +34,7 @@ This script can be used via two mechanisms:
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
import email import email
import os import os
@ -144,13 +145,13 @@ class Command(BaseCommand):
try: try:
mark_missed_message_address_as_used(rcpt_to) mark_missed_message_address_as_used(rcpt_to)
except ZulipEmailForwardError: except ZulipEmailForwardError:
print "5.1.1 Bad destination mailbox address: Bad or expired missed message address." print("5.1.1 Bad destination mailbox address: Bad or expired missed message address.")
exit(posix.EX_NOUSER) exit(posix.EX_NOUSER)
else: else:
try: try:
extract_and_validate(rcpt_to) extract_and_validate(rcpt_to)
except ZulipEmailForwardError: except ZulipEmailForwardError:
print "5.1.1 Bad destination mailbox address: Please use the address specified in your Streams page." print("5.1.1 Bad destination mailbox address: Please use the address specified in your Streams page.")
exit(posix.EX_NOUSER) exit(posix.EX_NOUSER)
# Read in the message, at most 25MiB. This is the limit enforced by # Read in the message, at most 25MiB. This is the limit enforced by
@ -159,7 +160,7 @@ class Command(BaseCommand):
if len(sys.stdin.read(1)) != 0: if len(sys.stdin.read(1)) != 0:
# We're not at EOF, reject large mail. # We're not at EOF, reject large mail.
print "5.3.4 Message too big for system: Max size is 25MiB" print("5.3.4 Message too big for system: Max size is 25MiB")
exit(posix.EX_DATAERR) exit(posix.EX_DATAERR)
queue_json_publish( queue_json_publish(
@ -175,7 +176,7 @@ class Command(BaseCommand):
if (not settings.EMAIL_GATEWAY_BOT or not settings.EMAIL_GATEWAY_LOGIN or if (not settings.EMAIL_GATEWAY_BOT or not settings.EMAIL_GATEWAY_LOGIN or
not settings.EMAIL_GATEWAY_PASSWORD or not settings.EMAIL_GATEWAY_IMAP_SERVER or not settings.EMAIL_GATEWAY_PASSWORD or not settings.EMAIL_GATEWAY_IMAP_SERVER or
not settings.EMAIL_GATEWAY_IMAP_PORT or not settings.EMAIL_GATEWAY_IMAP_FOLDER): not settings.EMAIL_GATEWAY_IMAP_PORT or not settings.EMAIL_GATEWAY_IMAP_FOLDER):
print "Please configure the Email Mirror Gateway in your local_settings.py, or specify $ORIGINAL_RECIPIENT if piping a single mail." print("Please configure the Email Mirror Gateway in your local_settings.py, or specify $ORIGINAL_RECIPIENT if piping a single mail.")
exit(1) exit(1)
reactor.callLater(0, main) reactor.callLater(0, main)
reactor.run() reactor.run()

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from zerver.lib.queue import queue_json_publish from zerver.lib.queue import queue_json_publish
@ -47,7 +48,7 @@ You can use "-" to represent stdin.
except IndexError: except IndexError:
payload = line payload = line
print 'Queueing to queue %s: %s' % (queue_name, payload) print('Queueing to queue %s: %s' % (queue_name, payload))
# Verify that payload is valid json. # Verify that payload is valid json.
data = ujson.loads(payload) data = ujson.loads(payload)

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
import os import os
import sys import sys
@ -60,7 +61,7 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
if len(options['log_files']) == 0: if len(options['log_files']) == 0:
print >>sys.stderr, 'WARNING: No log files specified; doing nothing.' print('WARNING: No log files specified; doing nothing.', file=sys.stderr)
for infile in options['log_files']: for infile in options['log_files']:
try: try:
@ -68,5 +69,5 @@ class Command(BaseCommand):
except KeyboardInterrupt: except KeyboardInterrupt:
raise raise
except: except:
print >>sys.stderr, 'WARNING: Could not expunge from', infile print('WARNING: Could not expunge from', infile, file=sys.stderr)
traceback.print_exc() traceback.print_exc()

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from confirmation.models import Confirmation from confirmation.models import Confirmation
@ -26,7 +27,7 @@ class Command(BaseCommand):
for email in options['emails']: for email in options['emails']:
try: try:
get_user_profile_by_email(email) get_user_profile_by_email(email)
print email + ": There is already a user registered with that address." print(email + ": There is already a user registered with that address.")
duplicates = True duplicates = True
continue continue
except UserProfile.DoesNotExist: except UserProfile.DoesNotExist:
@ -40,8 +41,8 @@ class Command(BaseCommand):
if domain: if domain:
realm = get_realm(domain) realm = get_realm(domain)
if not realm: if not realm:
print "The realm %s doesn't exist yet, please create it first." % (domain,) print("The realm %s doesn't exist yet, please create it first." % (domain,))
print "Don't forget default streams!" print("Don't forget default streams!")
exit(1) exit(1)
for email in options['emails']: for email in options['emails']:
@ -49,14 +50,14 @@ class Command(BaseCommand):
if realm.restricted_to_domain and \ if realm.restricted_to_domain and \
domain.lower() != email.split("@", 1)[-1].lower() and \ domain.lower() != email.split("@", 1)[-1].lower() and \
not options["force"]: not options["force"]:
print "You've asked to add an external user (%s) to a closed realm (%s)." % ( print("You've asked to add an external user (%s) to a closed realm (%s)." % (
email, domain) email, domain))
print "Are you sure? To do this, pass --force." print("Are you sure? To do this, pass --force.")
exit(1) exit(1)
else: else:
prereg_user = PreregistrationUser(email=email, realm=realm) prereg_user = PreregistrationUser(email=email, realm=realm)
else: else:
prereg_user = PreregistrationUser(email=email) prereg_user = PreregistrationUser(email=email)
prereg_user.save() prereg_user.save()
print email + ": " + Confirmation.objects.get_link_for_object(prereg_user) print(email + ": " + Confirmation.objects.get_link_for_object(prereg_user))

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from optparse import make_option from optparse import make_option
@ -41,9 +42,9 @@ Usage: python2.7 manage.py import_dump [--destroy-rebuild-database] [--chunk-siz
def new_instance_check(self, model): def new_instance_check(self, model):
count = model.objects.count() count = model.objects.count()
if count: if count:
print "Zulip instance is not empty, found %d rows in %s table. " \ print("Zulip instance is not empty, found %d rows in %s table. " \
% (count, model._meta.db_table) % (count, model._meta.db_table))
print "You may use --destroy-rebuild-database to destroy and rebuild the database prior to import." print("You may use --destroy-rebuild-database to destroy and rebuild the database prior to import.")
exit(1) exit(1)
@ -110,7 +111,7 @@ Usage: python2.7 manage.py import_dump [--destroy-rebuild-database] [--chunk-siz
encoding = sys.getfilesystemencoding() encoding = sys.getfilesystemencoding()
if len(args) == 0: if len(args) == 0:
print "Please provide at least one database dump file name." print("Please provide at least one database dump file name.")
exit(1) exit(1)
if not options["destroy_rebuild_database"]: if not options["destroy_rebuild_database"]:
@ -133,10 +134,10 @@ Usage: python2.7 manage.py import_dump [--destroy-rebuild-database] [--chunk-siz
try: try:
fp = open(file_name, 'r') fp = open(file_name, 'r')
except IOError: except IOError:
print "File not found: '%s'" % (file_name,) print("File not found: '%s'" % (file_name,))
exit(1) exit(1)
print "Processing file: %s ..." % (file_name,) print("Processing file: %s ..." % (file_name,))
# parse the database dump and load in memory # parse the database dump and load in memory
# TODO: change this to a streaming parser to support loads > RAM size # TODO: change this to a streaming parser to support loads > RAM size
@ -146,19 +147,19 @@ Usage: python2.7 manage.py import_dump [--destroy-rebuild-database] [--chunk-siz
self.increment_row_counter(row_counter, database_dump, model) self.increment_row_counter(row_counter, database_dump, model)
self.import_table(database_dump, realm_notification_map, model) self.import_table(database_dump, realm_notification_map, model)
print "" print("")
# set notifications_stream_id on realm objects to correct value now # set notifications_stream_id on realm objects to correct value now
# that foreign keys are in streams table # that foreign keys are in streams table
if len(realm_notification_map): if len(realm_notification_map):
print "Setting realm notification stream..." print("Setting realm notification stream...")
for id, notifications_stream_id in realm_notification_map.items(): for id, notifications_stream_id in realm_notification_map.items():
Realm.objects \ Realm.objects \
.filter(id=id) \ .filter(id=id) \
.update(notifications_stream = notifications_stream_id) .update(notifications_stream = notifications_stream_id)
print "" print("")
print "Testing data import: " print("Testing data import: ")
# test that everything from all json dumps made it into the database # test that everything from all json dumps made it into the database
for model in models_to_import: for model in models_to_import:

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
@ -45,16 +46,16 @@ ONLY perform this on customer request from an authorized person.
else: else:
if options['ack']: if options['ack']:
do_change_is_admin(profile, True, permission=options['permission']) do_change_is_admin(profile, True, permission=options['permission'])
print "Done!" print("Done!")
else: else:
print "Would have granted %s %s rights for %s" % (email, options['permission'], profile.realm.domain) print("Would have granted %s %s rights for %s" % (email, options['permission'], profile.realm.domain))
else: else:
if profile.has_perm(options['permission'], profile.realm): if profile.has_perm(options['permission'], profile.realm):
if options['ack']: if options['ack']:
do_change_is_admin(profile, False, permission=options['permission']) do_change_is_admin(profile, False, permission=options['permission'])
print "Done!" print("Done!")
else: else:
print "Would have removed %s's %s rights on %s" % (email, options['permission'], print("Would have removed %s's %s rights on %s" % (email, options['permission'],
profile.realm.domain) profile.realm.domain))
else: else:
raise CommandError("User did not have permission for this realm!") raise CommandError("User did not have permission for this realm!")

View File

@ -5,6 +5,7 @@ Shows backlog count of ScheduledJobs of type Email
""" """
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -24,7 +25,7 @@ Usage: python2.7 manage.py print_email_delivery_backlog
""" """
def handle(self, *args, **options): def handle(self, *args, **options):
print len(ScheduledJob.objects.filter(type=ScheduledJob.EMAIL, print(len(ScheduledJob.objects.filter(type=ScheduledJob.EMAIL,
scheduled_timestamp__lte=datetime.utcnow()-timedelta(minutes=1))) scheduled_timestamp__lte=datetime.utcnow()-timedelta(minutes=1))))
return return

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.core.management import CommandError from django.core.management import CommandError
@ -15,4 +16,4 @@ class Command(BaseCommand):
queue = SimpleQueueClient() queue = SimpleQueueClient()
queue.ensure_queue(queue_name, lambda: None) queue.ensure_queue(queue_name, lambda: None)
queue.channel.queue_purge(queue_name) queue.channel.queue_purge(queue_name)
print "Done" print("Done")

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
import sys import sys
@ -16,10 +17,10 @@ def query_ldap(**options):
if isinstance(backend, LDAPBackend): if isinstance(backend, LDAPBackend):
ldap_attrs = _LDAPUser(backend, backend.django_to_ldap_username(email)).attrs ldap_attrs = _LDAPUser(backend, backend.django_to_ldap_username(email)).attrs
if ldap_attrs is None: if ldap_attrs is None:
print "No such user found" print("No such user found")
else: else:
for django_field, ldap_field in settings.AUTH_LDAP_USER_ATTR_MAP.items(): for django_field, ldap_field in settings.AUTH_LDAP_USER_ATTR_MAP.items():
print "%s: %s" % (django_field, ldap_attrs[ldap_field]) print("%s: %s" % (django_field, ldap_attrs[ldap_field]))
class Command(BaseCommand): class Command(BaseCommand):
def add_arguments(self, parser): def add_arguments(self, parser):

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from zerver.models import UserProfile, get_user_profile_by_email from zerver.models import UserProfile, get_user_profile_by_email
from zerver.lib.rate_limiter import block_user, unblock_user from zerver.lib.rate_limiter import block_user, unblock_user
@ -36,7 +37,7 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
if (not options['api_key'] and not options['email']) or \ if (not options['api_key'] and not options['email']) or \
(options['api_key'] and options['email']): (options['api_key'] and options['email']):
print "Please enter either an email or API key to manage" print("Please enter either an email or API key to manage")
exit(1) exit(1)
if options['email']: if options['email']:
@ -45,7 +46,7 @@ class Command(BaseCommand):
try: try:
user_profile = UserProfile.objects.get(api_key=options['api_key']) user_profile = UserProfile.objects.get(api_key=options['api_key'])
except: except:
print "Unable to get user profile for api key %s" % (options['api_key'], ) print("Unable to get user profile for api key %s" % (options['api_key'], ))
exit(1) exit(1)
users = [user_profile] users = [user_profile]
@ -55,7 +56,7 @@ class Command(BaseCommand):
operation = options['operation'] operation = options['operation']
for user in users: for user in users:
print "Applying operation to User ID: %s: %s" % (user.id, operation) print("Applying operation to User ID: %s: %s" % (user.id, operation))
if operation == 'block': if operation == 'block':
block_user(user, options['seconds'], options['domain']) block_user(user, options['seconds'], options['domain'])

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from zerver.models import Realm, RealmAlias, get_realm from zerver.models import Realm, RealmAlias, get_realm
@ -25,15 +26,15 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
realm = get_realm(options["domain"]) realm = get_realm(options["domain"])
if options["op"] == "show": if options["op"] == "show":
print "Aliases for %s:" % (realm.domain,) print("Aliases for %s:" % (realm.domain,))
for alias in realm_aliases(realm): for alias in realm_aliases(realm):
print alias print(alias)
sys.exit(0) sys.exit(0)
alias = options['alias'] alias = options['alias']
if options["op"] == "add": if options["op"] == "add":
if get_realm(alias) is not None: if get_realm(alias) is not None:
print "A Realm already exists for this domain, cannot add it as an alias for another realm!" print("A Realm already exists for this domain, cannot add it as an alias for another realm!")
sys.exit(1) sys.exit(1)
RealmAlias.objects.create(realm=realm, domain=alias) RealmAlias.objects.create(realm=realm, domain=alias)
sys.exit(0) sys.exit(0)

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from zerver.models import Realm, get_realm from zerver.models import Realm, get_realm
@ -33,7 +34,7 @@ Example: python2.7 manage.py realm_emoji --realm=zulip.com --op=show
realm = get_realm(options["domain"]) realm = get_realm(options["domain"])
if options["op"] == "show": if options["op"] == "show":
for name, url in realm.get_emoji().iteritems(): for name, url in realm.get_emoji().iteritems():
print name, url print(name, url)
sys.exit(0) sys.exit(0)
name = options['name'] name = options['name']

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -39,7 +40,7 @@ Example: python2.7 manage.py realm_filters --realm=zulip.com --op=show
def handle(self, *args, **options): def handle(self, *args, **options):
realm = get_realm(options["domain"]) realm = get_realm(options["domain"])
if options["op"] == "show": if options["op"] == "show":
print "%s: %s" % (realm.domain, all_realm_filters().get(realm.domain, "")) print("%s: %s" % (realm.domain, all_realm_filters().get(realm.domain, "")))
sys.exit(0) sys.exit(0)
pattern = options['pattern'] pattern = options['pattern']

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from optparse import make_option from optparse import make_option
@ -51,6 +52,6 @@ class Command(BaseCommand):
for user_profile in user_profiles: for user_profile in user_profiles:
did_remove = do_remove_subscription(user_profile, stream) did_remove = do_remove_subscription(user_profile, stream)
print "%s %s from %s" % ( print("%s %s from %s" % (
"Removed" if did_remove else "Couldn't remove", "Removed" if did_remove else "Couldn't remove",
user_profile.email, stream_name) user_profile.email, stream_name))

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -27,7 +28,7 @@ class Command(BaseCommand):
try: try:
realm = get_realm(domain) realm = get_realm(domain)
except Realm.DoesNotExist: except Realm.DoesNotExist:
print "Unknown domain %s" % (domain,) print("Unknown domain %s" % (domain,))
exit(1) exit(1)
do_rename_stream(realm, old_name.decode(encoding), do_rename_stream(realm, old_name.decode(encoding),

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.conf import settings from django.conf import settings
settings.RUNNING_INSIDE_TORNADO = True settings.RUNNING_INSIDE_TORNADO = True
@ -73,11 +74,11 @@ class Command(BaseCommand):
from django.utils import translation from django.utils import translation
translation.activate(settings.LANGUAGE_CODE) translation.activate(settings.LANGUAGE_CODE)
print "Validating Django models.py..." print("Validating Django models.py...")
self.validate(display_num_errors=True) self.validate(display_num_errors=True)
print "\nDjango version %s" % (django.get_version()) print("\nDjango version %s" % (django.get_version()))
print "Tornado server is running at http://%s:%s/" % (addr, port) print("Tornado server is running at http://%s:%s/" % (addr, port))
print "Quit the server with %s." % (quit_command,) print("Quit the server with %s." % (quit_command,))
if settings.USING_RABBITMQ: if settings.USING_RABBITMQ:
queue_client = get_queue_client() queue_client = get_queue_client()

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -36,8 +37,8 @@ python2.7 manage.py set_default_streams --domain=foo.com --streams=
def handle(self, **options): def handle(self, **options):
if options["domain"] is None or options["streams"] is None: if options["domain"] is None or options["streams"] is None:
print >>sys.stderr, "Please provide both a domain name and a default \ print("Please provide both a domain name and a default \
set of streams (which can be empty, with `--streams=`)." set of streams (which can be empty, with `--streams=`).", file=sys.stderr)
exit(1) exit(1)
stream_names = [stream.strip() for stream in options["streams"].split(",")] stream_names = [stream.strip() for stream in options["streams"].split(",")]

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from optparse import make_option from optparse import make_option
import logging import logging
@ -41,7 +42,7 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
if not options["flag"] or not options["op"] or not options["email"]: if not options["flag"] or not options["op"] or not options["email"]:
print "Please specify an operation, a flag and an email" print("Please specify an operation, a flag and an email")
exit(1) exit(1)
op = options['op'] op = options['op']

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from zerver.models import get_realm, Realm from zerver.models import get_realm, Realm
@ -17,16 +18,16 @@ class Command(BaseCommand):
try: try:
realm = get_realm(realm) realm = get_realm(realm)
except Realm.DoesNotExist: except Realm.DoesNotExist:
print 'There is no realm called %s.' % (realm,) print('There is no realm called %s.' % (realm,))
sys.exit(1) sys.exit(1)
users = realm.get_admin_users() users = realm.get_admin_users()
if users: if users:
print 'Admins:\n' print('Admins:\n')
for user in users: for user in users:
print ' %s (%s)' % (user.email, user.full_name) print(' %s (%s)' % (user.email, user.full_name))
else: else:
print 'There are no admins for this realm!' print('There are no admins for this realm!')
print '\nYou can use the "knight" management command to knight admins.' print('\nYou can use the "knight" management command to knight admins.')

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from optparse import make_option from optparse import make_option
@ -35,12 +36,12 @@ class Command(BaseCommand):
for email in emails: for email in emails:
user_profiles.append(get_user_profile_by_email(email)) user_profiles.append(get_user_profile_by_email(email))
print "Turned off digest emails for:" print("Turned off digest emails for:")
for user_profile in user_profiles: for user_profile in user_profiles:
already_disabled_prefix = "" already_disabled_prefix = ""
if user_profile.enable_digest_emails: if user_profile.enable_digest_emails:
do_change_enable_digest_emails(user_profile, False) do_change_enable_digest_emails(user_profile, False)
else: else:
already_disabled_prefix = "(already off) " already_disabled_prefix = "(already off) "
print "%s%s <%s>" % (already_disabled_prefix, user_profile.full_name, print("%s%s <%s>" % (already_disabled_prefix, user_profile.full_name,
user_profile.email) user_profile.email))

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import print_function
from django.conf import settings from django.conf import settings
from django.test import TestCase from django.test import TestCase
@ -149,7 +150,7 @@ class BugdownTest(TestCase):
for name, test in format_tests.iteritems(): for name, test in format_tests.iteritems():
converted = bugdown_convert(test['input']) converted = bugdown_convert(test['input'])
print "Running Bugdown test %s" % (name,) print("Running Bugdown test %s" % (name,))
self.assertEqual(converted, test['expected_output']) self.assertEqual(converted, test['expected_output'])
def replaced(payload, url, phrase=''): def replaced(payload, url, phrase=''):
@ -164,7 +165,7 @@ class BugdownTest(TestCase):
return payload % ("<a href=\"%s\"%s title=\"%s\">%s</a>" % (href, target, href, url),) return payload % ("<a href=\"%s\"%s title=\"%s\">%s</a>" % (href, target, href, url),)
print "Running Bugdown Linkify tests" print("Running Bugdown Linkify tests")
self.maxDiff = None self.maxDiff = None
for inline_url, reference, url in linkify_tests: for inline_url, reference, url in linkify_tests:
try: try:

View File

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.test import TestCase from django.test import TestCase
@ -40,7 +41,7 @@ import time
import ujson import ujson
def bail(msg): def bail(msg):
print '\nERROR: %s\n' % (msg,) print('\nERROR: %s\n' % (msg,))
sys.exit(1) sys.exit(1)
try: try:

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from optparse import make_option from optparse import make_option
import sys import sys
@ -31,17 +32,17 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
if None in (options["api"], options["web"], options["domain"]): if None in (options["api"], options["web"], options["domain"]):
print >>sys.stderr, "\033[1;31mYou must provide a domain, an API URL, and a web URL.\033[0m\n" print("\033[1;31mYou must provide a domain, an API URL, and a web URL.\033[0m\n", file=sys.stderr)
self.print_help("python2.7 manage.py", "create_realm") self.print_help("python2.7 manage.py", "create_realm")
exit(1) exit(1)
if not options["no_realm"]: if not options["no_realm"]:
CreateRealm().handle(*args, **options) CreateRealm().handle(*args, **options)
print # Newline print() # Newline
realm = get_realm(options["domain"]) realm = get_realm(options["domain"])
if realm is None: if realm is None:
print >>sys.stderr, "\033[1;31mRealm does not exist!\033[0m\n" print("\033[1;31mRealm does not exist!\033[0m\n", file=sys.stderr)
exit(2) exit(2)
dep = Deployment() dep = Deployment()
@ -55,6 +56,6 @@ class Command(BaseCommand):
dep.base_api_url = options["api"] dep.base_api_url = options["api"]
dep.base_site_url = options["web"] dep.base_site_url = options["web"]
dep.save() dep.save()
print "Deployment %s created." % (dep.id,) print("Deployment %s created." % (dep.id,))
print "DEPLOYMENT_ROLE_NAME = %s" % (dep.name,) print("DEPLOYMENT_ROLE_NAME = %s" % (dep.name,))
print "DEPLOYMENT_ROLE_KEY = %s" % (dep.api_key,) print("DEPLOYMENT_ROLE_KEY = %s" % (dep.api_key,))

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.utils.timezone import now from django.utils.timezone import now
@ -261,7 +262,7 @@ def restore_saved_messages():
client_set = set(["populate_db", "website", "zephyr_mirror"]) client_set = set(["populate_db", "website", "zephyr_mirror"])
huddle_user_set = set() huddle_user_set = set()
# First, determine all the objects our messages will need. # First, determine all the objects our messages will need.
print datetime.datetime.now(), "Creating realms/streams/etc..." print(datetime.datetime.now(), "Creating realms/streams/etc...")
def process_line(line): def process_line(line):
old_message_json = line.strip() old_message_json = line.strip()
@ -376,21 +377,21 @@ def restore_saved_messages():
huddle_recipients = {} huddle_recipients = {}
# Then, create the objects our messages need. # Then, create the objects our messages need.
print datetime.datetime.now(), "Creating realms..." print(datetime.datetime.now(), "Creating realms...")
bulk_create_realms(realm_set) bulk_create_realms(realm_set)
realms = {} realms = {}
for realm in Realm.objects.all(): for realm in Realm.objects.all():
realms[realm.domain] = realm realms[realm.domain] = realm
print datetime.datetime.now(), "Creating clients..." print(datetime.datetime.now(), "Creating clients...")
bulk_create_clients(client_set) bulk_create_clients(client_set)
clients = {} clients = {}
for client in Client.objects.all(): for client in Client.objects.all():
clients[client.name] = client clients[client.name] = client
print datetime.datetime.now(), "Creating streams..." print(datetime.datetime.now(), "Creating streams...")
bulk_create_streams(realms, stream_dict.values()) bulk_create_streams(realms, stream_dict.values())
streams = {} streams = {}
@ -400,7 +401,7 @@ def restore_saved_messages():
stream_recipients[(streams[recipient.type_id].realm_id, stream_recipients[(streams[recipient.type_id].realm_id,
streams[recipient.type_id].name.lower())] = recipient streams[recipient.type_id].name.lower())] = recipient
print datetime.datetime.now(), "Creating users..." print(datetime.datetime.now(), "Creating users...")
bulk_create_users(realms, user_set) bulk_create_users(realms, user_set)
users = {} users = {}
@ -411,7 +412,7 @@ def restore_saved_messages():
for recipient in Recipient.objects.filter(type=Recipient.PERSONAL): for recipient in Recipient.objects.filter(type=Recipient.PERSONAL):
user_recipients[users_by_id[recipient.type_id].email] = recipient user_recipients[users_by_id[recipient.type_id].email] = recipient
print datetime.datetime.now(), "Creating huddles..." print(datetime.datetime.now(), "Creating huddles...")
bulk_create_huddles(users, huddle_user_set) bulk_create_huddles(users, huddle_user_set)
huddles_by_id = {} huddles_by_id = {}
@ -423,14 +424,14 @@ def restore_saved_messages():
# TODO: Add a special entry type in the log that is a subscription # TODO: Add a special entry type in the log that is a subscription
# change and import those as we go to make subscription changes # change and import those as we go to make subscription changes
# take effect! # take effect!
print datetime.datetime.now(), "Importing subscriptions..." print(datetime.datetime.now(), "Importing subscriptions...")
subscribers = {} subscribers = {}
for s in Subscription.objects.select_related().all(): for s in Subscription.objects.select_related().all():
if s.active: if s.active:
subscribers.setdefault(s.recipient.id, set()).add(s.user_profile.id) subscribers.setdefault(s.recipient.id, set()).add(s.user_profile.id)
# Then create all the messages, without talking to the DB! # Then create all the messages, without talking to the DB!
print datetime.datetime.now(), "Importing messages, part 1..." print(datetime.datetime.now(), "Importing messages, part 1...")
first_message_id = None first_message_id = None
if Message.objects.exists(): if Message.objects.exists():
first_message_id = Message.objects.all().order_by("-id")[0].id + 1 first_message_id = Message.objects.all().order_by("-id")[0].id + 1
@ -482,12 +483,12 @@ def restore_saved_messages():
raise ValueError('Bad message type') raise ValueError('Bad message type')
messages_to_create.append(message) messages_to_create.append(message)
print datetime.datetime.now(), "Importing messages, part 2..." print(datetime.datetime.now(), "Importing messages, part 2...")
Message.objects.bulk_create(messages_to_create) Message.objects.bulk_create(messages_to_create)
messages_to_create = [] messages_to_create = []
# Finally, create all the UserMessage objects # Finally, create all the UserMessage objects
print datetime.datetime.now(), "Importing usermessages, part 1..." print(datetime.datetime.now(), "Importing usermessages, part 1...")
personal_recipients = {} personal_recipients = {}
for r in Recipient.objects.filter(type = Recipient.PERSONAL): for r in Recipient.objects.filter(type = Recipient.PERSONAL):
personal_recipients[r.id] = True personal_recipients[r.id] = True
@ -500,7 +501,7 @@ def restore_saved_messages():
messages_by_id[message.id] = message messages_by_id[message.id] = message
if len(messages_by_id) == 0: if len(messages_by_id) == 0:
print datetime.datetime.now(), "No old messages to replay" print(datetime.datetime.now(), "No old messages to replay")
return return
if first_message_id is None: if first_message_id is None:
@ -526,8 +527,8 @@ def restore_saved_messages():
try: try:
subscribers[stream_recipients[stream_key].id].remove(user_id) subscribers[stream_recipients[stream_key].id].remove(user_id)
except KeyError: except KeyError:
print "Error unsubscribing %s from %s: not subscribed" % ( print("Error unsubscribing %s from %s: not subscribed" % (
old_message["user"], old_message["name"]) old_message["user"], old_message["name"]))
pending_subs[(stream_recipients[stream_key].id, pending_subs[(stream_recipients[stream_key].id,
users[old_message["user"]].id)] = False users[old_message["user"]].id)] = False
continue continue
@ -627,11 +628,11 @@ def restore_saved_messages():
UserMessage.objects.bulk_create(user_messages_to_create) UserMessage.objects.bulk_create(user_messages_to_create)
user_messages_to_create = [] user_messages_to_create = []
print datetime.datetime.now(), "Importing usermessages, part 2..." print(datetime.datetime.now(), "Importing usermessages, part 2...")
tot_user_messages += len(user_messages_to_create) tot_user_messages += len(user_messages_to_create)
UserMessage.objects.bulk_create(user_messages_to_create) UserMessage.objects.bulk_create(user_messages_to_create)
print datetime.datetime.now(), "Finalizing subscriptions..." print(datetime.datetime.now(), "Finalizing subscriptions...")
current_subs = {} current_subs = {}
current_subs_obj = {} current_subs_obj = {}
for s in Subscription.objects.select_related().all(): for s in Subscription.objects.select_related().all():
@ -666,14 +667,14 @@ def restore_saved_messages():
# TODO: do restore of subscription colors -- we're currently not # TODO: do restore of subscription colors -- we're currently not
# logging changes so there's little point in having the code :( # logging changes so there's little point in having the code :(
print datetime.datetime.now(), "Finished importing %s messages (%s usermessages)" % \ print(datetime.datetime.now(), "Finished importing %s messages (%s usermessages)" % \
(len(all_messages), tot_user_messages) (len(all_messages), tot_user_messages))
site = Site.objects.get_current() site = Site.objects.get_current()
site.domain = 'zulip.com' site.domain = 'zulip.com'
site.save() site.save()
print datetime.datetime.now(), "Filling in user pointers..." print(datetime.datetime.now(), "Filling in user pointers...")
# Set restored pointers to the very latest messages # Set restored pointers to the very latest messages
for user_profile in UserProfile.objects.all(): for user_profile in UserProfile.objects.all():
@ -685,7 +686,7 @@ def restore_saved_messages():
user_profile.pointer = -1 user_profile.pointer = -1
user_profile.save(update_fields=["pointer"]) user_profile.save(update_fields=["pointer"])
print datetime.datetime.now(), "Done replaying old messages" print(datetime.datetime.now(), "Done replaying old messages")
# Create some test messages, including: # Create some test messages, including:
# - multiple streams # - multiple streams

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from zerver.lib.initial_password import initial_password from zerver.lib.initial_password import initial_password
@ -14,9 +15,9 @@ class Command(BaseCommand):
help="email of user to show password and API key for") help="email of user to show password and API key for")
def handle(self, *args, **options): def handle(self, *args, **options):
print self.fmt % ('email', 'password', 'API key') print(self.fmt % ('email', 'password', 'API key'))
for email in options['emails']: for email in options['emails']:
if '@' not in email: if '@' not in email:
print 'ERROR: %s does not look like an email address' % (email,) print('ERROR: %s does not look like an email address' % (email,))
continue continue
print self.fmt % (email, initial_password(email), get_user_profile_by_email(email).api_key) print(self.fmt % (email, initial_password(email), get_user_profile_by_email(email).api_key))

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
@ -20,6 +21,6 @@ Usage: python2.7 manage.py render_old_messages"""
for message in messages: for message in messages:
message.maybe_render_content(None, save=True) message.maybe_render_content(None, save=True)
total_rendered += len(messages) total_rendered += len(messages)
print datetime.datetime.now(), total_rendered print(datetime.datetime.now(), total_rendered)
# Put in some sleep so this can run safely on low resource machines # Put in some sleep so this can run safely on low resource machines
time.sleep(0.25) time.sleep(0.25)

View File

@ -1,4 +1,5 @@
from __future__ import absolute_import from __future__ import absolute_import
from __future__ import print_function
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from zerver.models import get_user_profile_by_email, UserProfile from zerver.models import get_user_profile_by_email, UserProfile
@ -23,4 +24,4 @@ class Command(BaseCommand):
user_profile.api_key = api_key user_profile.api_key = api_key
user_profile.save(update_fields=["api_key"]) user_profile.save(update_fields=["api_key"])
except UserProfile.DoesNotExist: except UserProfile.DoesNotExist:
print "User %s does not exist; not syncing API key" % (email,) print("User %s does not exist; not syncing API key" % (email,))

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python2.7 #!/usr/bin/env python2.7
from __future__ import print_function
import os import os
import sys import sys
import datetime import datetime
@ -27,4 +28,4 @@ def make_deploy_path():
if __name__ == '__main__': if __name__ == '__main__':
cmd = sys.argv[1] cmd = sys.argv[1]
if cmd == 'make_deploy_path': if cmd == 'make_deploy_path':
print make_deploy_path() print(make_deploy_path())