]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
tahoe-ls.py: initial version of an 'ls' CLI utility
authorBrian Warner <warner@lothar.com>
Tue, 10 Jul 2007 22:34:55 +0000 (15:34 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 10 Jul 2007 22:34:55 +0000 (15:34 -0700)
src/allmydata/scripts/tahoe-ls.py [new file with mode: 0644]

diff --git a/src/allmydata/scripts/tahoe-ls.py b/src/allmydata/scripts/tahoe-ls.py
new file mode 100644 (file)
index 0000000..b5f389d
--- /dev/null
@@ -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)
+
+