2007-10-12 03:31:48 +00:00
|
|
|
|
|
|
|
import re
|
2007-10-12 05:29:23 +00:00
|
|
|
import urllib
|
2007-10-12 03:31:48 +00:00
|
|
|
import simplejson
|
2007-10-12 05:29:23 +00:00
|
|
|
from allmydata.scripts.common_http import do_http
|
2007-10-12 03:31:48 +00:00
|
|
|
|
2008-01-04 00:02:05 +00:00
|
|
|
def mv(nodeurl, dir_uri, frompath, topath, stdout, stderr):
|
2007-10-27 01:30:44 +00:00
|
|
|
frompath = urllib.quote(frompath)
|
|
|
|
topath = urllib.quote(topath)
|
2007-10-12 03:31:48 +00:00
|
|
|
if nodeurl[-1] != "/":
|
|
|
|
nodeurl += "/"
|
2008-01-04 00:02:05 +00:00
|
|
|
url = nodeurl + "uri/%s/" % urllib.quote(dir_uri)
|
2007-10-12 03:31:48 +00:00
|
|
|
data = urllib.urlopen(url + frompath + "?t=json").read()
|
|
|
|
|
|
|
|
nodetype, attrs = simplejson.loads(data)
|
|
|
|
uri = attrs.get("rw_uri") or attrs["ro_uri"]
|
2007-10-12 05:29:23 +00:00
|
|
|
# simplejson always returns unicode, but we know that it's really just a
|
|
|
|
# bytestring.
|
|
|
|
uri = str(uri)
|
2007-10-12 03:31:48 +00:00
|
|
|
|
|
|
|
put_url = url + topath + "?t=uri"
|
|
|
|
resp = do_http("PUT", put_url, uri)
|
|
|
|
status = resp.status
|
|
|
|
if not re.search(r'^2\d\d$', str(status)):
|
|
|
|
print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
|
|
|
|
print >>stderr, resp.read()
|
|
|
|
|
|
|
|
# now remove the original
|
|
|
|
resp = do_http("DELETE", url + frompath)
|
|
|
|
if not re.search(r'^2\d\d$', str(status)):
|
|
|
|
print >>stderr, "error, got %s %s" % (resp.status, resp.reason)
|
|
|
|
print >>stderr, resp.read()
|
|
|
|
|
|
|
|
print >>stdout, "OK"
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|