]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/scripts/tahoe_mv.py
remove automatic private dir
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / scripts / tahoe_mv.py
1 #! /usr/bin/python
2
3 import re
4 import urllib
5 import simplejson
6 from allmydata.scripts.common_http import do_http
7
8 def mv(nodeurl, dir_uri, frompath, topath, stdout, stderr):
9     frompath = urllib.quote(frompath)
10     topath = urllib.quote(topath)
11     if nodeurl[-1] != "/":
12         nodeurl += "/"
13     url = nodeurl + "uri/%s/" % urllib.quote(dir_uri)
14     data = urllib.urlopen(url + frompath + "?t=json").read()
15
16     nodetype, attrs = simplejson.loads(data)
17     uri = attrs.get("rw_uri") or attrs["ro_uri"]
18     # simplejson always returns unicode, but we know that it's really just a
19     # bytestring.
20     uri = str(uri)
21
22     put_url = url + topath + "?t=uri"
23     resp = do_http("PUT", put_url, uri)
24     status = resp.status
25     if not re.search(r'^2\d\d$', str(status)):
26         print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
27         print >>stderr, resp.read()
28
29     # now remove the original
30     resp = do_http("DELETE", url + frompath)
31     if not re.search(r'^2\d\d$', str(status)):
32         print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
33         print >>stderr, resp.read()
34
35     print >>stdout, "OK"
36     return
37
38
39