From 07dfb3aa11e40dd9bf4ff20c418c98492380c88c Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 6 Sep 2019 22:08:48 +0100 Subject: [PATCH] bin: convert python scripts to python3 --- bin/decrypt_names.py | 6 +++--- bin/make_backend_docs.py | 8 ++++---- bin/make_changelog.py | 9 +++++---- bin/make_manual.py | 10 +++++----- bin/update-authors.py | 7 ++++--- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/bin/decrypt_names.py b/bin/decrypt_names.py index 1fec84c61..55e9cc50a 100755 --- a/bin/decrypt_names.py +++ b/bin/decrypt_names.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ This is a tool to decrypt file names in rclone logs. @@ -43,13 +43,13 @@ def map_log_file(crypt_map, log_file): """ with open(log_file) as fd: for line in fd: - for cipher, plain in crypt_map.iteritems(): + for cipher, plain in crypt_map.items(): line = line.replace(cipher, plain) sys.stdout.write(line) def main(): if len(sys.argv) < 3: - print "Syntax: %s " % sys.argv[0] + print("Syntax: %s " % sys.argv[0]) raise SystemExit(1) mapping_file, log_file = sys.argv[1:] crypt_map = read_crypt_map(mapping_file) diff --git a/bin/make_backend_docs.py b/bin/make_backend_docs.py index 046433050..a30df22ad 100755 --- a/bin/make_backend_docs.py +++ b/bin/make_backend_docs.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ Make backend documentation """ @@ -52,9 +52,9 @@ if __name__ == "__main__": for backend in find_backends(): try: alter_doc(backend) - except Exception, e: - print "Failed adding docs for %s backend: %s" % (backend, e) + except Exception as e: + print("Failed adding docs for %s backend: %s" % (backend, e)) failed += 1 else: success += 1 - print "Added docs for %d backends with %d failures" % (success, failed) + print("Added docs for %d backends with %d failures" % (success, failed)) diff --git a/bin/make_changelog.py b/bin/make_changelog.py index e3f1a3cc3..f726ec3d0 100755 --- a/bin/make_changelog.py +++ b/bin/make_changelog.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 """ Generate a markdown changelog for the rclone project """ @@ -99,10 +99,11 @@ def process_log(log): def main(): if len(sys.argv) != 3: - print >>sys.stderr, "Syntax: %s vX.XX vX.XY" % sys.argv[0] + print("Syntax: %s vX.XX vX.XY" % sys.argv[0], file=sys.stderr) sys.exit(1) version, next_version = sys.argv[1], sys.argv[2] log = subprocess.check_output(["git", "log", '''--pretty=format:%H|%an|%aI|%s'''] + [version+".."+next_version]) + log = log.decode("utf-8") by_category = process_log(log) # Output backends first so remaining in by_category are core items @@ -112,7 +113,7 @@ def main(): out("local", title="Local") out("cache", title="Cache") out("crypt", title="Crypt") - backend_names = sorted(x for x in by_category.keys() if x in backends) + backend_names = sorted(x for x in list(by_category.keys()) if x in backends) for backend_name in backend_names: if backend_name in backend_titles: backend_title = backend_titles[backend_name] @@ -123,7 +124,7 @@ def main(): # Split remaining in by_category into new features and fixes new_features = defaultdict(list) bugfixes = defaultdict(list) - for name, messages in by_category.iteritems(): + for name, messages in by_category.items(): for message in messages: if IS_FIX_RE.search(message): bugfixes[name].append(message) diff --git a/bin/make_manual.py b/bin/make_manual.py index 3255cd4d0..afb29feb4 100755 --- a/bin/make_manual.py +++ b/bin/make_manual.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 """ Make single page versions of the documentation for release and conversion into man pages etc. @@ -118,8 +118,8 @@ def check_docs(docpath): docs_set = set(docs) if files == docs_set: return - print "Files on disk but not in docs variable: %s" % ", ".join(files - docs_set) - print "Files in docs variable but not on disk: %s" % ", ".join(docs_set - files) + print("Files on disk but not in docs variable: %s" % ", ".join(files - docs_set)) + print("Files in docs variable but not on disk: %s" % ", ".join(docs_set - files)) raise ValueError("Missing files") def read_command(command): @@ -142,7 +142,7 @@ def read_commands(docpath): def main(): check_docs(docpath) - command_docs = read_commands(docpath) + command_docs = read_commands(docpath).replace("\\", "\\\\") # escape \ so we can use command_docs in re.sub with open(outfile, "w") as out: out.write("""\ %% rclone(1) User Manual @@ -156,7 +156,7 @@ def main(): if doc == "docs.md": contents = re.sub(r"The main rclone commands.*?for the full list.", command_docs, contents, 0, re.S) out.write(contents) - print "Written '%s'" % outfile + print("Written '%s'" % outfile) if __name__ == "__main__": main() diff --git a/bin/update-authors.py b/bin/update-authors.py index a8c7fc37e..0bf75c20e 100755 --- a/bin/update-authors.py +++ b/bin/update-authors.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 """ Update the authors.md file with the authors from the git log """ @@ -23,13 +23,14 @@ def add_email(name, email): """ adds the email passed in to the end of authors.md """ - print "Adding %s <%s>" % (name, email) + print("Adding %s <%s>" % (name, email)) with open(AUTHORS, "a+") as fd: - print >>fd, " * %s <%s>" % (name, email) + print(" * %s <%s>" % (name, email), file=fd) subprocess.check_call(["git", "commit", "-m", "Add %s to contributors" % name, AUTHORS]) def main(): out = subprocess.check_output(["git", "log", '--reverse', '--format=%an|%ae', "master"]) + out = out.decode("utf-8") previous = load() for line in out.split("\n"):