2007-08-17 20:23:16 +00:00
|
|
|
|
2007-10-12 05:29:23 +00:00
|
|
|
import urllib
|
|
|
|
from allmydata.scripts.common_http import do_http
|
2010-02-11 02:43:18 +00:00
|
|
|
from allmydata.scripts.common import get_alias, DEFAULT_ALIAS, escape_path, \
|
|
|
|
UnknownAliasError
|
2007-08-17 20:23:16 +00:00
|
|
|
|
2008-08-01 18:46:24 +00:00
|
|
|
def rm(options):
|
2007-08-17 20:23:16 +00:00
|
|
|
"""
|
|
|
|
@return: a Deferred which eventually fires with the exit code
|
|
|
|
"""
|
2008-08-01 18:46:24 +00:00
|
|
|
nodeurl = options['node-url']
|
|
|
|
aliases = options.aliases
|
|
|
|
where = options.where
|
|
|
|
stdout = options.stdout
|
|
|
|
stderr = options.stderr
|
|
|
|
|
2007-10-12 05:29:23 +00:00
|
|
|
if nodeurl[-1] != "/":
|
|
|
|
nodeurl += "/"
|
2010-02-11 02:43:18 +00:00
|
|
|
try:
|
|
|
|
rootcap, path = get_alias(aliases, where, DEFAULT_ALIAS)
|
|
|
|
except UnknownAliasError, e:
|
|
|
|
print >>stderr, "error: %s" % e.args[0]
|
|
|
|
return 1
|
2008-05-20 02:28:50 +00:00
|
|
|
assert path
|
|
|
|
url = nodeurl + "uri/%s" % urllib.quote(rootcap)
|
|
|
|
url += "/" + escape_path(path)
|
2007-08-17 20:23:16 +00:00
|
|
|
|
2007-10-12 05:29:23 +00:00
|
|
|
resp = do_http("DELETE", url)
|
2007-08-17 20:23:16 +00:00
|
|
|
|
2007-10-12 05:29:23 +00:00
|
|
|
if resp.status in (200,):
|
|
|
|
print >>stdout, "%s %s" % (resp.status, resp.reason)
|
|
|
|
return 0
|
2007-08-17 20:23:16 +00:00
|
|
|
|
2007-10-12 05:29:23 +00:00
|
|
|
print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
|
|
|
|
print >>stderr, resp.read()
|
2007-08-17 20:23:16 +00:00
|
|
|
return 1
|