bin: convert python scripts to python3

This commit is contained in:
Nick Craig-Wood 2019-09-06 22:08:48 +01:00
parent 1382dba3c8
commit 07dfb3aa11
5 changed files with 21 additions and 19 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
""" """
This is a tool to decrypt file names in rclone logs. 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: with open(log_file) as fd:
for line in fd: for line in fd:
for cipher, plain in crypt_map.iteritems(): for cipher, plain in crypt_map.items():
line = line.replace(cipher, plain) line = line.replace(cipher, plain)
sys.stdout.write(line) sys.stdout.write(line)
def main(): def main():
if len(sys.argv) < 3: if len(sys.argv) < 3:
print "Syntax: %s <crypt-mapping-file> <log-file>" % sys.argv[0] print("Syntax: %s <crypt-mapping-file> <log-file>" % sys.argv[0])
raise SystemExit(1) raise SystemExit(1)
mapping_file, log_file = sys.argv[1:] mapping_file, log_file = sys.argv[1:]
crypt_map = read_crypt_map(mapping_file) crypt_map = read_crypt_map(mapping_file)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
""" """
Make backend documentation Make backend documentation
""" """
@ -52,9 +52,9 @@ if __name__ == "__main__":
for backend in find_backends(): for backend in find_backends():
try: try:
alter_doc(backend) alter_doc(backend)
except Exception, e: except Exception as e:
print "Failed adding docs for %s backend: %s" % (backend, e) print("Failed adding docs for %s backend: %s" % (backend, e))
failed += 1 failed += 1
else: else:
success += 1 success += 1
print "Added docs for %d backends with %d failures" % (success, failed) print("Added docs for %d backends with %d failures" % (success, failed))

View File

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
""" """
Generate a markdown changelog for the rclone project Generate a markdown changelog for the rclone project
""" """
@ -99,10 +99,11 @@ def process_log(log):
def main(): def main():
if len(sys.argv) != 3: 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) sys.exit(1)
version, next_version = sys.argv[1], sys.argv[2] 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 = subprocess.check_output(["git", "log", '''--pretty=format:%H|%an|%aI|%s'''] + [version+".."+next_version])
log = log.decode("utf-8")
by_category = process_log(log) by_category = process_log(log)
# Output backends first so remaining in by_category are core items # Output backends first so remaining in by_category are core items
@ -112,7 +113,7 @@ def main():
out("local", title="Local") out("local", title="Local")
out("cache", title="Cache") out("cache", title="Cache")
out("crypt", title="Crypt") 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: for backend_name in backend_names:
if backend_name in backend_titles: if backend_name in backend_titles:
backend_title = backend_titles[backend_name] backend_title = backend_titles[backend_name]
@ -123,7 +124,7 @@ def main():
# Split remaining in by_category into new features and fixes # Split remaining in by_category into new features and fixes
new_features = defaultdict(list) new_features = defaultdict(list)
bugfixes = defaultdict(list) bugfixes = defaultdict(list)
for name, messages in by_category.iteritems(): for name, messages in by_category.items():
for message in messages: for message in messages:
if IS_FIX_RE.search(message): if IS_FIX_RE.search(message):
bugfixes[name].append(message) bugfixes[name].append(message)

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
""" """
Make single page versions of the documentation for release and Make single page versions of the documentation for release and
conversion into man pages etc. conversion into man pages etc.
@ -118,8 +118,8 @@ def check_docs(docpath):
docs_set = set(docs) docs_set = set(docs)
if files == docs_set: if files == docs_set:
return return
print "Files on disk but not in docs variable: %s" % ", ".join(files - docs_set) 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 in docs variable but not on disk: %s" % ", ".join(docs_set - files))
raise ValueError("Missing files") raise ValueError("Missing files")
def read_command(command): def read_command(command):
@ -142,7 +142,7 @@ def read_commands(docpath):
def main(): def main():
check_docs(docpath) 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: with open(outfile, "w") as out:
out.write("""\ out.write("""\
%% rclone(1) User Manual %% rclone(1) User Manual
@ -156,7 +156,7 @@ def main():
if doc == "docs.md": if doc == "docs.md":
contents = re.sub(r"The main rclone commands.*?for the full list.", command_docs, contents, 0, re.S) contents = re.sub(r"The main rclone commands.*?for the full list.", command_docs, contents, 0, re.S)
out.write(contents) out.write(contents)
print "Written '%s'" % outfile print("Written '%s'" % outfile)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
""" """
Update the authors.md file with the authors from the git log 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 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: 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]) subprocess.check_call(["git", "commit", "-m", "Add %s to contributors" % name, AUTHORS])
def main(): def main():
out = subprocess.check_output(["git", "log", '--reverse', '--format=%an|%ae', "master"]) out = subprocess.check_output(["git", "log", '--reverse', '--format=%an|%ae', "master"])
out = out.decode("utf-8")
previous = load() previous = load()
for line in out.split("\n"): for line in out.split("\n"):