]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/scripts/tahoe_rm.py
3b133d089e07730596b6ee4992a3586717c47021
[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     assert path
25     url = nodeurl + "uri/%s" % urllib.quote(rootcap)
26     url += "/" + escape_path(path)
27
28     resp = do_http("DELETE", url)
29
30     if resp.status in (200,):
31         print >>stdout, format_http_success(resp)
32         return 0
33
34     print >>stderr, format_http_error("ERROR", resp)
35     return 1