'tahoe stats': tolerate empty directories. Closes #693.
This commit is contained in:
parent
7950fc0f2e
commit
efa608a135
|
@ -117,24 +117,25 @@ class StatsGrabber(SlowOperationRunner):
|
|||
print >>stdout, fmt % (k, data[k]), " ", absize
|
||||
else:
|
||||
print >>stdout, fmt % (k, data[k])
|
||||
print >>stdout, "Size Histogram:"
|
||||
prevmax = None
|
||||
maxlen = max([len(str(maxsize))
|
||||
for (minsize, maxsize, count)
|
||||
in data["size-files-histogram"]])
|
||||
maxcountlen = max([len(str(count))
|
||||
for (minsize, maxsize, count)
|
||||
in data["size-files-histogram"]])
|
||||
minfmt = "%" + str(maxlen) + "d"
|
||||
maxfmt = "%-" + str(maxlen) + "d"
|
||||
countfmt = "%-" + str(maxcountlen) + "d"
|
||||
linefmt = minfmt + "-" + maxfmt + " : " + countfmt + " %s"
|
||||
for (minsize, maxsize, count) in data["size-files-histogram"]:
|
||||
if prevmax is not None and minsize != prevmax+1:
|
||||
print >>stdout, " "*(maxlen-1) + "..."
|
||||
prevmax = maxsize
|
||||
print >>stdout, linefmt % (minsize, maxsize, count,
|
||||
abbreviate_space_both(maxsize))
|
||||
if data["size-files-histogram"]:
|
||||
print >>stdout, "Size Histogram:"
|
||||
prevmax = None
|
||||
maxlen = max([len(str(maxsize))
|
||||
for (minsize, maxsize, count)
|
||||
in data["size-files-histogram"]])
|
||||
maxcountlen = max([len(str(count))
|
||||
for (minsize, maxsize, count)
|
||||
in data["size-files-histogram"]])
|
||||
minfmt = "%" + str(maxlen) + "d"
|
||||
maxfmt = "%-" + str(maxlen) + "d"
|
||||
countfmt = "%-" + str(maxcountlen) + "d"
|
||||
linefmt = minfmt + "-" + maxfmt + " : " + countfmt + " %s"
|
||||
for (minsize, maxsize, count) in data["size-files-histogram"]:
|
||||
if prevmax is not None and minsize != prevmax+1:
|
||||
print >>stdout, " "*(maxlen-1) + "..."
|
||||
prevmax = maxsize
|
||||
print >>stdout, linefmt % (minsize, maxsize, count,
|
||||
abbreviate_space_both(maxsize))
|
||||
|
||||
def stats(options):
|
||||
return StatsGrabber().run(options)
|
||||
|
|
|
@ -1268,6 +1268,21 @@ class Check(GridTestMixin, CLITestMixin, unittest.TestCase):
|
|||
in lines, out)
|
||||
d.addCallback(_check2)
|
||||
|
||||
d.addCallback(lambda ign: self.do_cli("stats", self.rooturi))
|
||||
def _check_stats((rc, out, err)):
|
||||
self.failUnlessEqual(err, "")
|
||||
self.failUnlessEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
self.failUnlessIn(" count-immutable-files: 1", lines)
|
||||
self.failUnlessIn(" count-mutable-files: 1", lines)
|
||||
self.failUnlessIn(" count-literal-files: 1", lines)
|
||||
self.failUnlessIn(" count-directories: 1", lines)
|
||||
self.failUnlessIn(" size-immutable-files: 400", lines)
|
||||
self.failUnlessIn("Size Histogram:", lines)
|
||||
self.failUnlessIn(" 4-10 : 1 (10 B, 10 B)", lines)
|
||||
self.failUnlessIn(" 317-1000 : 1 (1000 B, 1000 B)", lines)
|
||||
d.addCallback(_check_stats)
|
||||
|
||||
def _clobber_shares(ignored):
|
||||
shares = self.find_shares(self.uris["good"])
|
||||
self.failUnlessEqual(len(shares), 10)
|
||||
|
@ -1431,3 +1446,31 @@ class Errors(GridTestMixin, CLITestMixin, unittest.TestCase):
|
|||
d.addCallback(_check1)
|
||||
|
||||
return d
|
||||
|
||||
class Stats(GridTestMixin, CLITestMixin, unittest.TestCase):
|
||||
def test_empty_directory(self):
|
||||
self.basedir = "cli/Stats/empty_directory"
|
||||
self.set_up_grid()
|
||||
c0 = self.g.clients[0]
|
||||
self.fileurls = {}
|
||||
d = c0.create_empty_dirnode()
|
||||
def _stash_root(n):
|
||||
self.rootnode = n
|
||||
self.rooturi = n.get_uri()
|
||||
d.addCallback(_stash_root)
|
||||
|
||||
# make sure we can get stats on an empty directory too
|
||||
d.addCallback(lambda ign: self.do_cli("stats", self.rooturi))
|
||||
def _check_stats((rc, out, err)):
|
||||
self.failUnlessEqual(err, "")
|
||||
self.failUnlessEqual(rc, 0)
|
||||
lines = out.splitlines()
|
||||
self.failUnlessIn(" count-immutable-files: 0", lines)
|
||||
self.failUnlessIn(" count-mutable-files: 0", lines)
|
||||
self.failUnlessIn(" count-literal-files: 0", lines)
|
||||
self.failUnlessIn(" count-directories: 1", lines)
|
||||
self.failUnlessIn(" size-immutable-files: 0", lines)
|
||||
self.failIfIn("Size Histogram:", lines)
|
||||
d.addCallback(_check_stats)
|
||||
|
||||
return d
|
||||
|
|
Loading…
Reference in New Issue