]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
add 'allmydata-tahoe dump-uri-extension' utility command
authorBrian Warner <warner@allmydata.com>
Tue, 12 Jun 2007 01:38:21 +0000 (18:38 -0700)
committerBrian Warner <warner@allmydata.com>
Tue, 12 Jun 2007 01:38:21 +0000 (18:38 -0700)
src/allmydata/scripts/runner.py
src/allmydata/uri.py

index d1e33fd50e79e5833a050cba9fbb0ef966f958a0..988729640258c469eee5dc7b4bf7fc7b08b765de 100644 (file)
@@ -116,6 +116,19 @@ class CreateIntroducerOptions(NoDefaultBasedirMixin, usage.Options):
         ["quiet", "q", "operate silently"],
         ]
 
+class DumpOptions(usage.Options):
+    optParameters = [
+        ["filename", "f", None, "which file to dump"],
+        ]
+
+    def parseArgs(self, filename=None):
+        if filename:
+            self['filename'] = filename
+
+    def postOptions(self):
+        if not self['filename']:
+            raise usage.UsageError("<filename> parameter is required")
+
 client_tac = """
 # -*- python -*-
 
@@ -149,6 +162,8 @@ class Options(usage.Options):
         ["start", None, StartOptions, "Start a node (of any type)."],
         ["stop", None, StopOptions, "Stop a node."],
         ["restart", None, RestartOptions, "Restart a node."],
+        ["dump-uri-extension", None, DumpOptions,
+         "Unpack and display the contents of a uri_extension file."],
         ]
 
     def postOptions(self):
@@ -192,6 +207,8 @@ def runner(argv, run_by_human=True):
             return rc
         for basedir in so.basedirs:
             rc = start(basedir, so) or rc
+    elif command == "dump-uri-extension":
+        rc = dump_uri_extension(so)
     return rc
 
 def run():
@@ -275,3 +292,35 @@ def stop(basedir, config):
         time.sleep(1)
     print "never saw process go away"
     return 1
+
+def dump_uri_extension(config):
+    from allmydata import uri
+
+    filename = config['filename']
+    unpacked = uri.unpack_extension_readable(open(filename,"rb").read())
+    keys1 = ("size", "num_segments", "segment_size",
+             "needed_shares", "total_shares")
+    keys2 = ("codec_name", "codec_params", "tail_codec_params")
+    keys3 = ("plaintext_hash", "plaintext_root_hash",
+             "crypttext_hash", "crypttext_root_hash",
+             "share_root_hash")
+    for k in keys1:
+        if k in unpacked:
+            print "%19s: %s" % (k, unpacked[k])
+    print
+    for k in keys2:
+        if k in unpacked:
+            print "%19s: %s" % (k, unpacked[k])
+    print
+    for k in keys3:
+        if k in unpacked:
+            print "%19s: %s" % (k, unpacked[k])
+
+    leftover = set(unpacked.keys()) - set(keys1 + keys2 + keys3)
+    if leftover:
+        print
+        for k in sorted(leftover):
+            print "%s: %s" % (k, unpacked[k])
+
+    print
+    return 0
index a5c0f0003277b2bd24e246308872e0d5fc1be2bc..308f64de6a66960428f94c3b77094fe62c388f92 100644 (file)
@@ -79,3 +79,10 @@ def unpack_extension(data):
             d[intkey] = int(d[intkey])
     return d
 
+
+def unpack_extension_readable(data):
+    unpacked = unpack_extension(data)
+    for k in sorted(unpacked.keys()):
+        if "hash" in k:
+            unpacked[k] = idlib.b2a(unpacked[k])
+    return unpacked