2008-11-13 03:17:25 +00:00
|
|
|
|
|
|
|
from allmydata.util import base32
|
2008-11-19 03:17:36 +00:00
|
|
|
from allmydata.util.abbreviate import abbreviate_space_both
|
2008-11-13 03:17:25 +00:00
|
|
|
from allmydata import uri
|
2008-11-19 02:11:13 +00:00
|
|
|
from allmydata.scripts.slow_operation import SlowOperationRunner
|
2008-11-13 03:17:25 +00:00
|
|
|
|
2008-11-14 02:43:50 +00:00
|
|
|
class ManifestGrabber(SlowOperationRunner):
|
2008-11-19 02:11:13 +00:00
|
|
|
|
|
|
|
def make_url(self, base, ophandle):
|
|
|
|
return base + "?t=start-manifest&ophandle=" + ophandle
|
2008-11-14 02:43:50 +00:00
|
|
|
|
2008-11-13 03:17:25 +00:00
|
|
|
def write_results(self, data):
|
|
|
|
stdout = self.options.stdout
|
|
|
|
stderr = self.options.stderr
|
|
|
|
if self.options["storage-index"]:
|
|
|
|
for (path, cap) in data["manifest"]:
|
|
|
|
u = uri.from_string(str(cap))
|
|
|
|
si = u.get_storage_index()
|
|
|
|
if si is not None:
|
|
|
|
print >>stdout, base32.b2a(si)
|
|
|
|
else:
|
|
|
|
for (path, cap) in data["manifest"]:
|
|
|
|
try:
|
|
|
|
print >>stdout, cap, "/".join(path)
|
|
|
|
except UnicodeEncodeError:
|
|
|
|
print >>stdout, cap, "/".join([p.encode("utf-8")
|
|
|
|
for p in path])
|
|
|
|
|
|
|
|
def manifest(options):
|
|
|
|
return ManifestGrabber().run(options)
|
2008-11-14 02:43:50 +00:00
|
|
|
|
|
|
|
class StatsGrabber(SlowOperationRunner):
|
2008-11-19 02:11:13 +00:00
|
|
|
|
|
|
|
def make_url(self, base, ophandle):
|
|
|
|
return base + "?t=start-deep-stats&ophandle=" + ophandle
|
2008-11-14 02:43:50 +00:00
|
|
|
|
|
|
|
def write_results(self, data):
|
|
|
|
stdout = self.options.stdout
|
|
|
|
stderr = self.options.stderr
|
|
|
|
keys = ("count-immutable-files",
|
|
|
|
"count-mutable-files",
|
|
|
|
"count-literal-files",
|
|
|
|
"count-files",
|
|
|
|
"count-directories",
|
|
|
|
"size-immutable-files",
|
|
|
|
"size-mutable-files",
|
|
|
|
"size-literal-files",
|
|
|
|
"size-directories",
|
|
|
|
"largest-directory",
|
2008-11-19 03:28:16 +00:00
|
|
|
"largest-immutable-file",
|
2008-11-14 02:43:50 +00:00
|
|
|
)
|
|
|
|
width = max([len(k) for k in keys])
|
|
|
|
print >>stdout, "Counts and Total Sizes:"
|
|
|
|
for k in keys:
|
|
|
|
fmt = "%" + str(width) + "s: %d"
|
|
|
|
if k in data:
|
2008-11-19 03:28:16 +00:00
|
|
|
value = data[k]
|
|
|
|
if not k.startswith("count-") and value > 1000:
|
|
|
|
absize = abbreviate_space_both(value)
|
|
|
|
print >>stdout, fmt % (k, data[k]), " ", absize
|
|
|
|
else:
|
|
|
|
print >>stdout, fmt % (k, data[k])
|
2008-11-14 02:43:50 +00:00
|
|
|
print >>stdout, "Size Histogram:"
|
|
|
|
prevmax = None
|
|
|
|
maxlen = max([len(str(maxsize))
|
|
|
|
for (minsize, maxsize, count)
|
|
|
|
in data["size-files-histogram"]])
|
2008-11-19 03:17:36 +00:00
|
|
|
maxcountlen = max([len(str(count))
|
|
|
|
for (minsize, maxsize, count)
|
|
|
|
in data["size-files-histogram"]])
|
2008-11-14 02:43:50 +00:00
|
|
|
minfmt = "%" + str(maxlen) + "d"
|
|
|
|
maxfmt = "%-" + str(maxlen) + "d"
|
2008-11-19 03:17:36 +00:00
|
|
|
countfmt = "%-" + str(maxcountlen) + "d"
|
|
|
|
linefmt = minfmt + "-" + maxfmt + " : " + countfmt + " %s"
|
2008-11-14 02:43:50 +00:00
|
|
|
for (minsize, maxsize, count) in data["size-files-histogram"]:
|
|
|
|
if prevmax is not None and minsize != prevmax+1:
|
|
|
|
print >>stdout, " "*(maxlen-1) + "..."
|
|
|
|
prevmax = maxsize
|
2008-11-19 03:17:36 +00:00
|
|
|
print >>stdout, linefmt % (minsize, maxsize, count,
|
|
|
|
abbreviate_space_both(maxsize))
|
2008-11-14 02:43:50 +00:00
|
|
|
|
|
|
|
def stats(options):
|
|
|
|
return StatsGrabber().run(options)
|