2 from cStringIO import StringIO
5 from allmydata.scripts.common_http import do_http
6 from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path
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 nodeurl = options['node-url']
15 aliases = options.aliases
16 from_file = options.from_file
17 to_file = options.to_file
18 mutable = options['mutable']
24 stdout = options.stdout
25 stderr = options.stderr
27 if nodeurl[-1] != "/":
30 # several possibilities for the TO_FILE argument.
31 # <none> : unlinked upload
32 # foo : TAHOE_ALIAS/foo
33 # subdir/foo : TAHOE_ALIAS/subdir/foo
34 # /oops/subdir/foo : DISALLOWED
35 # ALIAS:foo : aliases[ALIAS]/foo
36 # ALIAS:subdir/foo : aliases[ALIAS]/subdir/foo
38 # ALIAS:/oops/subdir/foo : DISALLOWED
39 # DIRCAP:./foo : DIRCAP/foo
40 # DIRCAP:./subdir/foo : DIRCAP/subdir/foo
41 # MUTABLE-FILE-WRITECAP : filecap
43 if to_file.startswith("URI:SSK:"):
44 url = nodeurl + "uri/%s" % urllib.quote(to_file)
46 rootcap, path = get_alias(aliases, to_file, DEFAULT_ALIAS)
47 if path.startswith("/"):
48 suggestion = to_file.replace("/", "", 1)
49 print >>stderr, "ERROR: The remote filename must not start with a slash"
50 print >>stderr, "Please try again, perhaps with:", suggestion
52 url = nodeurl + "uri/%s/" % urllib.quote(rootcap)
54 url += escape_path(path)
59 url += "?mutable=true"
61 infileobj = open(os.path.expanduser(from_file), "rb")
63 # do_http() can't use stdin directly: for one thing, we need a
64 # Content-Length field. So we currently must copy it.
66 print >>stderr, "waiting for file data on stdin.."
68 infileobj = StringIO(data)
70 resp = do_http("PUT", url, infileobj)
72 if resp.status in (200, 201,):
73 print >>stderr, "%s %s" % (resp.status, resp.reason)
74 print >>stdout, resp.read()
77 print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
78 print >>stderr, resp.read()