From: meejah Date: Wed, 3 Feb 2016 19:38:16 +0000 (-0700) Subject: remove humanize, use internal method, teach internal method to understand timedelta X-Git-Url: https://git.rkrishnan.org/(%5B%5E?a=commitdiff_plain;h=83a3f7047a24a8f6a00e21e9d6b94953ef48fff7;p=tahoe-lafs%2Ftahoe-lafs.git remove humanize, use internal method, teach internal method to understand timedelta --- diff --git a/src/allmydata/_auto_deps.py b/src/allmydata/_auto_deps.py index 3dbff4c9..bdbf0807 100644 --- a/src/allmydata/_auto_deps.py +++ b/src/allmydata/_auto_deps.py @@ -64,8 +64,6 @@ install_requires = [ "characteristic >= 14.0.0", # latest service-identity depends on this version "pyasn1 >= 0.1.8", # latest pyasn1-modules depends on this version "pyasn1-modules >= 0.0.5", # service-identity depends on this - - "humanize >= 0.5.1", # might not *need* to be this new ] # We no longer have any setup dependencies. @@ -91,13 +89,11 @@ package_imports = [ ('service-identity', 'service_identity'), ('characteristic', 'characteristic'), ('pyasn1-modules', 'pyasn1_modules'), - ('humanize', 'humanize'), ] # Dependencies for which we don't know how to get a version number at run-time. not_import_versionable = [ 'zope.interface', - 'humanize', ] # Dependencies reported by pkg_resources that we can safely ignore. diff --git a/src/allmydata/scripts/magic_folder_cli.py b/src/allmydata/scripts/magic_folder_cli.py index df81e750..cf17cdf4 100644 --- a/src/allmydata/scripts/magic_folder_cli.py +++ b/src/allmydata/scripts/magic_folder_cli.py @@ -6,7 +6,6 @@ from types import NoneType from cStringIO import StringIO from datetime import datetime -import humanize import simplejson from twisted.python import usage @@ -23,6 +22,7 @@ from allmydata.scripts.common_http import do_http, format_http_success, \ from allmydata.util import fileutil from allmydata.util import configutil from allmydata import uri +from allmydata.util.abbreviate import abbreviate_space, abbreviate_time INVITE_SEPARATOR = "+" @@ -250,7 +250,7 @@ def _print_item_status(item, now, longest): paddedname = (' ' * (longest - len(item['path']))) + item['path'] if 'failure_at' in item: ts = datetime.fromtimestamp(item['started_at']) - prog = 'Failed %s (%s)' % (humanize.naturaltime(now - ts), ts) + prog = 'Failed %s (%s)' % (abbreviate_time(now - ts), ts) elif item['percent_done'] < 100.0: if 'started_at' not in item: prog = 'not yet started' @@ -262,7 +262,7 @@ def _print_item_status(item, now, longest): time_left = (100.0 - item['percent_done']) / rate prog = '%2.1f%% done, around %s left' % ( item['percent_done'], - humanize.naturaldelta(time_left), + abbreviate_time(time_left), ) else: time_left = None @@ -275,7 +275,7 @@ def _print_item_status(item, now, longest): keyname = verb + '_at' if keyname in item: when = datetime.fromtimestamp(item[keyname]) - prog = '%s %s' % (verb, humanize.naturaltime(now - when)) + prog = '%s %s' % (verb, abbreviate_time(now - when)) break print " %s: %s" % (paddedname, prog) @@ -305,8 +305,8 @@ def status(options): size = meta['size'] created = datetime.fromtimestamp(meta['metadata']['tahoe']['linkcrtime']) version = meta['metadata']['version'] - nice_size = humanize.naturalsize(size) - nice_created = humanize.naturaltime(now - created) + nice_size = abbreviate_space(size) + nice_created = abbreviate_time(now - created) if captype != 'filenode': print "%20s: error, should be a filecap" % name continue @@ -332,8 +332,8 @@ def status(options): size = meta['size'] created = datetime.fromtimestamp(meta['metadata']['tahoe']['linkcrtime']) version = meta['metadata']['version'] - nice_size = humanize.naturalsize(size) - nice_created = humanize.naturaltime(now - created) + nice_size = abbreviate_space(size) + nice_created = abbreviate_time(now - created) print " %s (%s): %s, version=%s, created %s" % (n, nice_size, status, version, nice_created) with open(os.path.join(nodedir, u'private', u'api_auth_token'), 'rb') as f: diff --git a/src/allmydata/test/check_magicfolder_smoke.py b/src/allmydata/test/check_magicfolder_smoke.py index 05a4dd55..649fbb4e 100644 --- a/src/allmydata/test/check_magicfolder_smoke.py +++ b/src/allmydata/test/check_magicfolder_smoke.py @@ -360,7 +360,7 @@ if True: if True: # bob leaves - print 'bob leaves' + print('bob leaves') data_dir = join(data_base, 'bob') subprocess.check_call( [ diff --git a/src/allmydata/util/abbreviate.py b/src/allmydata/util/abbreviate.py index 4bc17061..2bce7dcf 100644 --- a/src/allmydata/util/abbreviate.py +++ b/src/allmydata/util/abbreviate.py @@ -1,5 +1,6 @@ import re +from datetime import timedelta HOUR = 3600 DAY = 24*3600 @@ -8,11 +9,18 @@ MONTH = 30*DAY YEAR = 365*DAY def abbreviate_time(s): + postfix = '' + if isinstance(s, timedelta): + s = s.total_seconds() + if s >= 0.0: + postfix = ' ago' + else: + postfix = ' in the future' def _plural(count, unit): count = int(count) if count == 1: - return "%d %s" % (count, unit) - return "%d %ss" % (count, unit) + return "%d %s%s" % (count, unit, postfix) + return "%d %ss%s" % (count, unit, postfix) if s is None: return "unknown" if s < 120: