def subindex(self, *path):
"""
Returns an `IndexFile` object listing only those files in or below the
directory given by ``*path``. The path keys in the resulting object
will be relative to ``*path``.
``*path`` may be any relative path specification accepted by
`PurePath.relative_to`, such as a string (e.g., ``"main"`` or
``"main/binary-amd64"``), a sequence of strings (e.g., ``"main",
"binary-amd64"``), or a `PurePosixPath` object.
"""
### TODO: Add an option for also updating the `filename` attributes of
### the IndexEntries?
### TODO: Add an option for controlling whether to keep `fields`?
subfiles = {}
for p, entry in self.files.items():
pathobj = PurePosixPath(p)
### TODO: Handle absolute paths and paths beginning with .. (or .?)
try:
subpath = pathobj.relative_to(*path)
except ValueError:
pass
else:
subfiles[str(subpath)] = entry
return type(self)(files=subfiles, fields=self.fields.copy())
评论列表
文章目录