From cecd1d864fc3cf02cf50d367111e0d0e173c5dc6 Mon Sep 17 00:00:00 2001 From: Sarah Owens Date: Thu, 1 Nov 2012 22:59:27 -0700 Subject: Change print statements to work in python3 This is part of a series of changes to introduce Python3 support. Change-Id: I373be5de7141aa127d7debdbce1df39148dbec32 --- main.py | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'main.py') diff --git a/main.py b/main.py index 9fbccfb9..87e9c349 100755 --- a/main.py +++ b/main.py @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function import getpass import imp import netrc @@ -98,15 +99,14 @@ class _Repo(object): if name == 'help': name = 'version' else: - print >>sys.stderr, 'fatal: invalid usage of --version' + print('fatal: invalid usage of --version', file=sys.stderr) return 1 try: cmd = self.commands[name] except KeyError: - print >>sys.stderr,\ - "repo: '%s' is not a repo command. See 'repo help'."\ - % name + print("repo: '%s' is not a repo command. See 'repo help'." % name, + file=sys.stderr) return 1 cmd.repodir = self.repodir @@ -114,9 +114,8 @@ class _Repo(object): Editor.globalConfig = cmd.manifest.globalConfig if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror: - print >>sys.stderr, \ - "fatal: '%s' requires a working directory"\ - % name + print("fatal: '%s' requires a working directory" % name, + file=sys.stderr) return 1 copts, cargs = cmd.OptionParser.parse_args(argv) @@ -142,22 +141,21 @@ class _Repo(object): minutes, seconds = divmod(remainder, 60) if gopts.time: if hours == 0: - print >>sys.stderr, 'real\t%dm%.3fs' \ - % (minutes, seconds) + print('real\t%dm%.3fs' % (minutes, seconds), file=sys.stderr) else: - print >>sys.stderr, 'real\t%dh%dm%.3fs' \ - % (hours, minutes, seconds) + print('real\t%dh%dm%.3fs' % (hours, minutes, seconds), + file=sys.stderr) except DownloadError as e: - print >>sys.stderr, 'error: %s' % str(e) + print('error: %s' % str(e), file=sys.stderr) return 1 except ManifestInvalidRevisionError as e: - print >>sys.stderr, 'error: %s' % str(e) + print('error: %s' % str(e), file=sys.stderr) return 1 except NoSuchProjectError as e: if e.name: - print >>sys.stderr, 'error: project %s not found' % e.name + print('error: project %s not found' % e.name, file=sys.stderr) else: - print >>sys.stderr, 'error: no project in current directory' + print('error: no project in current directory', file=sys.stderr) return 1 return result @@ -183,7 +181,7 @@ def _CheckWrapperVersion(ver, repo_path): repo_path = '~/bin/repo' if not ver: - print >>sys.stderr, 'no --wrapper-version argument' + print('no --wrapper-version argument', file=sys.stderr) sys.exit(1) exp = _CurrentWrapperVersion() @@ -193,25 +191,25 @@ def _CheckWrapperVersion(ver, repo_path): exp_str = '.'.join(map(str, exp)) if exp[0] > ver[0] or ver < (0, 4): - print >>sys.stderr, """ + print(""" !!! A new repo command (%5s) is available. !!! !!! You must upgrade before you can continue: !!! cp %s %s -""" % (exp_str, _MyWrapperPath(), repo_path) +""" % (exp_str, _MyWrapperPath(), repo_path), file=sys.stderr) sys.exit(1) if exp > ver: - print >>sys.stderr, """ + print(""" ... A new repo command (%5s) is available. ... You should upgrade soon: cp %s %s -""" % (exp_str, _MyWrapperPath(), repo_path) +""" % (exp_str, _MyWrapperPath(), repo_path), file=sys.stderr) def _CheckRepoDir(repo_dir): if not repo_dir: - print >>sys.stderr, 'no --repo-dir argument' + print('no --repo-dir argument', file=sys.stderr) sys.exit(1) def _PruneOptions(argv, opt): @@ -281,7 +279,7 @@ def _AddPasswordFromUserInput(handler, msg, req): url = req.get_full_url() user, password = handler.passwd.find_user_password(None, url) if user is None: - print msg + print(msg) try: user = raw_input('User: ') password = getpass.getpass() @@ -388,10 +386,10 @@ def _Main(argv): finally: close_ssh() except KeyboardInterrupt: - print >>sys.stderr, 'aborted by user' + print('aborted by user', file=sys.stderr) result = 1 except ManifestParseError as mpe: - print >>sys.stderr, 'fatal: %s' % mpe + print('fatal: %s' % mpe, file=sys.stderr) result = 1 except RepoChangedException as rce: # If repo changed, re-exec ourselves. @@ -401,8 +399,8 @@ def _Main(argv): try: os.execv(__file__, argv) except OSError as e: - print >>sys.stderr, 'fatal: cannot restart repo after upgrade' - print >>sys.stderr, 'fatal: %s' % e + print('fatal: cannot restart repo after upgrade', file=sys.stderr) + print('fatal: %s' % e, file=sys.stderr) result = 128 sys.exit(result) -- cgit v1.2.3-54-g00ecf