]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
remove humanize, use internal method, teach internal method to understand timedelta 239/head
authormeejah <meejah@meejah.ca>
Wed, 3 Feb 2016 19:38:16 +0000 (12:38 -0700)
committermeejah <meejah@meejah.ca>
Mon, 8 Feb 2016 17:13:09 +0000 (10:13 -0700)
src/allmydata/_auto_deps.py
src/allmydata/scripts/magic_folder_cli.py
src/allmydata/test/check_magicfolder_smoke.py
src/allmydata/util/abbreviate.py

index 3dbff4c992c9520aa62778d44953fd746eeb80f7..bdbf0807fd863238ca99a46a7fcb282711cda222 100644 (file)
@@ -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.
index df81e750fb4ae11e1e097dbf722478f926e4f9f5..cf17cdf4e3080d07f8826f58b0d5a2844a370801 100644 (file)
@@ -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:
index 05a4dd55e93703a25a39c4d802653c9c9407fe70..649fbb4e16b18d111157178ae484e4ecfed99d72 100644 (file)
@@ -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(
         [
index 4bc170618cc5abe83d156953f76999be7cbcf3d8..2bce7dcfd0335346ff85f41d73bb3eac1b07527d 100644 (file)
@@ -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: