git cl upload: convert to print_function

This makes the code work both in python2 and python3.

Review-Url: https://codereview.chromium.org/2078553002
changes/90/365990/1
vapier 10 years ago committed by Commit bot
parent 8057ac8802
commit c094376847

@ -34,6 +34,8 @@ against by using the '--rev' option.
# This code is derived from appcfg.py in the App Engine SDK (open source), # This code is derived from appcfg.py in the App Engine SDK (open source),
# and from ASPN recipe #146306. # and from ASPN recipe #146306.
from __future__ import print_function
import ConfigParser import ConfigParser
import cookielib import cookielib
import errno import errno
@ -168,12 +170,12 @@ def StatusUpdate(msg):
msg: The string to print. msg: The string to print.
""" """
if verbosity > 0: if verbosity > 0:
print msg print(msg)
def ErrorExit(msg): def ErrorExit(msg):
"""Print an error message to stderr and exit.""" """Print an error message to stderr and exit."""
print >> sys.stderr, msg print(msg, file=sys.stderr)
sys.exit(1) sys.exit(1)
@ -358,7 +360,7 @@ class AbstractRpcServer(object):
except ClientLoginError, exc: except ClientLoginError, exc:
e = exc e = exc
if e: if e:
print >> sys.stderr, '' print('', file=sys.stderr)
error_message = e.reason error_message = e.reason
if error_map: if error_map:
error_message = error_map.get(error_message, error_message) error_message = error_map.get(error_message, error_message)
@ -370,7 +372,7 @@ class AbstractRpcServer(object):
"See http://www.google.com/" "See http://www.google.com/"
"support/accounts/bin/answer.py?answer=185833") "support/accounts/bin/answer.py?answer=185833")
else: else:
print >> sys.stderr, "Invalid username or password." print("Invalid username or password.", file=sys.stderr)
elif error_message == "CaptchaRequired": elif error_message == "CaptchaRequired":
print >> sys.stderr, ( print >> sys.stderr, (
"Please go to\n" "Please go to\n"
@ -379,23 +381,24 @@ class AbstractRpcServer(object):
"If you are using a Google Apps account the URL is:\n" "If you are using a Google Apps account the URL is:\n"
"https://www.google.com/a/yourdomain.com/UnlockCaptcha") "https://www.google.com/a/yourdomain.com/UnlockCaptcha")
elif error_message == "NotVerified": elif error_message == "NotVerified":
print >> sys.stderr, "Account not verified." print("Account not verified.", file=sys.stderr)
elif error_message == "TermsNotAgreed": elif error_message == "TermsNotAgreed":
print >> sys.stderr, "User has not agreed to TOS." print("User has not agreed to TOS.", file=sys.stderr)
elif error_message == "AccountDeleted": elif error_message == "AccountDeleted":
print >> sys.stderr, "The user account has been deleted." print("The user account has been deleted.", file=sys.stderr)
elif error_message == "AccountDisabled": elif error_message == "AccountDisabled":
print >> sys.stderr, "The user account has been disabled." print("The user account has been disabled.", file=sys.stderr)
break break
elif error_message == "ServiceDisabled": elif error_message == "ServiceDisabled":
print >> sys.stderr, ("The user's access to the service has been " print("The user's access to the service has been disabled.",
"disabled.") file=sys.stderr)
elif error_message == "ServiceUnavailable": elif error_message == "ServiceUnavailable":
print >> sys.stderr, "The service is not available; try again later." print("The service is not available; try again later.",
file=sys.stderr)
else: else:
# Unknown error. # Unknown error.
raise e raise e
print >> sys.stderr, '' print('', file=sys.stderr)
continue continue
self._GetAuthCookie(auth_token) self._GetAuthCookie(auth_token)
return return
@ -720,10 +723,10 @@ class KeyringCreds(object):
except: except:
# Sadly, we have to trap all errors here as # Sadly, we have to trap all errors here as
# gnomekeyring.IOError inherits from object. :/ # gnomekeyring.IOError inherits from object. :/
print "Failed to get password from keyring" print("Failed to get password from keyring")
keyring = None keyring = None
if password is not None: if password is not None:
print "Using password from system keyring." print("Using password from system keyring.")
self.accounts_seen.add(email) self.accounts_seen.add(email)
else: else:
password = getpass.getpass("Password for %s: " % email) password = getpass.getpass("Password for %s: " % email)
@ -920,9 +923,9 @@ class VersionControlSystem(object):
"""Show an "are you sure?" prompt if there are unknown files.""" """Show an "are you sure?" prompt if there are unknown files."""
unknown_files = self.GetUnknownFiles() unknown_files = self.GetUnknownFiles()
if unknown_files: if unknown_files:
print "The following files are not added to version control:" print("The following files are not added to version control:")
for line in unknown_files: for line in unknown_files:
print line print(line)
prompt = "Are you sure to continue?(y/N) " prompt = "Are you sure to continue?(y/N) "
answer = raw_input(prompt).strip() answer = raw_input(prompt).strip()
if answer != "y": if answer != "y":
@ -1029,7 +1032,7 @@ class VersionControlSystem(object):
threads.append(t) threads.append(t)
for t in threads: for t in threads:
print t.get(timeout=60) print(t.get(timeout=60))
def IsImage(self, filename): def IsImage(self, filename):
"""Returns true if the filename has an image extension.""" """Returns true if the filename has an image extension."""
@ -1703,7 +1706,7 @@ class PerforceVCS(VersionControlSystem):
ErrorExit("Error checking perforce login") ErrorExit("Error checking perforce login")
if not retcode and (not "code" in data or data["code"] != "error"): if not retcode and (not "code" in data or data["code"] != "error"):
break break
print "Enter perforce password: " print("Enter perforce password: ")
self.RunPerforceCommandWithReturnCode(["login"]) self.RunPerforceCommandWithReturnCode(["login"])
super(PerforceVCS, self).__init__(options) super(PerforceVCS, self).__init__(options)
@ -2083,8 +2086,8 @@ def UploadSeparatePatches(issue, rpc_server, patchset, data, options):
rv = [] rv = []
for patch in patches: for patch in patches:
if len(patch[1]) > MAX_UPLOAD_SIZE: if len(patch[1]) > MAX_UPLOAD_SIZE:
print ("Not uploading the patch for " + patch[0] + print("Not uploading the patch for %s because the file is too large." %
" because the file is too large.") (patch[0],))
continue continue
filename = patch[0] filename = patch[0]
@ -2095,7 +2098,7 @@ def UploadSeparatePatches(issue, rpc_server, patchset, data, options):
for t in threads: for t in threads:
result = t.get(timeout=60) result = t.get(timeout=60)
print result[0] print(result[0])
rv.append(result[1]) rv.append(result[1])
return rv return rv
@ -2372,8 +2375,8 @@ def RealMain(argv, data=None):
guessed_base = vcs.GuessBase(options.download_base) guessed_base = vcs.GuessBase(options.download_base)
if base: if base:
if guessed_base and base != guessed_base: if guessed_base and base != guessed_base:
print "Using base URL \"%s\" from --base_url instead of \"%s\"" % \ print("Using base URL \"%s\" from --base_url instead of \"%s\"" %
(base, guessed_base) (base, guessed_base))
else: else:
base = guessed_base base = guessed_base
@ -2386,12 +2389,12 @@ def RealMain(argv, data=None):
data = vcs.GenerateDiff(args) data = vcs.GenerateDiff(args)
data = vcs.PostProcessDiff(data) data = vcs.PostProcessDiff(data)
if options.print_diffs: if options.print_diffs:
print "Rietveld diff start:*****" print("Rietveld diff start:*****")
print data print(data)
print "Rietveld diff end:*****" print("Rietveld diff end:*****")
files = vcs.GetBaseFiles(data) files = vcs.GetBaseFiles(data)
if verbosity >= 1: if verbosity >= 1:
print "Upload server:", options.server, "(change with -s/--server)" print("Upload server:", options.server, "(change with -s/--server)")
auth_config = auth.extract_auth_config_from_options(options) auth_config = auth.extract_auth_config_from_options(options)
rpc_server = GetRpcServer(options.server, auth_config, options.email) rpc_server = GetRpcServer(options.server, auth_config, options.email)
@ -2477,7 +2480,7 @@ def RealMain(argv, data=None):
form_fields.append(("base_hashes", base_hashes)) form_fields.append(("base_hashes", base_hashes))
if options.private: if options.private:
if options.issue: if options.issue:
print "Warning: Private flag ignored when updating an existing issue." print("Warning: Private flag ignored when updating an existing issue.")
else: else:
form_fields.append(("private", "1")) form_fields.append(("private", "1"))
if options.send_patch: if options.send_patch:
@ -2485,7 +2488,7 @@ def RealMain(argv, data=None):
if not options.download_base: if not options.download_base:
form_fields.append(("content_upload", "1")) form_fields.append(("content_upload", "1"))
if len(data) > MAX_UPLOAD_SIZE: if len(data) > MAX_UPLOAD_SIZE:
print "Patch is large, so uploading file patches separately." print("Patch is large, so uploading file patches separately.")
uploaded_diff_file = [] uploaded_diff_file = []
form_fields.append(("separate_patches", "1")) form_fields.append(("separate_patches", "1"))
else: else:
@ -2544,7 +2547,7 @@ def main():
StatusUpdate("Interrupted.") StatusUpdate("Interrupted.")
sys.exit(1) sys.exit(1)
except auth.AuthenticationError as e: except auth.AuthenticationError as e:
print >> sys.stderr, e print(e, file=sys.stderr)
sys.exit(1) sys.exit(1)

Loading…
Cancel
Save