From e0dfedb0a617f569c9f2635dd30c6ef5ad5a524b Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 11 Jun 2007 18:38:21 -0700 Subject: [PATCH] add 'allmydata-tahoe dump-uri-extension' utility command --- src/allmydata/scripts/runner.py | 49 +++++++++++++++++++++++++++++++++ src/allmydata/uri.py | 7 +++++ 2 files changed, 56 insertions(+) diff --git a/src/allmydata/scripts/runner.py b/src/allmydata/scripts/runner.py index d1e33fd5..98872964 100644 --- a/src/allmydata/scripts/runner.py +++ b/src/allmydata/scripts/runner.py @@ -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(" 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 diff --git a/src/allmydata/uri.py b/src/allmydata/uri.py index a5c0f000..308f64de 100644 --- a/src/allmydata/uri.py +++ b/src/allmydata/uri.py @@ -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 -- 2.45.2