From: Daira Hopwood Date: Sat, 26 Apr 2014 20:26:56 +0000 (+0100) Subject: Add total size output to 'tahoe admin ls-container'. X-Git-Url: https://git.rkrishnan.org/?a=commitdiff_plain;h=8b24043e6a12286b169639ddf9aeafb37c12a83d;p=tahoe-lafs%2Ftahoe-lafs.git Add total size output to 'tahoe admin ls-container'. Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/scripts/admin.py b/src/allmydata/scripts/admin.py index 33579748..2a9c50b5 100644 --- a/src/allmydata/scripts/admin.py +++ b/src/allmydata/scripts/admin.py @@ -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) diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index c6975b38..23121b25 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -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)