Line | |
---|
1 | """ |
---|
2 | Ported to Python 3. |
---|
3 | """ |
---|
4 | |
---|
5 | from urllib.parse import quote as url_quote |
---|
6 | from allmydata.scripts.common_http import do_http, format_http_success, format_http_error |
---|
7 | from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \ |
---|
8 | UnknownAliasError |
---|
9 | |
---|
10 | def 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.