2 from cStringIO import StringIO
4 from allmydata.scripts.common_http import do_http
5 from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
9 @param verbosity: 0, 1, or 2, meaning quiet, verbose, or very verbose
11 @return: a Deferred which eventually fires with the exit code
13 nodeurl = options['node-url']
14 aliases = options.aliases
15 from_file = options.from_file
16 to_file = options.to_file
17 mutable = options['mutable']
23 stdout = options.stdout
24 stderr = options.stderr
26 if nodeurl[-1] != "/":
29 rootcap, path = get_alias(aliases, to_file, DEFAULT_ALIAS)
30 url = nodeurl + "uri/%s/" % urllib.quote(rootcap)
32 url += escape_path(path)
36 url += "?mutable=true"
38 infileobj = open(from_file, "rb")
40 # do_http() can't use stdin directly: for one thing, we need a
41 # Content-Length field. So we currently must copy it.
43 print >>stderr, "waiting for file data on stdin.."
45 infileobj = StringIO(data)
47 resp = do_http("PUT", url, infileobj)
49 if resp.status in (200, 201,):
50 print >>stderr, "%s %s" % (resp.status, resp.reason)
51 print >>stdout, resp.read()
54 print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
55 print >>stderr, resp.read()