4 from allmydata.scripts.common_http import do_http
6 def put(nodeurl, root_uri, local_fname, vdrive_fname, verbosity,
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 if nodeurl[-1] != "/":
15 url = nodeurl + "uri/%s/" % urllib.quote(root_uri.replace("/","!"))
17 url += urllib.quote(vdrive_fname)
19 infileobj = open(local_fname, "rb")
20 resp = do_http("PUT", url, infileobj)
22 if resp.status in (200, 201,):
23 print >>stdout, "%s %s" % (resp.status, resp.reason)
26 print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
27 print >>stderr, resp.read()
32 parser = optparse.OptionParser()
33 parser.add_option("-u", "--node-url", dest="nodeurl")
34 parser.add_option("-r", "--root-uri", dest="rooturi")
36 (options, args) = parser.parse_args()
38 NODEURL_RE=re.compile("http://([^:]*)(:([1-9][0-9]*))?")
39 if not isinstance(options.nodeurl, basestring) or not NODEURL_RE.match(options.nodeurl):
40 raise ValueError("--node-url is required to be a string and look like \"http://HOSTNAMEORADDR:PORT\", not: %r" % (options.nodeurl,))
42 if not options.rooturi:
43 raise ValueError("must provide --root-uri")
48 vdrive_fname = args[1]
50 return put(options.nodeurl, options.rooturi, vdrive_fname, local_file)
52 if __name__ == '__main__':