2007-07-11 17:26:19 +00:00
|
|
|
|
2007-10-12 02:47:40 +00:00
|
|
|
import urllib
|
2008-05-20 02:28:50 +00:00
|
|
|
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
|
|
|
|
from allmydata.scripts.common_http import do_http
|
2007-07-11 17:26:19 +00:00
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def get(options):
|
|
|
|
nodeurl = options['node-url']
|
|
|
|
aliases = options.aliases
|
|
|
|
from_file = options.from_file
|
|
|
|
to_file = options.to_file
|
|
|
|
stdout = options.stdout
|
|
|
|
stderr = options.stderr
|
|
|
|
|
2007-08-17 19:54:47 +00:00
|
|
|
if nodeurl[-1] != "/":
|
|
|
|
nodeurl += "/"
|
2008-05-20 02:28:50 +00:00
|
|
|
rootcap, path = get_alias(aliases, from_file, DEFAULT_ALIAS)
|
|
|
|
url = nodeurl + "uri/%s" % urllib.quote(rootcap)
|
|
|
|
if path:
|
|
|
|
url += "/" + escape_path(path)
|
2007-07-11 17:26:19 +00:00
|
|
|
|
2008-05-20 02:28:50 +00:00
|
|
|
if to_file:
|
|
|
|
outf = open(to_file, "wb")
|
|
|
|
close_outf = True
|
|
|
|
else:
|
2007-10-12 02:20:41 +00:00
|
|
|
outf = stdout
|
|
|
|
close_outf = False
|
2008-05-20 02:28:50 +00:00
|
|
|
|
|
|
|
resp = do_http("GET", url)
|
|
|
|
if resp.status in (200, 201,):
|
|
|
|
while True:
|
|
|
|
data = resp.read(4096)
|
|
|
|
if not data:
|
|
|
|
break
|
|
|
|
outf.write(data)
|
|
|
|
rc = 0
|
2007-07-11 17:26:19 +00:00
|
|
|
else:
|
2008-05-20 02:28:50 +00:00
|
|
|
print >>stderr, "Error, got %s %s" % (resp.status, resp.reason)
|
|
|
|
print >>stderr, resp.read()
|
|
|
|
rc = 1
|
|
|
|
|
2007-10-12 02:20:41 +00:00
|
|
|
if close_outf:
|
|
|
|
outf.close()
|
2007-07-11 17:26:19 +00:00
|
|
|
|
2008-05-20 02:28:50 +00:00
|
|
|
return rc
|