From 693e98e3a795159958def17cc0752e95c923aa9f Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Mon, 17 May 2021 10:05:44 -0400 Subject: [PATCH] Port to Python 3. --- src/allmydata/scripts/tahoe_backup.py | 24 ++++++++++++++++-------- src/allmydata/util/_python3.py | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/allmydata/scripts/tahoe_backup.py b/src/allmydata/scripts/tahoe_backup.py index 4847f2e8c..b574f16e8 100644 --- a/src/allmydata/scripts/tahoe_backup.py +++ b/src/allmydata/scripts/tahoe_backup.py @@ -1,6 +1,14 @@ +""" +Ported to Python 3. +""" +from __future__ import unicode_literals +from __future__ import absolute_import +from __future__ import division from __future__ import print_function -from past.builtins import unicode +from future.utils import PY2 +if PY2: + from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 import os.path import time @@ -293,7 +301,7 @@ def collect_backup_targets(root, listdir, filter_children): yield FilenameUndecodableTarget(root, isdir=True) else: for child in filter_children(children): - assert isinstance(child, unicode), child + assert isinstance(child, str), child childpath = os.path.join(root, child) if os.path.islink(childpath): yield LinkTarget(childpath, isdir=False) @@ -498,10 +506,10 @@ class BackupProgress(object): ) def _format_elapsed(self, elapsed): - seconds = elapsed.total_seconds() - hours = int(seconds / 3600) - minutes = int(seconds / 60 % 60) - seconds = int(seconds % 60) + seconds = int(elapsed.total_seconds()) + hours = seconds // 3600 + minutes = (seconds // 60) % 60 + seconds = seconds % 60 return "{}h {}m {}s".format( hours, minutes, @@ -526,12 +534,12 @@ class BackupProgress(object): return self, { os.path.basename(create_path): create_value for (create_path, create_value) - in self._create_contents.items() + in list(self._create_contents.items()) if os.path.dirname(create_path) == dirpath }, { os.path.basename(compare_path): compare_value for (compare_path, compare_value) - in self._compare_contents.items() + in list(self._compare_contents.items()) if os.path.dirname(compare_path) == dirpath } diff --git a/src/allmydata/util/_python3.py b/src/allmydata/util/_python3.py index 0bb9286d7..6e9dfd2e4 100644 --- a/src/allmydata/util/_python3.py +++ b/src/allmydata/util/_python3.py @@ -102,6 +102,7 @@ PORTED_MODULES = [ "allmydata.scripts.runner", "allmydata.scripts.slow_operation", "allmydata.scripts.tahoe_add_alias", + "allmydata.scripts.tahoe_backup", "allmydata.scripts.types_", "allmydata.stats", "allmydata.storage_client",