Return list of dicts: each has line ranges for in-place edit.
(path: Path)
| 64 | |
| 65 | |
| 66 | def parse_entries(path: Path) -> list[dict]: |
| 67 | """Return list of dicts: each has line ranges for in-place edit.""" |
| 68 | text = path.read_text(encoding="utf-8") |
| 69 | lines = text.split("\n") |
| 70 | entries: list[dict] = [] |
| 71 | current: dict | None = None |
| 72 | for idx, line in enumerate(lines): |
| 73 | if line.startswith(" - id:"): |
| 74 | if current is not None: |
| 75 | current["end_line"] = idx - 1 |
| 76 | entries.append(current) |
| 77 | m = ENTRY_START_RE.match(line) |
| 78 | current = {"start_line": idx, "fields": {}, "field_lines": {}, "raw": lines} |
| 79 | current["fields"]["id"] = m.group(1).strip() |
| 80 | current["field_lines"]["id"] = idx |
| 81 | continue |
| 82 | if current is None: |
| 83 | continue |
| 84 | m = FIELD_RE.match(line) |
| 85 | if m: |
| 86 | key, val = m.group(1), m.group(2) |
| 87 | current["fields"][key] = yaml_decode(val) |
| 88 | current["field_lines"][key] = idx |
| 89 | if current is not None: |
| 90 | current["end_line"] = len(lines) - 1 |
| 91 | entries.append(current) |
| 92 | return entries |
| 93 | |
| 94 | |
| 95 | def write_archive_url(path: Path, entry: dict, archive_url: str) -> None: |
no test coverage detected