--- /dev/null
+
+from twisted.python import usage
+
+class VDriveOptions(usage.Options):
+ optParameters = [
+ ["vdrive", "d", "global",
+ "which virtual drive to use: 'global' or 'private'"],
+
+ ["server", "s", "http://tahoebs1.allmydata.com:8011/",
+ "which vdrive server to use, a URL like http://example.com/"],
+ ]
+
+class ListOptions(VDriveOptions):
+ def parseArgs(self, vdrive_filename=""):
+ self['vdrive_filename'] = vdrive_filename
+
+class GetOptions(VDriveOptions):
+ def parseArgs(self, vdrive_filename, local_filename="-"):
+ self['vdrive_filename'] = vdrive_filename
+ self['local_filename'] = local_filename
+
+
+subCommands = [
+ ["ls", None, ListOptions, "List a directory"],
+ ["get", None, GetOptions, "Retrieve a file from the virtual drive"],
+ ]
+
+def list(config, stdout, stderr):
+ from allmydata.scripts import tahoe_ls
+ rc = tahoe_ls.list(config['server'],
+ config['vdrive'],
+ config['vdrive_filename'])
+ return rc
+
+def get(config, stdout, stderr):
+ from allmydata.scripts import tahoe_get
+ rc = tahoe_get.get(config['server'],
+ config['vdrive'],
+ config['vdrive_filename'])
+ return rc
+
+dispatch = {
+ "ls": list,
+ "get": get,
+ }
+
from cStringIO import StringIO
from twisted.python import usage
-from allmydata.scripts import debug, create_node, startstop_node
+from allmydata.scripts import debug, create_node, startstop_node, cli
class Options(usage.Options):
synopsis = "Usage: allmydata <command> [command options]"
subCommands += create_node.subCommands
subCommands += startstop_node.subCommands
subCommands += debug.subCommands
+ subCommands += cli.subCommands
def postOptions(self):
if not hasattr(self, 'subOptions'):
rc = startstop_node.dispatch[command](so, stdout, stderr)
elif command in debug.dispatch:
rc = debug.dispatch[command](so, stdout, stderr)
+ elif command in cli.dispatch:
+ rc = cli.dispatch[command](so, stdout, stderr)
return rc
+++ /dev/null
-#! /usr/bin/python
-
-import optparse, 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)
-
-
--- /dev/null
+#! /usr/bin/python
+
+import urllib
+import simplejson
+
+def GET(url, outf):
+ f = urllib.urlopen(url)
+ outf.write(f.read())
+
+def list(server, vdrive, vdrive_file):
+
+ if server[-1] != "/":
+ server += "/"
+ url = server + "vdrive/" + vdrive + "/"
+ if vdrive_file:
+ url += vdrive_file
+ url += "?t=json"
+ print "URL:", url
+ 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)
+
+
+
+def main():
+ import optparse
+ 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()
+
+ vdrive_file = ""
+ if args:
+ vdrive_file = args[0]
+
+ list(options.server, options.vdrive, vdrive_file)
+
+if __name__ == '__main__':
+ main()