import simplejson
from allmydata.interfaces import IDownloadTarget, IDirectoryNode, IFileNode, \
IMutableFileNode
-from allmydata import upload, download
+from allmydata import download
+from allmydata.upload import FileHandle, FileName
from allmydata import provisioning
from allmydata import get_package_versions_string
from zope.interface import implements, Interface
raise RuntimeError("mkdir requires a name")
d = self._check_replacement(name)
d.addCallback(lambda res: self._node.create_empty_directory(name))
- def _done(res):
- return "directory created"
- d.addCallback(_done)
+ d.addCallback(lambda res: "directory created")
elif t == "uri":
if not name:
raise RuntimeError("set-uri requires a name")
newuri = req.fields["uri"].value.strip()
d = self._check_replacement(name)
d.addCallback(lambda res: self._node.set_uri(name, newuri))
- def _done(res):
- return newuri
- d.addCallback(_done)
+ d.addCallback(lambda res: newuri)
elif t == "delete":
if name is None:
# apparently an <input type="hidden" name="name" value="">
# buttons ourselves.
name = ''
d = self._node.delete(name)
- def _done(res):
- return "thing deleted"
- d.addCallback(_done)
+ d.addCallback(lambda res: "thing deleted")
elif t == "rename":
from_name = 'from_name' in req.fields and req.fields["from_name"].value
if from_name is not None:
def rm_src(junk):
return self._node.delete(from_name)
d.addCallback(rm_src)
- def _done(res):
- return "thing renamed"
- d.addCallback(_done)
+ d.addCallback(lambda res: "thing renamed")
elif t == "upload":
if "mutable" in req.fields:
# SDMF: files are small, and we can only upload data.
contents.file.seek(0)
data = contents.file.read()
- uploadable = upload.FileHandle(contents.file)
+ uploadable = FileHandle(contents.file)
d = self._check_replacement(name)
d.addCallback(lambda res: self._node.has_child(name))
def _checked(present):
name = name.strip()
if not name:
raise RuntimeError("upload requires a name")
- uploadable = upload.FileHandle(contents.file)
+ uploadable = FileHandle(contents.file)
d = self._check_replacement(name)
d.addCallback(lambda res: self._node.add_file(name, uploadable))
def _done(newnode):
data = contents.file.read()
# TODO: 'name' handling needs review
d = defer.succeed(self._node)
- def _got_child(child_node):
+ def _got_child_overwrite(child_node):
child_node.replace(data)
return child_node.get_uri()
- d.addCallback(_got_child)
+ d.addCallback(_got_child_overwrite)
elif t == "check":
d = self._node.get(name)
- def _got_child(child_node):
+ def _got_child_check(child_node):
d2 = child_node.check()
def _done(res):
log.msg("checked %s, results %s" % (child_node, res))
return str(res)
d2.addCallback(_done)
return d2
- d.addCallback(_got_child)
+ d.addCallback(_got_child_check)
else:
print "BAD t=%s" % t
return "BAD t=%s" % t
return d
def _upload_file(self, node, contents, name):
- uploadable = upload.FileHandle(contents)
+ uploadable = FileHandle(contents)
d = node.add_file(name, uploadable)
def _done(filenode):
log.msg("webish upload complete")
return d
def _upload_localfile(self, node, localfile, name):
- uploadable = upload.FileName(localfile)
+ uploadable = FileName(localfile)
d = node.add_file(name, uploadable)
d.addCallback(lambda filenode: filenode.get_uri())
return d
# the node must exist, and our operation will be performed on the
# node itself.
d = self.get_child_at_path(path)
- def _got(node):
+ def _got_POST(node):
return POSTHandler(node, replace), ()
- d.addCallback(_got)
+ d.addCallback(_got_POST)
elif method == "DELETE":
# the node must exist, and our operation will be performed on its
# parent node.
assert path # you can't delete the root
d = self.get_child_at_path(path[:-1])
- def _got(node):
+ def _got_DELETE(node):
return DELETEHandler(node, path[-1]), ()
- d.addCallback(_got)
+ d.addCallback(_got_DELETE)
elif method in ("PUT",):
# the node may or may not exist, and our operation may involve
# all the ancestors of the node.
if t == "":
# "PUT /uri", to create an unlinked file. This is like PUT but
# without the associated set_uri.
- uploadable = upload.FileHandle(req.content)
+ uploadable = FileHandle(req.content)
d = IClient(ctx).upload(uploadable)
# that fires with the URI of the new file
return d
if t in ("", "upload"):
# "POST /uri", to create an unlinked file.
fileobj = req.fields["file"].file
- uploadable = upload.FileHandle(fileobj)
+ uploadable = FileHandle(fileobj)
d = IClient(ctx).upload(uploadable)
# that fires with the URI of the new file
return d