source: trunk/src/allmydata/scripts/tahoe_unlink.py

Last change on this file was 1cfe843d, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-22T23:40:25Z

more python2 removal

  • Property mode set to 100644
File size: 1.2 KB
Line 
1"""
2Ported to Python 3.
3"""
4
5from urllib.parse import quote as url_quote
6from allmydata.scripts.common_http import do_http, format_http_success, format_http_error
7from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
8                                     UnknownAliasError
9
10def unlink(options, command="unlink"):
11    """
12    @return: a Deferred which eventually fires with the exit code
13    """
14    nodeurl = options['node-url']
15    aliases = options.aliases
16    where = options.where
17    stdout = options.stdout
18    stderr = options.stderr
19
20    if nodeurl[-1] != "/":
21        nodeurl += "/"
22    try:
23        rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
24    except UnknownAliasError as e:
25        e.display(stderr)
26        return 1
27    if not path:
28        print("""
29'tahoe %s' can only unlink directory entries, so a path must be given.""" % (command,), file=stderr)
30        return 1
31
32    url = nodeurl + "uri/%s" % url_quote(rootcap)
33    url += "/" + escape_path(path)
34
35    resp = do_http("DELETE", url)
36
37    if resp.status in (200,):
38        print(format_http_success(resp), file=stdout)
39        return 0
40
41    print(format_http_error("ERROR", resp), file=stderr)
42    return 1
Note: See TracBrowser for help on using the repository browser.