From: Brian Warner Date: Fri, 29 Jun 2007 00:46:14 +0000 (-0700) Subject: change IVirtualDrive.get_node_at_path to accept either a list or a single slash-separ... X-Git-Tag: allmydata-tahoe-0.4.0~16 X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/file/URI:LIT:krugkidfnzsc4/(%5B%5E?a=commitdiff_plain;h=efb99078b65a51b14d941524beb0d9af63d2fe6f;p=tahoe-lafs%2Ftahoe-lafs.git change IVirtualDrive.get_node_at_path to accept either a list or a single slash-separated string --- diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index af99b727..ba4367f0 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -682,11 +682,17 @@ class IVirtualDrive(Interface): def get_node_at_path(self, path): """Transform a path into an IDirectoryNode or IFileNode. - The path is a list of path-name elements, typically constructed by - doing userpath.split('/') . If the first element of this list is '~', - the rest will be interpreted relative to the local user's private - root directory. Otherwse it will be interpreted relative to the - global public root directory. + The path can either be a single string or a list of path-name + elements. The former is generated from the latter by using + .join('/'). If the first element of this list is '~', the rest will + be interpreted relative to the local user's private root directory. + Otherwse it will be interpreted relative to the global public root + directory. As a result, the following three values of 'path' are + equivalent:: + + '/dirname/foo.txt' + 'dirname/foo.txt' + ['dirname', 'foo.txt'] This method returns a Deferred that fires with the node in question, or errbacks with an IndexError if the target node could not be found. diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index 4733a00e..ec445271 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -313,7 +313,7 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase): def _do_publish_private(self, res): ut = upload.Data(self.data) vdrive0 = self.clients[0].getServiceNamed("vdrive") - d = vdrive0.get_node_at_path(["~"]) + d = vdrive0.get_node_at_path("~") d.addCallback(self.log, "GOT ~") def _got_root(rootnode): d1 = rootnode.create_empty_directory("personal") @@ -350,12 +350,11 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase): def _check_publish2(self, res): # this one uses the path-based API vdrive1 = self.clients[1].getServiceNamed("vdrive") - def get_path(path): - return vdrive1.get_node_at_path(path.split("/")) + get_path = vdrive1.get_node_at_path d = get_path("subdir1") d.addCallback(lambda dirnode: self.failUnless(IDirectoryNode.providedBy(dirnode))) - d.addCallback(lambda res: get_path("subdir1/mydata567")) + d.addCallback(lambda res: get_path("/subdir1/mydata567")) d.addCallback(lambda filenode: filenode.download_to_data()) d.addCallback(lambda data: self.failUnlessEqual(data, self.data)) @@ -371,7 +370,7 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase): # this one uses the path-based API def get_path(path): vdrive0 = self.clients[0].getServiceNamed("vdrive") - return vdrive0.get_node_at_path(path.split("/")) + return vdrive0.get_node_at_path(path) d = get_path("~/personal") def _got_personal(personal): self._personal_node = personal diff --git a/src/allmydata/vdrive.py b/src/allmydata/vdrive.py index cb44d36f..48c3eea4 100644 --- a/src/allmydata/vdrive.py +++ b/src/allmydata/vdrive.py @@ -93,6 +93,11 @@ class VirtualDrive(service.MultiService): def get_node_at_path(self, path, root=None): + if not isinstance(path, (list, tuple)): + assert isinstance(path, (str, unicode)) + if path[0] == "/": + path = path[1:] + path = path.split("/") assert isinstance(path, (list, tuple)) if root is None: