2007-07-11 17:26:19 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import sys, urllib
|
|
|
|
|
2007-08-17 19:54:47 +00:00
|
|
|
def get(nodeurl, vdrive, vdrive_file, local_file):
|
|
|
|
if nodeurl[-1] != "/":
|
|
|
|
nodeurl += "/"
|
|
|
|
url = nodeurl + "vdrive/" + vdrive + "/"
|
2007-07-11 17:26:19 +00:00
|
|
|
if vdrive_file:
|
|
|
|
url += vdrive_file
|
|
|
|
|
|
|
|
if local_file is None or local_file == "-":
|
|
|
|
outf = sys.stdout
|
|
|
|
else:
|
|
|
|
outf = open(local_file, "wb")
|
|
|
|
inf = urllib.urlopen(url)
|
|
|
|
while True:
|
|
|
|
data = inf.read(4096)
|
|
|
|
if not data:
|
|
|
|
break
|
|
|
|
outf.write(data)
|
|
|
|
outf.close()
|
|
|
|
|
|
|
|
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()
|
|
|
|
parser.add_option("-d", "--vdrive", dest="vdrive", default="global")
|
2007-08-17 19:54:47 +00:00
|
|
|
parser.add_option("-u", "--nodeurl", dest="nodeurl")
|
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-07-11 17:26:19 +00:00
|
|
|
vdrive_file = args[0]
|
|
|
|
local_file = None
|
|
|
|
if len(args) > 1:
|
|
|
|
local_file = args[1]
|
|
|
|
|
2007-08-17 19:54:47 +00:00
|
|
|
get(options.nodeurl, options.vdrive, vdrive_file, local_file)
|
2007-07-11 17:26:19 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|