]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Add total size output to 'tahoe admin ls-container'.
authorDaira Hopwood <daira@jacaranda.org>
Sat, 26 Apr 2014 20:26:56 +0000 (21:26 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Tue, 4 Aug 2015 18:10:29 +0000 (19:10 +0100)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/scripts/admin.py
src/allmydata/test/test_storage.py

index a68ad223cf87fe19dfffd084ea57e7c77cccb295..3e664f8ccf33baa4ef92be169247fcaa75505fdc 100644 (file)
@@ -129,6 +129,7 @@ def do_ls_container(options):
     from twisted.internet import defer
     from allmydata.node import ConfigOnly
     from allmydata.client import Client
+    from allmydata.util.namespace import Namespace
 
     out = options.stdout
     err = options.stderr
@@ -143,12 +144,18 @@ def do_ls_container(options):
 
         (backend, _) = Client.configure_backend(config)
 
+        ns = Namespace()
+        ns.total_size = 0
         d2 = backend.list_container()
         def _done(items):
             print >>out, "Listing %d object(s):" % len(items)
             print >>out, "    Size  Last modified         Key"
             for item in items:
                 print >>out, "% 8s  %20s  %s" % (item.size, format_date(item.modification_date), item.key)
+                ns.total_size += int(item.size)
+
+            print >>out
+            print >>out, "Total size: %d bytes" % (ns.total_size,)
         d2.addCallback(_done)
         return d2
     d.addCallback(_do_create)
index 77b23fadc0e71d693d1d9504d3149b57e2f29069..252733b493c4f067991eeaf7bcca173dbc1bc4da 100644 (file)
@@ -1668,7 +1668,9 @@ class AdminContainerTests(unittest.TestCase, WorkdirMixin):
             self.failUnlessEqual(out_lines[0], "Listing 0 object(s):", str(res))
             self.failUnless(re.match(r'^\s*Size\s+Last modified\s+Key$', out_lines[1]), str(res))
             self.failUnlessEqual(out_lines[2], "", str(res))
-            self.failUnlessEqual(len(out_lines), 3)
+            self.failUnlessEqual(out_lines[3], "Total size: 0 bytes", str(res))
+            self.failUnlessEqual(out_lines[4], "", str(res))
+            self.failUnlessEqual(len(out_lines), 5)
             self.failUnlessEqual(err, "", str(res))
             self.failUnlessEqual(rc, 0, str(res))
         d.addCallback(_check_no_objects)
@@ -1688,7 +1690,10 @@ class AdminContainerTests(unittest.TestCase, WorkdirMixin):
             self.failUnlessEqual(out_lines[0], "Listing 1 object(s):", str(res))
             self.failUnless(re.match(r'^\s*Size\s+Last modified\s+Key$', out_lines[1]), str(res))
             self.failUnless(re.match(r'^\s*10\s+\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d*)?Z\s+shares/fo/foo/0$', out_lines[2]), str(res))
-            self.failUnlessEqual(len(out_lines), 4)
+            self.failUnlessEqual(out_lines[3], "", str(res))
+            self.failUnlessEqual(out_lines[4], "Total size: 10 bytes", str(res))
+            self.failUnlessEqual(out_lines[5], "", str(res))
+            self.failUnlessEqual(len(out_lines), 6)
             self.failUnlessEqual(err, "", str(res))
             self.failUnlessEqual(rc, 0, str(res))
         d.addCallback(_check_one_object)