def resource_walk(package_or_requirement, resource_name):
"""Generate the file names in a resource tree.
Parameters
----------
package_or_requirement : str or Requirement
Package or requirement that contains the resource.
resource_name : str
Name of the resource.
Returns
-------
tuple
For each directory in the tree rooted at the given resoruce a 3-tuple
``(dirpath, dirnames, filenames)`` is returned. *dirpath* is a string,
the path to the directory starting with *resource_name*. *dirnames* is
a list of the names of subdirectories in *dirpath*. *filenames* is a
list of names of non-directory files in *dirpath*.
"""
queue = [resource_name]
while len(queue) > 0:
dirpath = queue.pop()
dirnames = []
filenames = []
for name in resource_listdir(package_or_requirement, dirpath):
fullpath = os.path.join(dirpath, name)
if resource_isdir(package_or_requirement, fullpath):
dirnames.append(name)
queue.append(fullpath)
else:
filenames.append(name)
yield dirpath, dirnames, filenames
评论列表
文章目录