From dec729028fe0dfb426cd0a3eee4a82c0da8a5cfe Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Tue, 10 Jul 2007 15:34:55 -0700 Subject: [PATCH] tahoe-ls.py: initial version of an 'ls' CLI utility --- src/allmydata/scripts/tahoe-ls.py | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/allmydata/scripts/tahoe-ls.py diff --git a/src/allmydata/scripts/tahoe-ls.py b/src/allmydata/scripts/tahoe-ls.py new file mode 100644 index 00000000..b5f389dc --- /dev/null +++ b/src/allmydata/scripts/tahoe-ls.py @@ -0,0 +1,37 @@ +#! /usr/bin/python + +import optparse, sys, urllib +import simplejson + +def GET(url, outf): + f = urllib.urlopen(url) + outf.write(f.read()) + +parser = optparse.OptionParser() +parser.add_option("-d", "--vdrive", dest="vdrive", default="global") +parser.add_option("-s", "--server", dest="server", default="http://tahoebs1.allmydata.com:8011") + +(options, args) = parser.parse_args() + + +url = options.server + "/vdrive/" + options.vdrive +if args: + url += "/" + args[0] +url += "?t=json" +data = urllib.urlopen(url).read() + +parsed = simplejson.loads(data) +nodetype, d = parsed +if nodetype == "dirnode": + childnames = sorted(d['children'].keys()) + for name in childnames: + child = d['children'][name] + childtype = child[0] + if childtype == "dirnode": + print "%10s %s/" % ("", name) + else: + assert childtype == "filenode" + size = child[1]['size'] + print "%10s %s" % (size, name) + + -- 2.45.2