2007-07-11 10:26:19 -07:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import sys, urllib
|
|
|
|
|
2007-08-23 13:27:00 -07:00
|
|
|
def get(nodeurl, vdrive_fname, local_file):
|
2007-08-17 12:54:47 -07:00
|
|
|
if nodeurl[-1] != "/":
|
|
|
|
nodeurl += "/"
|
2007-08-23 13:27:00 -07:00
|
|
|
url = nodeurl + "vdrive/global/"
|
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 == "-":
|
|
|
|
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 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-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-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-08-23 13:27:00 -07:00
|
|
|
get(options.nodeurl, vdrive_fname, local_file)
|
2007-07-11 10:26:19 -07:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|