From: Brian Warner Date: Mon, 4 Dec 2006 11:03:29 +0000 (-0700) Subject: add RIMutableDirectoryNode.get, to get a specific child file or directory X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~466 X-Git-Url: https://git.rkrishnan.org/htmlfontify-example.html?a=commitdiff_plain;h=faf0b13e3c20a14e484271412d56add734bf0cef;p=tahoe-lafs%2Ftahoe-lafs.git add RIMutableDirectoryNode.get, to get a specific child file or directory --- diff --git a/allmydata/filetable.py b/allmydata/filetable.py index bacae680..e93413c1 100644 --- a/allmydata/filetable.py +++ b/allmydata/filetable.py @@ -27,14 +27,6 @@ class MutableDirectoryNode(Referenceable): if name == "." or name == ".." or "/" in name: raise DeadDirectoryNodeError("bad filename component") - # this is private - def get_child(self, name): - self.validate_name(name) - absname = os.path.join(self._basedir, name) - if os.path.isdir(absname): - return self.make_subnode(absname) - raise DeadDirectoryNodeError("no such directory") - # these are the public methods, available to anyone who holds a reference def list(self): @@ -55,6 +47,21 @@ class MutableDirectoryNode(Referenceable): return results remote_list = list + def get(self, name): + self.validate_name(name) + absname = os.path.join(self._basedir, name) + if os.path.isdir(absname): + return self.make_subnode(absname) + elif os.path.isfile(absname): + f = open(absname, "rb") + data = f.read() + f.close() + return data + else: + raise BadFileError("there is nothing named '%s' in this directory" + % name) + remote_get = get + def add_directory(self, name): self.validate_name(name) absname = os.path.join(self._basedir, name) diff --git a/allmydata/interfaces.py b/allmydata/interfaces.py index f7e86b76..672bd908 100644 --- a/allmydata/interfaces.py +++ b/allmydata/interfaces.py @@ -55,6 +55,9 @@ class RIMutableDirectoryNode(RemoteInterface): maxLength=100, ) + def get(name=str): + return (RIMutableDirectoryNode_, Verifierid) + def add_directory(name=str): return RIMutableDirectoryNode_ diff --git a/allmydata/test/test_filetable.py b/allmydata/test/test_filetable.py index 060d0cc7..f72a9d31 100644 --- a/allmydata/test/test_filetable.py +++ b/allmydata/test/test_filetable.py @@ -19,9 +19,15 @@ class FileTable(unittest.TestCase): self.failUnlessRaises(BadFileError, root.remove, "two") self.failUnlessRaises(BadFileError, root.remove, "three") + self.failUnlessEqual(root.get("one"), "vid-one") + self.failUnlessRaises(BadFileError, root.get, "missing") + # now play with directories subdir1 = root.add_directory("subdir1") self.failUnless(isinstance(subdir1, MutableDirectoryNode)) + subdir1a = root.get("subdir1") + self.failUnless(isinstance(subdir1a, MutableDirectoryNode)) + self.failUnlessEqual(subdir1a._basedir, subdir1._basedir) entries = root.list() self.failUnlessEqual(len(entries), 2) one_index = entries.index( ("one", "vid-one") )