]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/scripts/tahoe_mkdir.py
add --format= to 'tahoe put'/'mkdir', remove --mutable-type. Closes #1561
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / tahoe_mkdir.py
1
2 import urllib
3 from allmydata.scripts.common_http import do_http, check_http_error
4 from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, UnknownAliasError
5 from allmydata.util.encodingutil import quote_output
6
7 def mkdir(options):
8     nodeurl = options['node-url']
9     aliases = options.aliases
10     where = options.where
11     stdout = options.stdout
12     stderr = options.stderr
13     if not nodeurl.endswith("/"):
14         nodeurl += "/"
15     if where:
16         try:
17             rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
18         except UnknownAliasError, e:
19             e.display(stderr)
20             return 1
21
22     if not where or not path:
23         # create a new unlinked directory
24         url = nodeurl + "uri?t=mkdir"
25         if options["format"]:
26             url += "&format=%s" % urllib.quote(options['format'])
27         resp = do_http("POST", url)
28         rc = check_http_error(resp, stderr)
29         if rc:
30             return rc
31         new_uri = resp.read().strip()
32         # emit its write-cap
33         print >>stdout, quote_output(new_uri, quotemarks=False)
34         return 0
35
36     # create a new directory at the given location
37     if path.endswith("/"):
38         path = path[:-1]
39     # path must be "/".join([s.encode("utf-8") for s in segments])
40     url = nodeurl + "uri/%s/%s?t=mkdir" % (urllib.quote(rootcap),
41                                            urllib.quote(path))
42     if options['format']:
43         url += "&format=%s" % urllib.quote(options['format'])
44
45     resp = do_http("POST", url)
46     check_http_error(resp, stderr)
47     new_uri = resp.read().strip()
48     print >>stdout, quote_output(new_uri, quotemarks=False)
49     return 0