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
7 def put(nodeurl, aliases, from_file, to_file, mutable,
8 verbosity, stdin, stdout, stderr):
10 @param verbosity: 0, 1, or 2, meaning quiet, verbose, or very verbose
12 @return: a Deferred which eventually fires with the exit code
14 if nodeurl[-1] != "/":
17 rootcap, path = get_alias(aliases, to_file, DEFAULT_ALIAS)
18 url = nodeurl + "uri/%s/" % urllib.quote(rootcap)
20 url += escape_path(path)
24 url += "?mutable=true"
26 infileobj = open(from_file, "rb")
28 # do_http() can't use stdin directly: for one thing, we need a
29 # Content-Length field. So we currently must copy it.
31 print >>stderr, "waiting for file data on stdin.."
33 infileobj = StringIO(data)
35 resp = do_http("PUT", url, infileobj)
37 if resp.status in (200, 201,):
38 print >>stderr, "%s %s" % (resp.status, resp.reason)
39 print >>stdout, resp.read()
42 print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
43 print >>stderr, resp.read()