-import os, sys
+# do not import any allmydata modules at this level. Do that from inside
+# individual functions instead.
+import os, sys, struct
from twisted.python import usage
from allmydata.scripts.common import BasedirMixin
raise usage.UsageError("<uri> parameter is required")
def dump_uri_extension(config, out=sys.stdout, err=sys.stderr):
- from allmydata import uri
+ from allmydata import uri, storageserver
filename = config['filename']
- unpacked = uri.unpack_extension_readable(open(filename,"rb").read())
+ f = open(filename,"rb")
+ # use a ReadBucketProxy to parse the bucket and find the uri extension
+ bp = storageserver.ReadBucketProxy(None)
+ offsets = bp._parse_offsets(f.read(8*4))
+ f.seek(offsets['uri_extension'])
+ length = struct.unpack(">L", f.read(4))[0]
+ data = f.read(length)
+
+ unpacked = uri.unpack_extension_readable(data)
keys1 = ("size", "num_segments", "segment_size",
"needed_shares", "total_shares")
keys2 = ("codec_name", "codec_params", "tail_codec_params")
leftover = set(unpacked.keys()) - set(keys1 + keys2 + keys3)
if leftover:
print >>out
+ print >>out, "LEFTOVER:"
for k in sorted(leftover):
print >>out, "%s: %s" % (k, unpacked[k])
def _test_runner(self, res):
# exercise some of the diagnostic tools in runner.py
- # find a uri_extension file
+ # find a share
for (dirpath, dirnames, filenames) in os.walk(self.basedir):
- if "uri_extension" in filenames:
+ if "storage" not in dirpath:
+ continue
+ if not filenames:
+ continue
+ pieces = dirpath.split(os.sep)
+ if pieces[-2] == "storage":
+ # we're sitting in .../storage/$SINDEX , and there are
+ # sharefiles here
+ filename = os.path.join(dirpath, filenames[0])
break
else:
self.fail("unable to find any uri_extension files in %s"
% self.basedir)
- log.msg("test_system.SystemTest._test_runner using %s" % dirpath)
-
- filename = os.path.join(dirpath, "uri_extension")
+ log.msg("test_system.SystemTest._test_runner using %s" % filename)
out,err = StringIO(), StringIO()
rc = runner.runner(["dump-uri-extension",