返回 ppt-master
slide_roster.py
根目录 / skills / ppt-master / scripts / slide_roster.py
1 #!/usr/bin/env python3
2 """
3 PPT Master - Slide Roster Helpers
4
5 Orders slide SVG filenames by numeric segments for consistent page rosters.
6
7 Usage:
8 Imported by export, validation, preview, animation, and narration tools.
9
10 Examples:
11 discover_slide_svgs(Path("projects/demo/svg_output"))
12
13 Dependencies:
14 None (only uses standard library)
15 """
16
17 from __future__ import annotations
18
19 import re
20 from pathlib import Path
21
22
23 _NUMBER_RE = re.compile(r"(\d+)")
24
25
26 def _slide_filename_sort_key(
27 path: Path,
28 ) -> tuple[tuple[tuple[int, int | str], ...], str]:
29 """Order numeric filename segments by value, then break ties by name."""
30 name = path.name
31 folded = name.casefold()
32 segments = tuple(
33 (0, int(segment)) if segment.isdigit() else (1, segment)
34 for segment in _NUMBER_RE.split(folded)
35 )
36 return segments, name
37
38
39 def discover_slide_svgs(directory: Path) -> list[Path]:
40 """Return direct child SVG files in numeric filename order."""
41 return sorted(
42 directory.glob("*.svg"),
43 key=_slide_filename_sort_key,
44 )
45
45 lines PYTHON