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.
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")
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))
# 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
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: