2021-06-03 09:26:24 -04:00
|
|
|
"""
|
|
|
|
Ported to Python 3.
|
|
|
|
"""
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import division
|
2019-03-24 14:09:10 +01:00
|
|
|
from __future__ import print_function
|
2008-05-19 19:28:50 -07:00
|
|
|
|
2021-06-03 09:26:24 -04:00
|
|
|
from future.utils import PY2
|
|
|
|
if PY2:
|
|
|
|
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
2021-04-22 10:36:10 -04:00
|
|
|
|
|
|
|
from urllib.parse import quote as url_quote
|
2008-05-19 19:28:50 -07:00
|
|
|
from allmydata.scripts.common_http import do_http, check_http_error
|
2010-02-10 18:43:18 -08:00
|
|
|
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, UnknownAliasError
|
2010-07-11 17:30:15 -07:00
|
|
|
from allmydata.util.encodingutil import quote_output
|
2008-05-19 19:28:50 -07:00
|
|
|
|
2008-08-01 11:46:24 -07:00
|
|
|
def mkdir(options):
|
|
|
|
nodeurl = options['node-url']
|
|
|
|
aliases = options.aliases
|
|
|
|
where = options.where
|
|
|
|
stdout = options.stdout
|
|
|
|
stderr = options.stderr
|
2008-05-19 19:28:50 -07:00
|
|
|
if not nodeurl.endswith("/"):
|
|
|
|
nodeurl += "/"
|
|
|
|
if where:
|
2010-02-10 18:43:18 -08:00
|
|
|
try:
|
|
|
|
rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
|
2019-03-28 12:45:28 +01:00
|
|
|
except UnknownAliasError as e:
|
2010-06-06 18:02:15 -07:00
|
|
|
e.display(stderr)
|
2010-02-10 18:43:18 -08:00
|
|
|
return 1
|
2008-05-19 19:28:50 -07:00
|
|
|
|
|
|
|
if not where or not path:
|
|
|
|
# create a new unlinked directory
|
|
|
|
url = nodeurl + "uri?t=mkdir"
|
2011-10-13 20:15:00 -07:00
|
|
|
if options["format"]:
|
2021-04-22 10:36:10 -04:00
|
|
|
url += "&format=%s" % url_quote(options['format'])
|
2008-05-19 19:28:50 -07:00
|
|
|
resp = do_http("POST", url)
|
|
|
|
rc = check_http_error(resp, stderr)
|
|
|
|
if rc:
|
|
|
|
return rc
|
|
|
|
new_uri = resp.read().strip()
|
|
|
|
# emit its write-cap
|
2019-03-24 14:09:10 +01:00
|
|
|
print(quote_output(new_uri, quotemarks=False), file=stdout)
|
2008-05-19 19:28:50 -07:00
|
|
|
return 0
|
|
|
|
|
|
|
|
# create a new directory at the given location
|
2021-06-03 09:26:24 -04:00
|
|
|
path = str(path, "utf-8")
|
2008-05-19 19:28:50 -07:00
|
|
|
if path.endswith("/"):
|
|
|
|
path = path[:-1]
|
2010-06-06 18:02:15 -07:00
|
|
|
# path must be "/".join([s.encode("utf-8") for s in segments])
|
2021-04-22 10:36:10 -04:00
|
|
|
url = nodeurl + "uri/%s/%s?t=mkdir" % (url_quote(rootcap),
|
|
|
|
url_quote(path))
|
2011-10-13 20:15:00 -07:00
|
|
|
if options['format']:
|
2021-04-22 10:36:10 -04:00
|
|
|
url += "&format=%s" % url_quote(options['format'])
|
2011-08-01 19:16:13 -07:00
|
|
|
|
2008-05-19 19:28:50 -07:00
|
|
|
resp = do_http("POST", url)
|
|
|
|
check_http_error(resp, stderr)
|
|
|
|
new_uri = resp.read().strip()
|
2019-03-24 14:09:10 +01:00
|
|
|
print(quote_output(new_uri, quotemarks=False), file=stdout)
|
2008-05-19 19:28:50 -07:00
|
|
|
return 0
|