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/reliability?a=commitdiff_plain;h=ec57473a47dbc1bb55d39b77c2709bb6dcd9b31e;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 a68ad223..3e664f8c 100644 --- a/src/allmydata/scripts/admin.py +++ b/src/allmydata/scripts/admin.py @@ -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) diff --git a/src/allmydata/test/test_storage.py b/src/allmydata/test/test_storage.py index 77b23fad..252733b4 100644 --- a/src/allmydata/test/test_storage.py +++ b/src/allmydata/test/test_storage.py @@ -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)