change IVirtualDrive.get_node_at_path to accept either a list or a single slash-separated string

This commit is contained in:
Brian Warner 2007-06-28 17:46:14 -07:00
parent 5854916299
commit efb99078b6
3 changed files with 20 additions and 10 deletions

View File

@ -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.

View File

@ -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

View File

@ -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: