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