本文整理汇总了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)