f.write("contents of %s\n" % filename)
f.close()
- def test_PUT_NEWDIRURL_localdir(self): # NO
+ def walk_mynodes(self, node, path=()):
+ yield path, node
+ if interfaces.IDirectoryNode.providedBy(node):
+ for name in sorted(node.children.keys()):
+ child_uri = node.children[name]
+ childnode = self.nodes[child_uri]
+ childpath = path + (name,)
+ for xpath,xnode in self.walk_mynodes(childnode, childpath):
+ yield xpath, xnode
+
+ def dump_root(self):
+ print "NODEWALK"
+ for path,node in self.walk_mynodes(self.public_root):
+ print path
+
+ def test_PUT_NEWDIRURL_localdir(self): # YES
localdir = os.path.abspath("web/PUT_NEWDIRURL_localdir")
# create some files there
- fileutil.make_dirs(os.path.join(localdir, "web"))
- fileutil.make_dirs(os.path.join(localdir, "web/one"))
- fileutil.make_dirs(os.path.join(localdir, "web/two"))
- fileutil.make_dirs(os.path.join(localdir, "web/three"))
- self.touch(localdir, "web/three/foo.txt")
- self.touch(localdir, "web/three/bar.txt")
- self.touch(localdir, "web/zap.zip")
+ fileutil.make_dirs(os.path.join(localdir, "one"))
+ fileutil.make_dirs(os.path.join(localdir, "one/sub"))
+ fileutil.make_dirs(os.path.join(localdir, "two"))
+ fileutil.make_dirs(os.path.join(localdir, "three"))
+ self.touch(localdir, "three/foo.txt")
+ self.touch(localdir, "three/bar.txt")
+ self.touch(localdir, "zap.zip")
+
d = self.PUT("/vdrive/global/foo/newdir?localdir=%s" % localdir, "")
def _check(res):
self.failUnless("newdir" in self._foo_node.children)
- webnode = self.nodes[self._foo_node.children["newdir"]]
- self.failUnlessEqual(sorted(webnode.children.keys()),
+ newnode = self.nodes[self._foo_node.children["newdir"]]
+ self.failUnlessEqual(sorted(newnode.children.keys()),
sorted(["one", "two", "three", "zap.zip"]))
- threenode = self.nodes[webnode.children["three"]]
+ onenode = self.nodes[newnode.children["one"]]
+ self.failUnlessEqual(sorted(onenode.children.keys()),
+ sorted(["sub"]))
+ threenode = self.nodes[newnode.children["three"]]
self.failUnlessEqual(sorted(threenode.children.keys()),
sorted(["foo.txt", "bar.txt"]))
- barnode = self.nodes[threenode.children["foo.txt"]]
+ barnode = self.nodes[threenode.children["bar.txt"]]
contents = self.files[barnode.get_uri()]
- self.failUnlessEqual(contents, "contents of web/three/bar.txt")
+ self.failUnlessEqual(contents, "contents of three/bar.txt\n")
d.addCallback(_check)
return d
- def test_PUT_NEWDIRURL_localdir_mkdirs(self): # NO
+ def test_PUT_NEWDIRURL_localdir_mkdirs(self): # YES
localdir = os.path.abspath("web/PUT_NEWDIRURL_localdir_mkdirs")
# create some files there
- fileutil.make_dirs(os.path.join(localdir, "web"))
- fileutil.make_dirs(os.path.join(localdir, "web/one"))
- fileutil.make_dirs(os.path.join(localdir, "web/two"))
- fileutil.make_dirs(os.path.join(localdir, "web/three"))
- self.touch(localdir, "web/three/foo.txt")
- self.touch(localdir, "web/three/bar.txt")
- self.touch(localdir, "web/zap.zip")
+ fileutil.make_dirs(os.path.join(localdir, "one"))
+ fileutil.make_dirs(os.path.join(localdir, "one/sub"))
+ fileutil.make_dirs(os.path.join(localdir, "two"))
+ fileutil.make_dirs(os.path.join(localdir, "three"))
+ self.touch(localdir, "three/foo.txt")
+ self.touch(localdir, "three/bar.txt")
+ self.touch(localdir, "zap.zip")
+
d = self.PUT("/vdrive/global/foo/subdir/newdir?localdir=%s" % localdir,
"")
def _check(res):
self.failUnless("subdir" in self._foo_node.children)
subnode = self.nodes[self._foo_node.children["subdir"]]
self.failUnless("newdir" in subnode.children)
- webnode = self.nodes[subnode.children["newdir"]]
- self.failUnlessEqual(sorted(webnode.children.keys()),
+ newnode = self.nodes[subnode.children["newdir"]]
+ self.failUnlessEqual(sorted(newnode.children.keys()),
sorted(["one", "two", "three", "zap.zip"]))
- threenode = self.nodes[webnode.children["three"]]
+ onenode = self.nodes[newnode.children["one"]]
+ self.failUnlessEqual(sorted(onenode.children.keys()),
+ sorted(["sub"]))
+ threenode = self.nodes[newnode.children["three"]]
self.failUnlessEqual(sorted(threenode.children.keys()),
sorted(["foo.txt", "bar.txt"]))
- barnode = self.nodes[threenode.children["foo.txt"]]
+ barnode = self.nodes[threenode.children["bar.txt"]]
contents = self.files[barnode.get_uri()]
- self.failUnlessEqual(contents, "contents of web/three/bar.txt")
+ self.failUnlessEqual(contents, "contents of three/bar.txt\n")
d.addCallback(_check)
return d
if localfile:
d.addCallback(self._upload_localfile, localfile, name)
elif localdir:
+ d.addCallback(self._get_or_create_directories, self._path[-1:])
d.addCallback(self._upload_localdir, localdir)
elif t == "uri":
d.addCallback(self._attach_uri, req.content, name)
return d
def _upload_localdir(self, node, localdir):
+ print "PUTHandler._upload_localdir", localdir
# build up a list of files to upload
all_files = []
all_dirs = []
for root, dirs, files in os.walk(localdir):
- path = tuple(root.split(os.sep))
+ print "walking", root
+ if root == localdir:
+ path = ()
+ else:
+ relative_root = root[len(localdir)+1:]
+ path = tuple(relative_root.split(os.sep))
+ print " path", path
for d in dirs:
all_dirs.append(path + (d,))
for f in files:
return d
def _makedir(self, res, node, dir):
+ print "_makedir", node, dir
d = defer.succeed(None)
# get the parent. As long as os.walk gives us parents before
# children, this ought to work
return d
def _upload_one_file(self, res, node, localdir, f):
+ print "_upload_one_file", node, localdir, f
# get the parent. We can be sure this exists because we already
# went through and created all the directories we require.
- localfile = os.path.join(localdir, f)
+ localfile = os.path.join(localdir, *f)
d = node.get_child_at_path(f[:-1])
d.addCallback(self._upload_localfile, localfile, f[-1])
return d