]> 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>
Sat, 26 Apr 2014 20:26:56 +0000 (21:26 +0100)
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
src/allmydata/scripts/admin.py
src/allmydata/test/test_storage.py

index 335797483e21fcaf64ef4d4e0aeeb46691a45d77..2a9c50b5dbc5a3f5b8d3d625ebfb6d65cfc4b4a8 100644 (file)
@@ -131,6 +131,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
@@ -145,12 +146,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 717da5e2cc793a8c96f7a293d8d885268cf15cd8..8a617c7c6586578ba9e9ebaa44d2affbce528ed6 100644 (file)
@@ -1661,7 +1661,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)
@@ -1681,7 +1683,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)