本文整理匯總了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