2007-07-10 19:37:37 -07:00
|
|
|
#! /usr/bin/python
|
|
|
|
|
|
|
|
import urllib
|
|
|
|
import simplejson
|
|
|
|
|
2008-01-03 17:02:05 -07:00
|
|
|
def list(nodeurl, dir_uri, vdrive_pathname, stdout, stderr):
|
2007-08-17 12:54:47 -07:00
|
|
|
if nodeurl[-1] != "/":
|
|
|
|
nodeurl += "/"
|
2008-01-03 17:02:05 -07:00
|
|
|
url = nodeurl + "uri/%s/" % urllib.quote(dir_uri)
|
2007-08-17 13:23:16 -07:00
|
|
|
if vdrive_pathname:
|
2007-10-26 18:30:44 -07:00
|
|
|
url += urllib.quote(vdrive_pathname)
|
2007-07-10 19:37:37 -07:00
|
|
|
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":
|
2007-10-11 19:20:41 -07:00
|
|
|
print >>stdout, "%10s %s/" % ("", name)
|
2007-07-10 19:37:37 -07:00
|
|
|
else:
|
|
|
|
assert childtype == "filenode"
|
|
|
|
size = child[1]['size']
|
2007-10-11 19:20:41 -07:00
|
|
|
print >>stdout, "%10s %s" % (size, name)
|
2007-10-21 12:33:06 -07:00
|
|
|
elif nodetype == "filenode":
|
|
|
|
print >>stdout, "%10s %s" % (d['size'], vdrive_pathname)
|
2007-07-10 19:37:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2007-08-17 12:54:47 -07:00
|
|
|
import optparse, re
|
2007-07-10 19:37:37 -07:00
|
|
|
parser = optparse.OptionParser()
|
2007-08-17 12:54:47 -07:00
|
|
|
parser.add_option("-u", "--node-url", dest="nodeurl")
|
2008-01-08 10:41:27 -07:00
|
|
|
parser.add_option("-r", "--dir-cap", dest="rooturi")
|
2007-07-10 19:37:37 -07:00
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
2007-08-17 12:54:47 -07:00
|
|
|
NODEURL_RE=re.compile("http://([^:]*)(:([1-9][0-9]*))?")
|
|
|
|
if not isinstance(options.nodeurl, basestring) or not NODEURL_RE.match(options.nodeurl):
|
|
|
|
raise ValueError("--node-url is required to be a string and look like \"http://HOSTNAMEORADDR:PORT\", not: %r" % (options.nodeurl,))
|
2007-10-11 00:30:36 -07:00
|
|
|
|
|
|
|
if not options.rooturi:
|
2008-01-08 10:41:27 -07:00
|
|
|
raise ValueError("must provide --dir-cap")
|
2007-10-11 00:30:36 -07:00
|
|
|
|
2007-08-17 13:23:16 -07:00
|
|
|
vdrive_pathname = ""
|
2007-07-10 19:37:37 -07:00
|
|
|
if args:
|
2007-08-17 13:23:16 -07:00
|
|
|
vdrive_pathname = args[0]
|
2007-07-10 19:37:37 -07:00
|
|
|
|
2007-10-11 00:30:36 -07:00
|
|
|
list(options.nodeurl, options.rooturi, vdrive_pathname)
|
2007-07-10 19:37:37 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|