本文整理汇总了Python中fswrap.Folder.is_descendant_of方法的典型用法代码示例。如果您正苦于以下问题:Python Folder.is_descendant_of方法的具体用法?Python Folder.is_descendant_of怎么用?Python Folder.is_descendant_of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fswrap.Folder
的用法示例。
在下文中一共展示了Folder.is_descendant_of方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_node
# 需要导入模块: from fswrap import Folder [as 别名]
# 或者: from fswrap.Folder import is_descendant_of [as 别名]
def add_node(self, a_folder):
"""
Adds a new node to this folder's hierarchy.
Also adds it to the hashtable of path to node associations
for quick lookup.
"""
folder = Folder(a_folder)
node = self.node_from_path(folder)
if node:
logger.debug("Node exists at [%s]" % node.relative_path)
return node
if not folder.is_descendant_of(self.source_folder):
raise HydeException("The given folder [%s] does not"
" belong to this hierarchy [%s]" %
(folder, self.source_folder))
p_folder = folder
parent = None
hierarchy = []
while not parent:
hierarchy.append(p_folder)
p_folder = p_folder.parent
parent = self.node_from_path(p_folder)
hierarchy.reverse()
node = parent if parent else self
for h_folder in hierarchy:
node = node.add_child_node(h_folder)
self.node_map[str(h_folder)] = node
logger.debug("Added node [%s] to [%s]" % (
node.relative_path, self.source_folder))
return node