Change print statements to work in python3

This is part of a series of changes to introduce Python3 support.

Change-Id: I373be5de7141aa127d7debdbce1df39148dbec32
This commit is contained in:
Sarah Owens
2012-11-01 22:59:27 -07:00
parent fc241240d8
commit cecd1d864f
30 changed files with 310 additions and 288 deletions

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import sys
from command import Command
from git_command import git
@ -36,7 +37,7 @@ It is equivalent to "git branch -D <branchname>".
nb = args[0]
if not git.check_ref_format('heads/%s' % nb):
print >>sys.stderr, "error: '%s' is not a valid name" % nb
print("error: '%s' is not a valid name" % nb, file=sys.stderr)
sys.exit(1)
nb = args[0]
@ -58,13 +59,13 @@ It is equivalent to "git branch -D <branchname>".
if err:
for p in err:
print >>sys.stderr,\
"error: %s/: cannot abandon %s" \
% (p.relpath, nb)
print("error: %s/: cannot abandon %s" % (p.relpath, nb),
file=sys.stderr)
sys.exit(1)
elif not success:
print >>sys.stderr, 'error: no project has branch %s' % nb
print('error: no project has branch %s' % nb, file=sys.stderr)
sys.exit(1)
else:
print >>sys.stderr, 'Abandoned in %d project(s):\n %s' % (
len(success), '\n '.join(p.relpath for p in success))
print('Abandoned in %d project(s):\n %s'
% (len(success), '\n '.join(p.relpath for p in success)),
file=sys.stderr)

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import sys
from color import Coloring
from command import Command
@ -107,7 +108,7 @@ is shown, then the branch appears in all projects.
names.sort()
if not names:
print >>sys.stderr, ' (no branches)'
print(' (no branches)', file=sys.stderr)
return
width = 25

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import sys
from command import Command
from progress import Progress
@ -55,10 +56,9 @@ The command is equivalent to:
if err:
for p in err:
print >>sys.stderr,\
"error: %s/: cannot checkout %s" \
% (p.relpath, nb)
print("error: %s/: cannot checkout %s" % (p.relpath, nb),
file=sys.stderr)
sys.exit(1)
elif not success:
print >>sys.stderr, 'error: no project has branch %s' % nb
print('error: no project has branch %s' % nb, file=sys.stderr)
sys.exit(1)

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import re
import sys
from command import Command
@ -46,13 +47,13 @@ change id will be added.
capture_stdout = True,
capture_stderr = True)
if p.Wait() != 0:
print >>sys.stderr, p.stderr
print(p.stderr, file=sys.stderr)
sys.exit(1)
sha1 = p.stdout.strip()
p = GitCommand(None, ['cat-file', 'commit', sha1], capture_stdout=True)
if p.Wait() != 0:
print >>sys.stderr, "error: Failed to retrieve old commit message"
print("error: Failed to retrieve old commit message", file=sys.stderr)
sys.exit(1)
old_msg = self._StripHeader(p.stdout)
@ -62,8 +63,8 @@ change id will be added.
capture_stderr = True)
status = p.Wait()
print >>sys.stdout, p.stdout
print >>sys.stderr, p.stderr
print(p.stdout, file=sys.stdout)
print(p.stderr, file=sys.stderr)
if status == 0:
# The cherry-pick was applied correctly. We just need to edit the
@ -76,16 +77,14 @@ change id will be added.
capture_stderr = True)
p.stdin.write(new_msg)
if p.Wait() != 0:
print >>sys.stderr, "error: Failed to update commit message"
print("error: Failed to update commit message", file=sys.stderr)
sys.exit(1)
else:
print >>sys.stderr, """\
NOTE: When committing (please see above) and editing the commit message,
please remove the old Change-Id-line and add:
"""
print >>sys.stderr, self._GetReference(sha1)
print >>sys.stderr
print('NOTE: When committing (please see above) and editing the commit'
'message, please remove the old Change-Id-line and add:')
print(self._GetReference(sha1), file=stderr)
print(file=stderr)
def _IsChangeId(self, line):
return CHANGE_ID_RE.match(line)

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import re
import sys
@ -68,23 +69,23 @@ makes it available in your project's local working directory.
for project, change_id, ps_id in self._ParseChangeIds(args):
dl = project.DownloadPatchSet(change_id, ps_id)
if not dl:
print >>sys.stderr, \
'[%s] change %d/%d not found' \
% (project.name, change_id, ps_id)
print('[%s] change %d/%d not found'
% (project.name, change_id, ps_id),
file=sys.stderr)
sys.exit(1)
if not opt.revert and not dl.commits:
print >>sys.stderr, \
'[%s] change %d/%d has already been merged' \
% (project.name, change_id, ps_id)
print('[%s] change %d/%d has already been merged'
% (project.name, change_id, ps_id),
file=sys.stderr)
continue
if len(dl.commits) > 1:
print >>sys.stderr, \
'[%s] %d/%d depends on %d unmerged changes:' \
% (project.name, change_id, ps_id, len(dl.commits))
print('[%s] %d/%d depends on %d unmerged changes:' \
% (project.name, change_id, ps_id, len(dl.commits)),
file=sys.stderr)
for c in dl.commits:
print >>sys.stderr, ' %s' % (c)
print(' %s' % (c), file=sys.stderr)
if opt.cherrypick:
project._CherryPick(dl.commit)
elif opt.revert:

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import fcntl
import re
import os
@ -183,7 +184,7 @@ terminal and are not redirected.
if not os.path.exists(cwd):
if (opt.project_header and opt.verbose) \
or not opt.project_header:
print >>sys.stderr, 'skipping %s/' % project.relpath
print('skipping %s/' % project.relpath, file=sys.stderr)
continue
if opt.project_header:

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import sys
from color import Coloring
from command import PagedCommand
@ -178,8 +179,7 @@ contain a line that matches both expressions:
have_rev = False
if opt.revision:
if '--cached' in cmd_argv:
print >>sys.stderr,\
'fatal: cannot combine --cached and --revision'
print('fatal: cannot combine --cached and --revision', file=sys.stderr)
sys.exit(1)
have_rev = True
cmd_argv.extend(opt.revision)
@ -230,13 +230,13 @@ contain a line that matches both expressions:
out.nl()
else:
for line in r:
print line
print(line)
if have_match:
sys.exit(0)
elif have_rev and bad_rev:
for r in opt.revision:
print >>sys.stderr, "error: can't search revision %s" % r
print("error: can't search revision %s" % r, file=sys.stderr)
sys.exit(1)
else:
sys.exit(1)

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import re
import sys
from formatter import AbstractFormatter, DumbWriter
@ -31,10 +32,8 @@ Displays detailed usage information about a command.
"""
def _PrintAllCommands(self):
print 'usage: repo COMMAND [ARGS]'
print """
The complete list of recognized repo commands are:
"""
print('usage: repo COMMAND [ARGS]')
print('The complete list of recognized repo commands are:')
commandNames = self.commands.keys()
commandNames.sort()
@ -49,17 +48,14 @@ The complete list of recognized repo commands are:
summary = command.helpSummary.strip()
except AttributeError:
summary = ''
print fmt % (name, summary)
print """
See 'repo help <command>' for more information on a specific command.
"""
print(fmt % (name, summary))
print("See 'repo help <command>' for more information on a"
'specific command.')
def _PrintCommonCommands(self):
print 'usage: repo COMMAND [ARGS]'
print """
The most commonly used repo commands are:
"""
commandNames = [name
print('usage: repo COMMAND [ARGS]')
print('The most commonly used repo commands are:')
commandNames = [name
for name in self.commands.keys()
if self.commands[name].common]
commandNames.sort()
@ -75,11 +71,10 @@ The most commonly used repo commands are:
summary = command.helpSummary.strip()
except AttributeError:
summary = ''
print fmt % (name, summary)
print """
See 'repo help <command>' for more information on a specific command.
See 'repo help --all' for a complete list of recognized commands.
"""
print(fmt % (name, summary))
print(
"See 'repo help <command>' for more information on a specific command.\n"
"See 'repo help --all' for a complete list of recognized commands.")
def _PrintCommandHelp(self, cmd):
class _Out(Coloring):
@ -162,7 +157,7 @@ See 'repo help --all' for a complete list of recognized commands.
try:
cmd = self.commands[name]
except KeyError:
print >>sys.stderr, "repo: '%s' is not a repo command." % name
print("repo: '%s' is not a repo command." % name, file=sys.stderr)
sys.exit(1)
cmd.manifest = self.manifest

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import os
import platform
import re
@ -123,12 +124,12 @@ to update the working directory files.
if is_new:
if not opt.manifest_url:
print >>sys.stderr, 'fatal: manifest url (-u) is required.'
print('fatal: manifest url (-u) is required.', file=sys.stderr)
sys.exit(1)
if not opt.quiet:
print >>sys.stderr, 'Get %s' \
% GitConfig.ForUser().UrlInsteadOf(opt.manifest_url)
print('Get %s' % GitConfig.ForUser().UrlInsteadOf(opt.manifest_url),
file=sys.stderr)
m._InitGitDir()
if opt.manifest_branch:
@ -159,7 +160,7 @@ to update the working directory files.
elif opt.platform in all_platforms:
groups.extend(platformize(opt.platform))
elif opt.platform != 'none':
print >>sys.stderr, 'fatal: invalid platform flag'
print('fatal: invalid platform flag', file=sys.stderr)
sys.exit(1)
groups = [x for x in groups if x]
@ -175,12 +176,13 @@ to update the working directory files.
if is_new:
m.config.SetString('repo.mirror', 'true')
else:
print >>sys.stderr, 'fatal: --mirror not supported on existing client'
print('fatal: --mirror not supported on existing client',
file=sys.stderr)
sys.exit(1)
if not m.Sync_NetworkHalf(is_new=is_new):
r = m.GetRemote(m.remote.name)
print >>sys.stderr, 'fatal: cannot obtain manifest %s' % r.url
print('fatal: cannot obtain manifest %s' % r.url, file=sys.stderr)
# Better delete the manifest git dir if we created it; otherwise next
# time (when user fixes problems) we won't go through the "is_new" logic.
@ -197,19 +199,19 @@ to update the working directory files.
if is_new or m.CurrentBranch is None:
if not m.StartBranch('default'):
print >>sys.stderr, 'fatal: cannot create default in manifest'
print('fatal: cannot create default in manifest', file=sys.stderr)
sys.exit(1)
def _LinkManifest(self, name):
if not name:
print >>sys.stderr, 'fatal: manifest name (-m) is required.'
print('fatal: manifest name (-m) is required.', file=sys.stderr)
sys.exit(1)
try:
self.manifest.Link(name)
except ManifestParseError as e:
print >>sys.stderr, "fatal: manifest '%s' not available" % name
print >>sys.stderr, 'fatal: %s' % str(e)
print("fatal: manifest '%s' not available" % name, file=sys.stderr)
print('fatal: %s' % str(e), file=sys.stderr)
sys.exit(1)
def _Prompt(self, prompt, value):
@ -231,22 +233,22 @@ to update the working directory files.
mp.config.SetString('user.name', gc.GetString('user.name'))
mp.config.SetString('user.email', gc.GetString('user.email'))
print ''
print 'Your identity is: %s <%s>' % (mp.config.GetString('user.name'),
mp.config.GetString('user.email'))
print 'If you want to change this, please re-run \'repo init\' with --config-name'
print()
print('Your identity is: %s <%s>' % (mp.config.GetString('user.name'),
mp.config.GetString('user.email')))
print('If you want to change this, please re-run \'repo init\' with --config-name')
return False
def _ConfigureUser(self):
mp = self.manifest.manifestProject
while True:
print ''
print()
name = self._Prompt('Your Name', mp.UserName)
email = self._Prompt('Your Email', mp.UserEmail)
print ''
print 'Your identity is: %s <%s>' % (name, email)
print()
print('Your identity is: %s <%s>' % (name, email))
sys.stdout.write('is this correct [y/N]? ')
a = sys.stdin.readline().strip().lower()
if a in ('yes', 'y', 't', 'true'):
@ -274,8 +276,8 @@ to update the working directory files.
self._on = True
out = _Test()
print ''
print "Testing colorized output (for 'repo diff', 'repo status'):"
print()
print("Testing colorized output (for 'repo diff', 'repo status'):")
for c in ['black','red','green','yellow','blue','magenta','cyan']:
out.write(' ')
@ -319,14 +321,16 @@ to update the working directory files.
else:
init_type = ''
print ''
print 'repo %shas been initialized in %s' % (init_type, self.manifest.topdir)
print()
print('repo %shas been initialized in %s'
% (init_type, self.manifest.topdir))
current_dir = os.getcwd()
if current_dir != self.manifest.topdir:
print 'If this is not the directory in which you want to initialize repo, please run:'
print ' rm -r %s/.repo' % self.manifest.topdir
print 'and try again.'
print('If this is not the directory in which you want to initialize'
'repo, please run:')
print(' rm -r %s/.repo' % self.manifest.topdir)
print('and try again.')
def Execute(self, opt, args):
git_require(MIN_GIT_VERSION, fail=True)

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import re
from command import Command, MirrorSafeCommand
@ -64,7 +65,7 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
lines.append("%s : %s" % (_getpath(project), project.name))
lines.sort()
print '\n'.join(lines)
print('\n'.join(lines))
def FindProjects(self, args):
result = []

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import os
import sys
@ -69,7 +70,7 @@ in a Git repository for use during future 'repo init' invocations.
peg_rev_upstream = opt.peg_rev_upstream)
fd.close()
if opt.output_file != '-':
print >>sys.stderr, 'Saved manifest to %s' % opt.output_file
print('Saved manifest to %s' % opt.output_file, file=sys.stderr)
def Execute(self, opt, args):
if args:
@ -79,6 +80,6 @@ in a Git repository for use during future 'repo init' invocations.
self._Output(opt)
return
print >>sys.stderr, 'error: no operation to perform'
print >>sys.stderr, 'error: see repo help manifest'
print('error: no operation to perform', file=sys.stderr)
print('error: see repo help manifest', file=sys.stderr)
sys.exit(1)

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
from color import Coloring
from command import PagedCommand
@ -70,11 +71,11 @@ are displayed.
commits = branch.commits
date = branch.date
print '%s %-33s (%2d commit%s, %s)' % (
print('%s %-33s (%2d commit%s, %s)' % (
branch.name == project.CurrentBranch and '*' or ' ',
branch.name,
len(commits),
len(commits) != 1 and 's' or ' ',
date)
date))
for commit in commits:
print '%-35s - %s' % ('', commit)
print('%-35s - %s' % ('', commit))

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
from color import Coloring
from command import PagedCommand
@ -51,9 +52,9 @@ class Prune(PagedCommand):
commits = branch.commits
date = branch.date
print '%s %-33s (%2d commit%s, %s)' % (
print('%s %-33s (%2d commit%s, %s)' % (
branch.name == project.CurrentBranch and '*' or ' ',
branch.name,
len(commits),
len(commits) != 1 and 's' or ' ',
date)
date))

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import sys
from command import Command
@ -59,14 +60,16 @@ branch but need to incorporate new upstream changes "underneath" them.
one_project = len(all_projects) == 1
if opt.interactive and not one_project:
print >>sys.stderr, 'error: interactive rebase not supported with multiple projects'
print('error: interactive rebase not supported with multiple projects',
file=sys.stderr)
return -1
for project in all_projects:
cb = project.CurrentBranch
if not cb:
if one_project:
print >>sys.stderr, "error: project %s has a detatched HEAD" % project.relpath
print("error: project %s has a detatched HEAD" % project.relpath,
file=sys.stderr)
return -1
# ignore branches with detatched HEADs
continue
@ -74,7 +77,8 @@ branch but need to incorporate new upstream changes "underneath" them.
upbranch = project.GetBranch(cb)
if not upbranch.LocalMerge:
if one_project:
print >>sys.stderr, "error: project %s does not track any remote branches" % project.relpath
print("error: project %s does not track any remote branches"
% project.relpath, file=sys.stderr)
return -1
# ignore branches without remotes
continue
@ -101,8 +105,8 @@ branch but need to incorporate new upstream changes "underneath" them.
args.append(upbranch.LocalMerge)
print >>sys.stderr, '# %s: rebasing %s -> %s' % \
(project.relpath, cb, upbranch.LocalMerge)
print('# %s: rebasing %s -> %s'
% (project.relpath, cb, upbranch.LocalMerge), file=sys.stderr)
needs_stash = False
if opt.auto_stash:

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
from optparse import SUPPRESS_HELP
import sys
@ -52,7 +53,7 @@ need to be performed by an end-user.
else:
if not rp.Sync_NetworkHalf():
print >>sys.stderr, "error: can't update repo"
print("error: can't update repo", file=sys.stderr)
sys.exit(1)
rp.bare_git.gc('--auto')

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import sys
from color import Coloring
@ -50,7 +51,7 @@ The '%prog' command stages files to prepare the next commit.
def _Interactive(self, opt, args):
all_projects = filter(lambda x: x.IsDirty(), self.GetProjects(args))
if not all_projects:
print >>sys.stderr,'no projects have uncommitted modifications'
print('no projects have uncommitted modifications', file=sys.stderr)
return
out = _ProjectList(self.manifest.manifestProject.config)
@ -101,7 +102,7 @@ The '%prog' command stages files to prepare the next commit.
if len(p) == 1:
_AddI(p[0])
continue
print 'Bye.'
print('Bye.')
def _AddI(project):
p = GitCommand(project, ['add', '--interactive'], bare=False)

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import sys
from command import Command
from git_config import IsId
@ -41,7 +42,7 @@ revision specified in the manifest.
nb = args[0]
if not git.check_ref_format('heads/%s' % nb):
print >>sys.stderr, "error: '%s' is not a valid name" % nb
print("error: '%s' is not a valid name" % nb, file=sys.stderr)
sys.exit(1)
err = []
@ -49,7 +50,7 @@ revision specified in the manifest.
if not opt.all:
projects = args[1:]
if len(projects) < 1:
print >>sys.stderr, "error: at least one project must be specified"
print("error: at least one project must be specified", file=sys.stderr)
sys.exit(1)
all_projects = self.GetProjects(projects)
@ -67,7 +68,6 @@ revision specified in the manifest.
if err:
for p in err:
print >>sys.stderr,\
"error: %s/: cannot start %s" \
% (p.relpath, nb)
print("error: %s/: cannot start %s" % (p.relpath, nb),
file=sys.stderr)
sys.exit(1)

View File

@ -129,4 +129,4 @@ the following meanings:
output.dump(sys.stdout)
output.close()
if len(all_projects) == counter.next():
print 'nothing to commit (working directory clean)'
print('nothing to commit (working directory clean)')

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import netrc
from optparse import SUPPRESS_HELP
import os
@ -234,9 +235,10 @@ later is required to fix a server side protocol bug.
did_lock = True
if not success:
print >>sys.stderr, 'error: Cannot fetch %s' % project.name
print('error: Cannot fetch %s' % project.name, file=sys.stderr)
if opt.force_broken:
print >>sys.stderr, 'warn: --force-broken, continuing to sync'
print('warn: --force-broken, continuing to sync',
file=sys.stderr)
else:
raise _FetchError()
@ -265,9 +267,9 @@ later is required to fix a server side protocol bug.
clone_bundle=not opt.no_clone_bundle):
fetched.add(project.gitdir)
else:
print >>sys.stderr, 'error: Cannot fetch %s' % project.name
print('error: Cannot fetch %s' % project.name, file=sys.stderr)
if opt.force_broken:
print >>sys.stderr, 'warn: --force-broken, continuing to sync'
print('warn: --force-broken, continuing to sync', file=sys.stderr)
else:
sys.exit(1)
else:
@ -300,7 +302,7 @@ later is required to fix a server side protocol bug.
# If we saw an error, exit with code 1 so that other scripts can check.
if err_event.isSet():
print >>sys.stderr, '\nerror: Exited sync due to fetch errors'
print('\nerror: Exited sync due to fetch errors', file=sys.stderr)
sys.exit(1)
pm.end()
@ -353,7 +355,7 @@ later is required to fix a server side protocol bug.
t.join()
if err_event.isSet():
print >>sys.stderr, '\nerror: Exited sync due to gc errors'
print('\nerror: Exited sync due to gc errors', file=sys.stderr)
sys.exit(1)
def UpdateProjectList(self):
@ -390,12 +392,14 @@ later is required to fix a server side protocol bug.
groups = None)
if project.IsDirty():
print >>sys.stderr, 'error: Cannot remove project "%s": \
uncommitted changes are present' % project.relpath
print >>sys.stderr, ' commit changes, then run sync again'
print('error: Cannot remove project "%s": uncommitted changes'
'are present' % project.relpath, file=sys.stderr)
print(' commit changes, then run sync again',
file=sys.stderr)
return -1
else:
print >>sys.stderr, 'Deleting obsolete path %s' % project.worktree
print('Deleting obsolete path %s' % project.worktree,
file=sys.stderr)
shutil.rmtree(project.worktree)
# Try deleting parent subdirs if they are empty
project_dir = os.path.dirname(project.worktree)
@ -423,24 +427,24 @@ uncommitted changes are present' % project.relpath
self.jobs = min(self.jobs, (soft_limit - 5) / 3)
if opt.network_only and opt.detach_head:
print >>sys.stderr, 'error: cannot combine -n and -d'
print('error: cannot combine -n and -d', file=sys.stderr)
sys.exit(1)
if opt.network_only and opt.local_only:
print >>sys.stderr, 'error: cannot combine -n and -l'
print('error: cannot combine -n and -l', file=sys.stderr)
sys.exit(1)
if opt.manifest_name and opt.smart_sync:
print >>sys.stderr, 'error: cannot combine -m and -s'
print('error: cannot combine -m and -s', file=sys.stderr)
sys.exit(1)
if opt.manifest_name and opt.smart_tag:
print >>sys.stderr, 'error: cannot combine -m and -t'
print('error: cannot combine -m and -t', file=sys.stderr)
sys.exit(1)
if opt.manifest_server_username or opt.manifest_server_password:
if not (opt.smart_sync or opt.smart_tag):
print >>sys.stderr, 'error: -u and -p may only be combined with ' \
'-s or -t'
print('error: -u and -p may only be combined with -s or -t',
file=sys.stderr)
sys.exit(1)
if None in [opt.manifest_server_username, opt.manifest_server_password]:
print >>sys.stderr, 'error: both -u and -p must be given'
print('error: both -u and -p must be given', file=sys.stderr)
sys.exit(1)
if opt.manifest_name:
@ -448,8 +452,8 @@ uncommitted changes are present' % project.relpath
if opt.smart_sync or opt.smart_tag:
if not self.manifest.manifest_server:
print >>sys.stderr, \
'error: cannot smart sync: no manifest server defined in manifest'
print('error: cannot smart sync: no manifest server defined in'
'manifest', file=sys.stderr)
sys.exit(1)
manifest_server = self.manifest.manifest_server
@ -464,7 +468,8 @@ uncommitted changes are present' % project.relpath
try:
info = netrc.netrc()
except IOError:
print >>sys.stderr, '.netrc file does not exist or could not be opened'
print('.netrc file does not exist or could not be opened',
file=sys.stderr)
else:
try:
parse_result = urlparse.urlparse(manifest_server)
@ -474,10 +479,10 @@ uncommitted changes are present' % project.relpath
except TypeError:
# TypeError is raised when the given hostname is not present
# in the .netrc file.
print >>sys.stderr, 'No credentials found for %s in .netrc' % \
parse_result.hostname
print('No credentials found for %s in .netrc'
% parse_result.hostname, file=sys.stderr)
except netrc.NetrcParseError as e:
print >>sys.stderr, 'Error parsing .netrc file: %s' % e
print('Error parsing .netrc file: %s' % e, file=sys.stderr)
if (username and password):
manifest_server = manifest_server.replace('://', '://%s:%s@' %
@ -516,20 +521,21 @@ uncommitted changes are present' % project.relpath
finally:
f.close()
except IOError:
print >>sys.stderr, 'error: cannot write manifest to %s' % \
manifest_path
print('error: cannot write manifest to %s' % manifest_path,
file=sys.stderr)
sys.exit(1)
self.manifest.Override(manifest_name)
else:
print >>sys.stderr, 'error: %s' % manifest_str
print('error: %s' % manifest_str, file=sys.stderr)
sys.exit(1)
except (socket.error, IOError, xmlrpclib.Fault) as e:
print >>sys.stderr, 'error: cannot connect to manifest server %s:\n%s' % (
self.manifest.manifest_server, e)
print('error: cannot connect to manifest server %s:\n%s'
% (self.manifest.manifest_server, e), file=sys.stderr)
sys.exit(1)
except xmlrpclib.ProtocolError as e:
print >>sys.stderr, 'error: cannot connect to manifest server %s:\n%d %s' % (
self.manifest.manifest_server, e.errcode, e.errmsg)
print('error: cannot connect to manifest server %s:\n%d %s'
% (self.manifest.manifest_server, e.errcode, e.errmsg),
file=sys.stderr)
sys.exit(1)
rp = self.manifest.repoProject
@ -585,14 +591,14 @@ uncommitted changes are present' % project.relpath
if project.worktree:
project.Sync_LocalHalf(syncbuf)
pm.end()
print >>sys.stderr
print(file=sys.stderr)
if not syncbuf.Finish():
sys.exit(1)
# If there's a notice that's supposed to print at the end of the sync, print
# it now...
if self.manifest.notice:
print self.manifest.notice
print(self.manifest.notice)
def _PostRepoUpgrade(manifest, quiet=False):
wrapper = WrapperModule()
@ -604,27 +610,28 @@ def _PostRepoUpgrade(manifest, quiet=False):
def _PostRepoFetch(rp, no_repo_verify=False, verbose=False):
if rp.HasChanges:
print >>sys.stderr, 'info: A new version of repo is available'
print >>sys.stderr, ''
print('info: A new version of repo is available', file=sys.stderr)
print(file=sys.stderr)
if no_repo_verify or _VerifyTag(rp):
syncbuf = SyncBuffer(rp.config)
rp.Sync_LocalHalf(syncbuf)
if not syncbuf.Finish():
sys.exit(1)
print >>sys.stderr, 'info: Restarting repo with latest version'
print('info: Restarting repo with latest version', file=sys.stderr)
raise RepoChangedException(['--repo-upgraded'])
else:
print >>sys.stderr, 'warning: Skipped upgrade to unverified version'
print('warning: Skipped upgrade to unverified version', file=sys.stderr)
else:
if verbose:
print >>sys.stderr, 'repo version %s is current' % rp.work_git.describe(HEAD)
print('repo version %s is current' % rp.work_git.describe(HEAD),
file=sys.stderr)
def _VerifyTag(project):
gpg_dir = os.path.expanduser('~/.repoconfig/gnupg')
if not os.path.exists(gpg_dir):
print >>sys.stderr,\
"""warning: GnuPG was not available during last "repo init"
warning: Cannot automatically authenticate repo."""
print('warning: GnuPG was not available during last "repo init"\n'
'warning: Cannot automatically authenticate repo."""',
file=sys.stderr)
return True
try:
@ -638,10 +645,9 @@ warning: Cannot automatically authenticate repo."""
if rev.startswith(R_HEADS):
rev = rev[len(R_HEADS):]
print >>sys.stderr
print >>sys.stderr,\
"warning: project '%s' branch '%s' is not signed" \
% (project.name, rev)
print(file=sys.stderr)
print("warning: project '%s' branch '%s' is not signed"
% (project.name, rev), file=sys.stderr)
return False
env = os.environ.copy()
@ -660,10 +666,10 @@ warning: Cannot automatically authenticate repo."""
proc.stderr.close()
if proc.wait() != 0:
print >>sys.stderr
print >>sys.stderr, out
print >>sys.stderr, err
print >>sys.stderr
print(file=sys.stderr)
print(out, file=sys.stderr)
print(err, file=sys.stderr)
print(file=sys.stderr)
return False
return True

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import copy
import re
import sys
@ -26,16 +27,18 @@ UNUSUAL_COMMIT_THRESHOLD = 5
def _ConfirmManyUploads(multiple_branches=False):
if multiple_branches:
print "ATTENTION: One or more branches has an unusually high number of commits."
print('ATTENTION: One or more branches has an unusually high number'
'of commits.')
else:
print "ATTENTION: You are uploading an unusually high number of commits."
print "YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across branches?)"
print('ATTENTION: You are uploading an unusually high number of commits.')
print('YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across'
'branches?)')
answer = raw_input("If you are sure you intend to do this, type 'yes': ").strip()
return answer == "yes"
def _die(fmt, *args):
msg = fmt % args
print >>sys.stderr, 'error: %s' % msg
print('error: %s' % msg, file=sys.stderr)
sys.exit(1)
def _SplitEmails(values):
@ -176,14 +179,14 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
date = branch.date
commit_list = branch.commits
print 'Upload project %s/ to remote branch %s:' % (project.relpath, project.revisionExpr)
print ' branch %s (%2d commit%s, %s):' % (
print('Upload project %s/ to remote branch %s:' % (project.relpath, project.revisionExpr))
print(' branch %s (%2d commit%s, %s):' % (
name,
len(commit_list),
len(commit_list) != 1 and 's' or '',
date)
date))
for commit in commit_list:
print ' %s' % commit
print(' %s' % commit)
sys.stdout.write('to %s (y/N)? ' % remote.review)
answer = sys.stdin.readline().strip().lower()
@ -317,7 +320,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
sys.stdout.write('Uncommitted changes in ' + branch.project.name + ' (did you forget to amend?). Continue uploading? (y/N) ')
a = sys.stdin.readline().strip().lower()
if a not in ('y', 'yes', 't', 'true', 'on'):
print >>sys.stderr, "skipping upload"
print("skipping upload", file=sys.stderr)
branch.uploaded = False
branch.error = 'User aborted'
continue
@ -334,8 +337,8 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
branch.uploaded = False
have_errors = True
print >>sys.stderr, ''
print >>sys.stderr, '----------------------------------------------------------------------'
print(file=sys.stderr)
print('----------------------------------------------------------------------', file=sys.stderr)
if have_errors:
for branch in todo:
@ -344,17 +347,19 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
fmt = ' (%s)'
else:
fmt = '\n (%s)'
print >>sys.stderr, ('[FAILED] %-15s %-15s' + fmt) % (
print(('[FAILED] %-15s %-15s' + fmt) % (
branch.project.relpath + '/', \
branch.name, \
str(branch.error))
print >>sys.stderr, ''
str(branch.error)),
file=sys.stderr)
print()
for branch in todo:
if branch.uploaded:
print >>sys.stderr, '[OK ] %-15s %s' % (
print('[OK ] %-15s %s' % (
branch.project.relpath + '/',
branch.name)
branch.name),
file=sys.stderr)
if have_errors:
sys.exit(1)
@ -385,7 +390,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
try:
hook.Run(opt.allow_all_hooks, project_list=pending_proj_names)
except HookError as e:
print >>sys.stderr, "ERROR: %s" % str(e)
print("ERROR: %s" % str(e), file=sys.stderr)
return
if opt.reviewers:
@ -395,7 +400,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
people = (reviewers,cc)
if not pending:
print >>sys.stdout, "no branches ready for upload"
print("no branches ready for upload", file=sys.stderr)
elif len(pending) == 1 and len(pending[0][1]) == 1:
self._SingleBranch(opt, pending[0][1][0], people)
else:

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import sys
from command import Command, MirrorSafeCommand
from git_command import git
@ -32,12 +33,12 @@ class Version(Command, MirrorSafeCommand):
rp = self.manifest.repoProject
rem = rp.GetRemote(rp.remote.name)
print 'repo version %s' % rp.work_git.describe(HEAD)
print ' (from %s)' % rem.url
print('repo version %s' % rp.work_git.describe(HEAD))
print(' (from %s)' % rem.url)
if Version.wrapper_path is not None:
print 'repo launcher version %s' % Version.wrapper_version
print ' (from %s)' % Version.wrapper_path
print('repo launcher version %s' % Version.wrapper_version)
print(' (from %s)' % Version.wrapper_path)
print git.version().strip()
print 'Python %s' % sys.version
print(git.version().strip())
print('Python %s' % sys.version)