2007-07-11 17:26:19 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2007-10-12 02:47:40 +00:00
|
|
|
import urllib
|
2007-07-11 17:26:19 +00:00
|
|
|
|
2007-10-12 02:20:41 +00:00
|
|
|
def get(nodeurl, root_uri, vdrive_fname, local_file, stdout, stderr):
|
2007-08-17 19:54:47 +00:00
|
|
|
if nodeurl[-1] != "/":
|
|
|
|
nodeurl += "/"
|
2007-10-11 08:34:44 +00:00
|
|
|
url = nodeurl + "uri/%s/" % urllib.quote(root_uri.replace("/","!"))
|
2007-08-17 20:23:16 +00:00
|
|
|
if vdrive_fname:
|
2007-10-27 01:30:44 +00:00
|
|
|
url += urllib.quote(vdrive_fname)
|
2007-07-11 17:26:19 +00:00
|
|
|
|
|
|
|
if local_file is None or local_file == "-":
|
2007-10-12 02:20:41 +00:00
|
|
|
outf = stdout
|
|
|
|
close_outf = False
|
2007-07-11 17:26:19 +00:00
|
|
|
else:
|
|
|
|
outf = open(local_file, "wb")
|
2007-10-12 02:20:41 +00:00
|
|
|
close_outf = True
|
2007-07-11 17:26:19 +00:00
|
|
|
inf = urllib.urlopen(url)
|
|
|
|
while True:
|
|
|
|
data = inf.read(4096)
|
|
|
|
if not data:
|
|
|
|
break
|
|
|
|
outf.write(data)
|
2007-10-12 02:20:41 +00:00
|
|
|
if close_outf:
|
|
|
|
outf.close()
|
2007-07-11 17:26:19 +00:00
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2007-08-17 19:54:47 +00:00
|
|
|
import optparse, re
|
2007-07-11 17:26:19 +00:00
|
|
|
parser = optparse.OptionParser()
|
2007-08-17 19:54:47 +00:00
|
|
|
parser.add_option("-u", "--nodeurl", dest="nodeurl")
|
2007-10-11 07:30:36 +00:00
|
|
|
parser.add_option("-r", "--root-uri", dest="rooturi")
|
2007-07-11 17:26:19 +00:00
|
|
|
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
|
2007-08-17 19:54:47 +00: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 07:30:36 +00:00
|
|
|
|
|
|
|
if not options.rooturi:
|
|
|
|
raise ValueError("must provide --root-uri")
|
2007-11-01 22:28:54 +00:00
|
|
|
|
2007-08-17 20:23:16 +00:00
|
|
|
vdrive_fname = args[0]
|
2007-07-11 17:26:19 +00:00
|
|
|
local_file = None
|
|
|
|
if len(args) > 1:
|
|
|
|
local_file = args[1]
|
|
|
|
|
2007-10-11 07:30:36 +00:00
|
|
|
get(options.nodeurl, options.rooturi, vdrive_fname, local_file)
|
2007-07-11 17:26:19 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|