本文整理匯總了Python中fswrap.Folder.get_relative_path方法的典型用法代碼示例。如果您正苦於以下問題:Python Folder.get_relative_path方法的具體用法?Python Folder.get_relative_path怎麽用?Python Folder.get_relative_path使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類fswrap.Folder
的用法示例。
在下文中一共展示了Folder.get_relative_path方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Node
# 需要導入模塊: from fswrap import Folder [as 別名]
# 或者: from fswrap.Folder import get_relative_path [as 別名]
#.........這裏部分代碼省略.........
"""
Represents any folder that is processed by hyde
"""
def __init__(self, source_folder, parent=None):
super(Node, self).__init__(source_folder)
if not source_folder:
raise HydeException("Source folder is required"
" to instantiate a node.")
self.root = self
self.module = None
self.site = None
self.source_folder = Folder(str(source_folder))
self.parent = parent
if parent:
self.root = self.parent.root
self.module = self.parent.module if self.parent.module else self
self.site = parent.site
self.child_nodes = []
self.resources = []
def contains_resource(self, resource_name):
"""
Returns True if the given resource name exists as a file
in this node's source folder.
"""
return File(self.source_folder.child(resource_name)).exists
def get_resource(self, resource_name):
"""
Gets the resource if the given resource name exists as a file
in this node's source folder.
"""
if self.contains_resource(resource_name):
return self.root.resource_from_path(
self.source_folder.child(resource_name))
return None
def add_child_node(self, folder):
"""
Creates a new child node and adds it to the list of child nodes.
"""
if folder.parent != self.source_folder:
raise HydeException("The given folder [%s] is not a"
" direct descendant of [%s]" %
(folder, self.source_folder))
node = Node(folder, self)
self.child_nodes.append(node)
return node
def add_child_resource(self, afile):
"""
Creates a new resource and adds it to the list of child resources.
"""
if afile.parent != self.source_folder:
raise HydeException("The given file [%s] is not"
" a direct descendant of [%s]" %
(afile, self.source_folder))
resource = Resource(afile, self)
self.resources.append(resource)
return resource
def walk(self):
"""
Walks the node, first yielding itself then
yielding the child nodes depth-first.
"""
yield self
for child in sorted([node for node in self.child_nodes]):
for node in child.walk():
yield node
def rwalk(self):
"""
Walk the node upward, first yielding itself then
yielding its parents.
"""
x = self
while x:
yield x
x = x.parent
def walk_resources(self):
"""
Walks the resources in this hierarchy.
"""
for node in self.walk():
for resource in sorted([resource for resource in node.resources]):
yield resource
@property
def relative_path(self):
"""
Gets the path relative to the root folder (Content, Media, Layout)
"""
return self.source_folder.get_relative_path(self.root.source_folder)