]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/scripts/tahoe_rm.py
docs/webapi.rst: address Kevan's comments about use of 'delete' on ref #1104
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / tahoe_rm.py
1
2 import urllib
3 from allmydata.scripts.common_http import do_http, format_http_success, format_http_error
4 from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
5                                      UnknownAliasError
6
7 def rm(options):
8     """
9     @return: a Deferred which eventually fires with the exit code
10     """
11     nodeurl = options['node-url']
12     aliases = options.aliases
13     where = options.where
14     stdout = options.stdout
15     stderr = options.stderr
16
17     if nodeurl[-1] != "/":
18         nodeurl += "/"
19     try:
20         rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
21     except UnknownAliasError, e:
22         e.display(stderr)
23         return 1
24     if not path:
25         print >>stderr, """
26 'tahoe rm' can only unlink directory entries, so a path must be given."""
27         return 1
28
29     url = nodeurl + "uri/%s" % urllib.quote(rootcap)
30     url += "/" + escape_path(path)
31
32     resp = do_http("DELETE", url)
33
34     if resp.status in (200,):
35         print >>stdout, format_http_success(resp)
36         return 0
37
38     print >>stderr, format_http_error("ERROR", resp)
39     return 1