|
28 | 28 | # SUCH DAMAGE.
|
29 | 29 | #
|
30 | 30 |
|
31 |
| -import collections |
| 31 | +import collections.abc |
32 | 32 | import fnmatch
|
33 | 33 | import io
|
34 | 34 | import os
|
@@ -190,31 +190,32 @@ def _glob(self, patfrags: "list[str]", prefix: MtreePath, *, case_sensitive=Fals
|
190 | 190 |
|
191 | 191 | def glob(self, pattern: str, *, case_sensitive=False) -> Iterator[MtreePath]:
|
192 | 192 | if len(pattern) == 0:
|
193 |
| - raise StopIteration() # pytype does not like plain "return" |
| 193 | + return iter([]) |
194 | 194 | head, tail = os.path.split(pattern)
|
195 | 195 | patfrags = [tail]
|
196 | 196 | while head:
|
197 | 197 | head, tail = os.path.split(head)
|
198 | 198 | patfrags.insert(0, tail)
|
199 | 199 | return self._glob(patfrags, MtreePath(), case_sensitive=case_sensitive)
|
200 | 200 |
|
201 |
| - def _walk(self, top, prefix): |
| 201 | + def _walk(self, top, prefix) -> "Iterator[tuple[MtreePath, list[str], list[str]]]": |
202 | 202 | split = self._split_key(top)
|
203 | 203 | if split is not None:
|
204 |
| - return self.children[split[0]]._walk(split[1], prefix / split[0]) |
| 204 | + yield from self.children[split[0]]._walk(split[1], prefix / split[0]) |
205 | 205 | if self.entry is not None and self.entry.attributes["type"] != "dir":
|
206 |
| - raise StopIteration() # pytype does not like plain "return" |
207 |
| - files = [] |
208 |
| - dirs = [] |
| 206 | + return |
| 207 | + files: "list[tuple[str, MtreeSubtree]]" = [] |
| 208 | + dirs: "list[tuple[str, MtreeSubtree]]" = [] |
209 | 209 | for k, v in self.children.items():
|
210 | 210 | if v.entry is not None and v.entry.attributes["type"] != "dir":
|
211 | 211 | files.append((k, v))
|
212 | 212 | else:
|
213 | 213 | dirs.append((k, v))
|
214 |
| - yield (prefix, list([k for k, _ in dirs]), list([k for k, _ in files])) |
215 |
| - return iter([v._walk(MtreePath(), prefix) for _, v in dirs]) |
| 214 | + yield prefix, list([k for k, _ in dirs]), list([k for k, _ in files]) |
| 215 | + for _, v in dirs: |
| 216 | + yield from v._walk(MtreePath(), prefix) |
216 | 217 |
|
217 |
| - def walk(self, top): |
| 218 | + def walk(self, top) -> "Iterator[tuple[MtreePath, list[str], list[str]]]": |
218 | 219 | return self._walk(top, MtreePath())
|
219 | 220 |
|
220 | 221 |
|
@@ -315,6 +316,7 @@ def add_file(
|
315 | 316 | if symlink_dest is not None:
|
316 | 317 | mode = "0755"
|
317 | 318 | else:
|
| 319 | + assert file is not None |
318 | 320 | mode = self.infer_mode_string(file, False)
|
319 | 321 | mode = self._ensure_mtree_mode_fmt(mode)
|
320 | 322 | mtree_path = self._ensure_mtree_path_fmt(path_in_image)
|
@@ -409,7 +411,7 @@ def add_from_mtree(self, mtree_file: "MtreeFile", path: "Union[PurePath, str]",
|
409 | 411 | parent = mtree_path.parent
|
410 | 412 | if parent != mtree_path:
|
411 | 413 | self.add_from_mtree(mtree_file, parent, print_status=print_status)
|
412 |
| - attribs = mtree_file.get(mtree_path).attributes |
| 414 | + attribs = mtree_file._mtree[mtree_path].attributes |
413 | 415 | entry = MtreeEntry(mtree_path, attribs)
|
414 | 416 | if print_status:
|
415 | 417 | if "link" in attribs:
|
@@ -465,15 +467,15 @@ def write(self, output: "Union[io.StringIO,Path,typing.IO]", *, pretend):
|
465 | 467 | output.write("\n")
|
466 | 468 | output.write("# END\n")
|
467 | 469 |
|
468 |
| - def get(self, key): |
| 470 | + def get(self, key) -> Optional[MtreeEntry]: |
469 | 471 | return self._mtree.get(key)
|
470 | 472 |
|
471 | 473 | @property
|
472 |
| - def root(self): |
| 474 | + def root(self) -> MtreeSubtree: |
473 | 475 | return self._mtree
|
474 | 476 |
|
475 | 477 | def glob(self, pattern: str, *, case_sensitive=False) -> Iterator[MtreePath]:
|
476 | 478 | return self._mtree.glob(pattern, case_sensitive=case_sensitive)
|
477 | 479 |
|
478 |
| - def walk(self, top): |
| 480 | + def walk(self, top) -> "Iterator[tuple[MtreePath, list[str], list[str]]]": |
479 | 481 | return self._mtree.walk(top)
|
0 commit comments