2007-07-11 02:37:37 +00:00
|
|
|
|
|
|
|
import urllib
|
|
|
|
import simplejson
|
|
|
|
|
2008-01-04 00:02:05 +00:00
|
|
|
def list(nodeurl, dir_uri, vdrive_pathname, stdout, stderr):
|
2007-08-17 19:54:47 +00:00
|
|
|
if nodeurl[-1] != "/":
|
|
|
|
nodeurl += "/"
|
2008-01-04 00:02:05 +00:00
|
|
|
url = nodeurl + "uri/%s/" % urllib.quote(dir_uri)
|
2007-08-17 20:23:16 +00:00
|
|
|
if vdrive_pathname:
|
2007-10-27 01:30:44 +00:00
|
|
|
url += urllib.quote(vdrive_pathname)
|
2007-07-11 02:37:37 +00: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-12 02:20:41 +00:00
|
|
|
print >>stdout, "%10s %s/" % ("", name)
|
2007-07-11 02:37:37 +00:00
|
|
|
else:
|
|
|
|
assert childtype == "filenode"
|
|
|
|
size = child[1]['size']
|
2007-10-12 02:20:41 +00:00
|
|
|
print >>stdout, "%10s %s" % (size, name)
|
2007-10-21 19:33:06 +00:00
|
|
|
elif nodetype == "filenode":
|
|
|
|
print >>stdout, "%10s %s" % (d['size'], vdrive_pathname)
|