Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Work towards Python 3 compatibility. Since we already require Python …
Browse files Browse the repository at this point in the history
…2.7+,

we can use the new syntax without further limiting our Python 2 support.

* contrib/client-side/incremental-update.py
* contrib/client-side/svn_export_empty_files.py
* contrib/client-side/svnmerge/svnmerge.py
* contrib/hook-scripts/hook_toolbox.py
* contrib/hook-scripts/remove-zombie-locks.py
* contrib/server-side/add-needs-lock.py
* contrib/server-side/fsfsfixer/fixer/find_good_id.py
* contrib/server-side/fsfsfixer/fixer/fix-rev.py
* contrib/server-side/fsfsverify.py
* contrib/server-side/svn-tweak-author.py
* notes/directory-index/dirindex.py
* notes/move-tracking/path_pairs_to_eid_map.py
* subversion/tests/cmdline/svntest/main.py
* subversion/tests/cmdline/svntest/verify.py
* subversion/tests/manual/tree-conflicts-add-vs-add.py
* tools/client-side/mergeinfo-sanitizer.py
* tools/dev/benchmarks/RepoPerf/copy_repo.py
* tools/dev/benchmarks/suite1/benchmark.py
* tools/dev/gen-py-errors.py
* tools/dev/histogram.py
* tools/dev/sbox-ospath.py
* tools/dev/wc-format.py
* tools/dev/wc-ng/bump-to-19.py
* tools/dist/collect_sigs.py
* tools/examples/get-location-segments.py
* tools/server-side/svnpredumpfilter.py
* tools/server-side/svnpubsub/irkerbridge.py
* tools/server-side/svnpubsub/svntweet.py
  (): Replace occurances of Python 2 print statements with calls to the
      Python 3 style print function.  Note that this is not exhaustive
      and there are still several non-trival uses of print statements
      not covered by this patch.


git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1741732 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Stefan Fuhrmann committed Apr 30, 2016
1 parent 90662b5 commit 3f23c78
Show file tree
Hide file tree
Showing 28 changed files with 212 additions and 212 deletions.
10 changes: 5 additions & 5 deletions contrib/client-side/incremental-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ def main():
args = ' '.join(sys.argv[1:-1] + ['--non-interactive'])
print "Fetch HEAD revision...",
head_revision = get_head_revision(path, args)
print "done."
print "Updating to revision %d" % (head_revision)
print("done.")
print("Updating to revision %d" % (head_revision))
print "Harvesting the list of subdirectories...",
dirs = harvest_dirs(path)
print "done."
print("done.")
dirs.sort(compare_paths)
dirs.reverse()
print "Update the tree, one subdirectory at a time. This could take " \
"a while."
print("Update the tree, one subdirectory at a time. This could take " \
"a while.")
num_dirs = len(dirs)
width = len(str(num_dirs))
format_string = '[%%%dd/%%%dd] Updating %%s' % (width, width)
Expand Down
52 changes: 26 additions & 26 deletions contrib/client-side/svn_export_empty_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def check_url_for_export(ctx, url, revision, client_ctx):
# is something wrong with the given URL.
try:
if ctx.verbose:
print "Trying to list '%s'" % url
print("Trying to list '%s'" % url)
svn.client.ls(url, revision, 0, client_ctx)

# Given a URL, the ls command does not tell you if
Expand All @@ -82,39 +82,39 @@ def check_url_for_export(ctx, url, revision, client_ctx):
try:
last_slash_index = url.rindex('/')
except ValueError:
print "Cannot find a / in the URL '%s'" % url
print("Cannot find a / in the URL '%s'" % url)
return False

parent_url = url[:last_slash_index]
path_name = url[last_slash_index+1:]

try:
if ctx.verbose:
print "Trying to list '%s'" % parent_url
print("Trying to list '%s'" % parent_url)
remote_ls = svn.client.ls(parent_url,
revision,
0,
client_ctx)
except svn.core.SubversionException:
if ctx.verbose:
print "Listing of '%s' failed, assuming URL is top of repos" \
% parent_url
print("Listing of '%s' failed, assuming URL is top of repos" \
% parent_url)
return True

try:
path_info = remote_ls[path_name]
except ValueError:
print "Able to ls '%s' but '%s' not in ls of '%s'" \
% (url, path_name, parent_url)
print("Able to ls '%s' but '%s' not in ls of '%s'" \
% (url, path_name, parent_url))
return False

if svn.core.svn_node_dir != path_info.kind:
if ctx.verbose:
print "The URL '%s' is not a directory" % url
print("The URL '%s' is not a directory" % url)
return False
else:
if ctx.verbose:
print "The URL '%s' is a directory" % url
print("The URL '%s' is a directory" % url)
return True
finally:
pass
Expand Down Expand Up @@ -154,16 +154,16 @@ def synchronize_dir(ctx, url, dir_name, revision, client_ctx):
msg = ("'%s' which is a local non-directory but remotely a " +
"directory") % dir_name
if ctx.delete_local_paths:
print "Removing", msg
print("Removing", msg)
os.unlink(dir_name)
local_path_kind = LOCAL_PATH_NONE
else:
print "Need to remove", msg
print("Need to remove", msg)
ctx.delete_needed = True
return False

if LOCAL_PATH_NONE == local_path_kind:
print "Creating directory '%s'" % dir_name
print("Creating directory '%s'" % dir_name)
os.mkdir(dir_name)

remote_ls = svn.client.ls(url,
Expand All @@ -172,7 +172,7 @@ def synchronize_dir(ctx, url, dir_name, revision, client_ctx):
client_ctx)

if ctx.verbose:
print "Syncing '%s' to '%s'" % (url, dir_name)
print("Syncing '%s' to '%s'" % (url, dir_name))

remote_pathnames = remote_ls.keys()
remote_pathnames.sort()
Expand All @@ -191,7 +191,7 @@ def synchronize_dir(ctx, url, dir_name, revision, client_ctx):

if remote_pathname in ctx.ignore_names or \
full_remote_pathname in ctx.ignore_paths:
print "Skipping '%s'" % full_remote_pathname
print("Skipping '%s'" % full_remote_pathname)
continue

# Get the remote path kind.
Expand Down Expand Up @@ -221,16 +221,16 @@ def synchronize_dir(ctx, url, dir_name, revision, client_ctx):
msg = ("'%s' which is a local directory but remotely a " +
"non-directory") % full_remote_pathname
if ctx.delete_local_paths:
print "Removing", msg
print("Removing", msg)
recursive_delete(full_remote_pathname)
local_path_kind = LOCAL_PATH_NONE
else:
print "Need to remove", msg
print("Need to remove", msg)
ctx.delete_needed = True
continue

if LOCAL_PATH_NONE == local_path_kind:
print "Creating file '%s'" % full_remote_pathname
print("Creating file '%s'" % full_remote_pathname)
f = file(full_remote_pathname, 'w')
f.close()

Expand All @@ -240,17 +240,17 @@ def synchronize_dir(ctx, url, dir_name, revision, client_ctx):
full_local_pathname = os.path.join(dir_name, local_pathname)
if os.path.isdir(full_local_pathname):
if ctx.delete_local_paths:
print "Removing directory '%s'" % full_local_pathname
print("Removing directory '%s'" % full_local_pathname)
recursive_delete(full_local_pathname)
else:
print "Need to remove directory '%s'" % full_local_pathname
print("Need to remove directory '%s'" % full_local_pathname)
ctx.delete_needed = True
else:
if ctx.delete_local_paths:
print "Removing file '%s'" % full_local_pathname
print("Removing file '%s'" % full_local_pathname)
os.unlink(full_local_pathname)
else:
print "Need to remove file '%s'" % full_local_pathname
print("Need to remove file '%s'" % full_local_pathname)
ctx.delete_needed = True

return status
Expand Down Expand Up @@ -293,14 +293,14 @@ def main(ctx, url, export_pathname):
client_ctx)

if ctx.delete_needed:
print "There are files and directories in the local filesystem"
print "that do not exist in the Subversion repository that were"
print("There are files and directories in the local filesystem")
print("that do not exist in the Subversion repository that were")
print "not deleted. ",
if ctx.delete_needed:
print "Please pass the --delete command line option"
print "to have this script delete those files and directories."
print("Please pass the --delete command line option")
print("to have this script delete those files and directories.")
else:
print ""
print("")

if status:
return 0
Expand Down
26 changes: 13 additions & 13 deletions contrib/client-side/svnmerge/svnmerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def error(s):
def report(s):
"""Subroutine to output progress message, unless in quiet mode."""
if opts["verbose"]:
print "%s: %s" % (NAME, s)
print("%s: %s" % (NAME, s))

def prefix_lines(prefix, lines):
"""Given a string representing one or more lines of text, insert the
Expand Down Expand Up @@ -1312,10 +1312,10 @@ def display_revisions(revs, display_style, revisions_msg, source_url):
for start, end in revs.normalized():
print
if start == end:
print "%s: changes in revision %d follow" % (NAME, start)
print("%s: changes in revision %d follow" % (NAME, start))
else:
print "%s: changes in revisions %d-%d follow" % (NAME,
start, end)
print("%s: changes in revisions %d-%d follow" % (NAME,
start, end))
print

# Note: the starting revision number to 'svn diff' is
Expand Down Expand Up @@ -1878,7 +1878,7 @@ def _print_wrapped(self, text, indent=0):
text = self._paragraphs(text, self.cwidth - indent)
print text.pop(0)
for t in text:
print " " * indent + t
print(" " * indent + t)

def _find_common(self, fl):
for o in self.copts:
Expand Down Expand Up @@ -1988,12 +1988,12 @@ def error(self, s, cmd=None):
self.print_small_help()
sys.exit(1)
def print_small_help(self):
print "Type '%s help' for usage" % self.progname
print("Type '%s help' for usage" % self.progname)
def print_usage_line(self):
print "usage: %s <subcommand> [options...] [args...]\n" % self.progname
print("usage: %s <subcommand> [options...] [args...]\n" % self.progname)
def print_command_list(self):
print "Available commands (use '%s help COMMAND' for more details):\n" \
% self.progname
print("Available commands (use '%s help COMMAND' for more details):\n" \
% self.progname)
cmds = self.ctable.keys()
cmds.sort()
indent = max(map(len, cmds))
Expand All @@ -2003,7 +2003,7 @@ def print_command_list(self):
self._print_wrapped(h, indent+6)
def print_command_help(self, cmd):
cmd = self.ctable[str(cmd)]
print 'usage: %s %s\n' % (self.progname, cmd.usage)
print('usage: %s %s\n' % (self.progname, cmd.usage))
self._print_wrapped(cmd.help)
def print_opts(opts, self=self):
if not opts: return
Expand All @@ -2012,9 +2012,9 @@ def print_opts(opts, self=self):
for f,o in zip(flags, opts):
print " %-*s :" % (indent, f),
self._print_wrapped(o.help, indent+5)
print '\nCommand options:'
print('\nCommand options:')
print_opts(cmd.opts)
print '\nGlobal options:'
print('\nGlobal options:')
print_opts(self.gopts)

def print_version(self):
Expand Down Expand Up @@ -2374,5 +2374,5 @@ def main(args):
error(err_msg)
except KeyboardInterrupt:
# Avoid traceback on CTRL+C
print "aborted by user"
print("aborted by user")
sys.exit(1)
10 changes: 5 additions & 5 deletions contrib/hook-scripts/hook_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def read_config(repos, filename, expected_tokens_per_line=-1):
'''
path = os.path.join(repos, 'conf', filename)
if not os.path.exists(path):
print 'Not present:', path
print('Not present:', path)
return []

config_lines = open(path).readlines()
Expand All @@ -114,24 +114,24 @@ def read_config(repos, filename, expected_tokens_per_line=-1):
if len(tokens) == expected_tokens_per_line ]

if len(matching_lines) < len(tokenized_lines):
print '*** %d syntax errors in %s' % (
print('*** %d syntax errors in %s' % (
len(tokenized_lines) - len(matching_lines),
path)
path))

return matching_lines


def update_working_copy(wc_path):
if not os.path.exists(wc_path):
print '--> *** Cannot find working copy', wc_path
print('--> *** Cannot find working copy', wc_path)
return None
return run(os.path.join(BIN_PATH, 'svn'), 'update', wc_path)


def run(*cmd):
'''Call the given command & args and return what it printed to stdout.
e.g. result = run('/usr/bin/svn', 'info', wc_dir_path) '''
print '-->', ' '.join(cmd)
print('-->', ' '.join(cmd))
stdout = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
print stdout.strip()
return stdout
Expand Down
6 changes: 3 additions & 3 deletions contrib/hook-scripts/remove-zombie-locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def run(self):
"""iterate over every locked file in repo_path/repo_subpath,
calling unlock_nonexistent_files for each"""

print "Removing all zombie locks from repository at %s\n" \
"This may take several minutes..." % self.repos_path
print("Removing all zombie locks from repository at %s\n" \
"This may take several minutes..." % self.repos_path)

# Try to use svn_fs_get_locks2() if it's present, as it's believed
# to be problem-free.
Expand Down Expand Up @@ -151,7 +151,7 @@ def bdb_lock_callback(lock, callback_pool):
else:
svn.fs.svn_fs_get_locks(self.fs_ptr, self.repos_subpath,
self.unlock_nonexistent_files, self.pool)
print "Done."
print("Done.")


class RevisionZombieLockRemover:
Expand Down
18 changes: 9 additions & 9 deletions contrib/server-side/add-needs-lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def addneedslock(repos_path, uname='', commitmsg='', included='.*', excluded='^$

interesting_files = []

print 'Searching ' + str(len(files)) + ' file(s)...'
print('Searching ' + str(len(files)) + ' file(s)...')

for path in files:
locked_val = svn.fs.get_lock(fsob, path)
Expand All @@ -135,29 +135,29 @@ def addneedslock(repos_path, uname='', commitmsg='', included='.*', excluded='^$
if interesting_files:
if dryrun:
for path in interesting_files:
print "Need to add svn:needs-lock to '" + path + "'"
print("Need to add svn:needs-lock to '" + path + "'")
else:
# open a transaction against HEAD
headrev = svn.fs.youngest_rev(fsob)
txn = svn.repos.fs_begin_txn_for_commit(repos_ptr, headrev, uname, commitmsg)
root = svn.fs.txn_root(txn)

for path in interesting_files:
print "Adding svn:needs-lock to '" + path + "'..."
print("Adding svn:needs-lock to '" + path + "'...")
svn.fs.change_node_prop(root, path, svn.core.SVN_PROP_NEEDS_LOCK, '*')

conflict, newrev = svn.fs.commit_txn(txn)
if conflict:
raise Exception("Conflict encountered (%s)" % conflict)

print 'Created revision: ', newrev
print('Created revision: ', newrev)
else:
print 'Nothing changed. Current Revision: ', headrev
print('Nothing changed. Current Revision: ', headrev)


################################################################################
def usage():
print "USAGE: add-needs-lock.py [-u username] [-m commitmsg] [-i includeregexp] [-e excluderegexp] [-r REV] [-d] REPOS-PATH"
print("USAGE: add-needs-lock.py [-u username] [-m commitmsg] [-i includeregexp] [-e excluderegexp] [-r REV] [-d] REPOS-PATH")
sys.exit(1)


Expand All @@ -184,12 +184,12 @@ def main():
if name == '-r':
rev = int(value)
if name == '-d':
print 'Performing dry run...'
print('Performing dry run...')
dryrun = 1
if rev is None:
print 'Searching all files...'
print('Searching all files...')
else:
print 'Searching revision: ' + str(rev) + '...'
print('Searching revision: ' + str(rev) + '...')
if len(args) == 1:
addneedslock(args[0], uname, commitmsg, included, excluded, rev, dryrun)
else:
Expand Down
2 changes: 1 addition & 1 deletion contrib/server-side/fsfsfixer/fixer/find_good_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def find_good_rep_header(repo_dir, rev, size):
repo_dir = sys.argv[1]
rev = sys.argv[2]
size = sys.argv[3]
print "Good offset:", find_good_rep_header(repo_dir, rev, size)
print("Good offset:", find_good_rep_header(repo_dir, rev, size))
sys.exit(0)

if len(sys.argv) != 3:
Expand Down
Loading

0 comments on commit 3f23c78

Please sign in to comment.