import urllib, simplejson
from twisted.protocols.basic import LineOnlyReceiver
-from allmydata.util import base32
from allmydata.util.abbreviate import abbreviate_space_both
-from allmydata import uri
from allmydata.scripts.slow_operation import SlowOperationRunner
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
from allmydata.scripts.common_http import do_http
class FakeTransport:
disconnecting = False
+
class ManifestStreamer(LineOnlyReceiver):
delimiter = "\n"
+
def __init__(self):
self.transport = FakeTransport()
print >>stdout, d["cap"], "/".join([p.encode("utf-8")
for p in d["path"]])
-
-
-class ManifestGrabber(SlowOperationRunner):
-
- def make_url(self, base, ophandle):
- return base + "?t=start-manifest&ophandle=" + ophandle
-
- 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):
- if options["stream"]:
- return ManifestStreamer().run(options)
- else:
- return ManifestGrabber().run(options)
+ return ManifestStreamer().run(options)
class StatsGrabber(SlowOperationRunner):
def do_test_cli_good(self, ignored):
d = defer.succeed(None)
- d.addCallback(lambda ign: self.do_cli_manifest1())
- d.addCallback(lambda ign: self.do_cli_manifest2())
- d.addCallback(lambda ign: self.do_cli_manifest3())
d.addCallback(lambda ign: self.do_cli_manifest_stream1())
d.addCallback(lambda ign: self.do_cli_manifest_stream2())
d.addCallback(lambda ign: self.do_cli_manifest_stream3())
d.addCallback(lambda ign: self.do_cli_stats2())
return d
- def do_cli_manifest1(self):
- basedir = self.getdir("client0")
- d = self._run_cli(["manifest",
- "--node-directory", basedir,
- self.root_uri])
- def _check((out,err)):
- self.failUnlessEqual(err, "")
- lines = [l for l in out.split("\n") if l]
- self.failUnlessEqual(len(lines), 5)
- caps = {}
- for l in lines:
- try:
- cap, path = l.split(None, 1)
- except ValueError:
- cap = l.strip()
- path = ""
- caps[cap] = path
- self.failUnless(self.root.get_uri() in caps)
- self.failUnlessEqual(caps[self.root.get_uri()], "")
- self.failUnlessEqual(caps[self.mutable.get_uri()], "mutable")
- self.failUnlessEqual(caps[self.large.get_uri()], "large")
- self.failUnlessEqual(caps[self.small.get_uri()], "small")
- self.failUnlessEqual(caps[self.small2.get_uri()], "small2")
- d.addCallback(_check)
- return d
-
- def do_cli_manifest2(self):
- basedir = self.getdir("client0")
- d = self._run_cli(["manifest",
- "--node-directory", basedir,
- "--storage-index", self.root_uri])
- def _check((out,err)):
- self.failUnlessEqual(err, "")
- self._check_manifest_storage_index(out)
- d.addCallback(_check)
- return d
-
def _check_manifest_storage_index(self, out):
lines = [l for l in out.split("\n") if l]
self.failUnlessEqual(len(lines), 3)
self.failUnless(base32.b2a(self.mutable.get_storage_index()) in lines)
self.failUnless(base32.b2a(self.large.get_storage_index()) in lines)
- def do_cli_manifest3(self):
- basedir = self.getdir("client0")
- d = self._run_cli(["manifest",
- "--node-directory", basedir,
- "--raw", self.root_uri])
- def _check2r((out,err)):
- self.failUnlessEqual(err, "")
- data = simplejson.loads(out)
- sis = data["storage-index"]
- self.failUnlessEqual(len(sis), 3)
- self.failUnless(base32.b2a(self.root.get_storage_index()) in sis)
- self.failUnless(base32.b2a(self.mutable.get_storage_index()) in sis)
- self.failUnless(base32.b2a(self.large.get_storage_index()) in sis)
- self.failUnlessEqual(data["stats"]["count-files"], 4)
- self.failUnlessEqual(data["origin"],
- base32.b2a(self.root.get_storage_index()))
- verifycaps = data["verifycaps"]
- self.failUnlessEqual(len(verifycaps), 3)
- self.failUnless(self.root.get_verify_cap().to_string() in verifycaps)
- self.failUnless(self.mutable.get_verify_cap().to_string() in verifycaps)
- self.failUnless(self.large.get_verify_cap().to_string() in verifycaps)
- d.addCallback(_check2r)
- return d
-
def do_cli_manifest_stream1(self):
basedir = self.getdir("client0")
d = self._run_cli(["manifest",
"--node-directory", basedir,
- "--stream",
self.root_uri])
def _check((out,err)):
self.failUnlessEqual(err, "")
basedir = self.getdir("client0")
d = self._run_cli(["manifest",
"--node-directory", basedir,
- "--stream", "--raw",
+ "--raw",
self.root_uri])
def _check((out,err)):
self.failUnlessEqual(err, "")
basedir = self.getdir("client0")
d = self._run_cli(["manifest",
"--node-directory", basedir,
- "--stream", "--storage-index",
+ "--storage-index",
self.root_uri])
def _check((out,err)):
self.failUnlessEqual(err, "")
basedir = self.getdir("client0")
d = self._run_cli(["manifest",
"--node-directory", basedir,
- "--stream", "--verify-cap",
+ "--verify-cap",
self.root_uri])
def _check((out,err)):
self.failUnlessEqual(err, "")
basedir = self.getdir("client0")
d = self._run_cli(["manifest",
"--node-directory", basedir,
- "--stream", "--repair-cap",
+ "--repair-cap",
self.root_uri])
def _check((out,err)):
self.failUnlessEqual(err, "")