photon_platform.clerk.viewer.files¶
High-speed media file discovery, stdin parsing, and repo CSS detection.
Attributes¶
Functions¶
|
Classify a file path by supported media extension. |
|
Locate a sibling raster image matching an SVG's stem (e.g. facsimile PNG). |
|
Walk upward from |
|
Parse newline-delimited (or NUL-delimited) file paths from a stream. |
|
Discover and index supported SVG and raster media files. |
|
Construct indexed |
Module Contents¶
- photon_platform.clerk.viewer.files.classify_extension(path: pathlib.Path) photon_platform.clerk.viewer.models.MediaKind | None¶
Classify a file path by supported media extension.
- Parameters:
path – Filesystem path to inspect.
- Returns:
"svg","raster", orNoneif unsupported.
- photon_platform.clerk.viewer.files.find_paired_raster(svg_path: pathlib.Path) pathlib.Path | None¶
Locate a sibling raster image matching an SVG’s stem (e.g. facsimile PNG).
Checks the SVG’s own directory first, then falls back to the mirrored
resources/directory for PHOTON/GEOMETOR Book Codexdocsrc/layouts.- Parameters:
svg_path – Path to an
.svgor.svgzfile.- Returns:
Matching sibling raster
Path, orNoneif none exists.
- photon_platform.clerk.viewer.files.find_repo_css(item_path: pathlib.Path, *, cache: dict[pathlib.Path, pathlib.Path | None] | None = None) pathlib.Path | None¶
Walk upward from
item_pathto discover repo-localcustom.css.Looks for
docsrc/_static/css/custom.cssor_static/css/custom.cssup to the nearest repository boundary (.git) or filesystem root.- Parameters:
item_path – File or directory path inside a repository.
cache – Optional directory-to-CSS cache to avoid repeated stat calls.
- Returns:
Path to discovered
custom.css, orNone.
- photon_platform.clerk.viewer.files.parse_stdin_paths(stream: TextIO) list[str]¶
Parse newline-delimited (or NUL-delimited) file paths from a stream.
- Parameters:
stream – Readable text stream (typically
sys.stdin).- Returns:
Ordered list of stripped non-empty path strings.
- photon_platform.clerk.viewer.files.discover_items(paths: collections.abc.Sequence[str] = (), *, recursive: bool = False, from_stdin: bool = False, stdin_stream: TextIO | None = None, base_dir: pathlib.Path | None = None) list[photon_platform.clerk.viewer.models.MediaItem]¶
Discover and index supported SVG and raster media files.
Preserves explicit file ordering from
argvandstdin, naturally sorts directory scans, skips VCS/build directories during recursive traversal, and deduplicates resolved paths.- Parameters:
paths – Positional CLI file/directory arguments (
"-"triggers stdin).recursive – Whether to descend recursively into directories.
from_stdin – Read additional newline-delimited paths from
stdin_stream.stdin_stream – Stream to read when
from_stdinor"-"is active.base_dir – Base working directory for relative display names.
- Returns:
Indexed list of
MediaItementries.
- photon_platform.clerk.viewer.files.build_items_from_paths(resolved_paths: collections.abc.Iterable[str | pathlib.Path], *, base_dir: pathlib.Path | None = None) list[photon_platform.clerk.viewer.models.MediaItem]¶
Construct indexed
MediaItemobjects from pre-resolved paths.Useful for the warm daemon receiving an already-expanded item list.
- Parameters:
resolved_paths – Iterable of file paths.
base_dir – Base directory for relative display strings.
- Returns:
Indexed list of
MediaItemobjects.