Skip to content

comicbox.config.paths

Configure for paths.

clean_paths(config)

No null paths. Turn off options for no paths.

Source code in comicbox/config/paths.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def clean_paths(config: Subview) -> None:
    """No null paths. Turn off options for no paths."""
    paths: Iterable[str | Path] | None = config["paths"].get()
    paths_removed = False
    if paths:
        filtered_paths = set()
        for path in paths:
            if not path:
                continue
            if Path(path).is_dir() and not config["general"]["recurse"].get(bool):
                logger.warning(f"{path} is a directory. Ignored without --recurse.")
                paths_removed = True
                continue
            filtered_paths.add(path)
        paths = tuple(sorted(filtered_paths))
    if paths or paths_removed:
        if not paths:
            logger.error("No valid paths left.")
        final_paths = paths
    else:
        final_paths = _SINGLE_NO_PATH
    config["paths"].set(final_paths)

expand_glob_paths(paths)

Expand glob paths into a tuple of real paths.

Source code in comicbox/config/paths.py
131
132
133
134
135
136
137
138
139
140
141
142
def expand_glob_paths(paths: Sequence[str | Path] | None) -> tuple[Path, ...]:
    """Expand glob paths into a tuple of real paths."""
    if not paths:
        return ()
    expanded_paths: set[Path] = set()
    for path in paths:
        path_str = str(path)
        if "*" in path_str:
            expanded_paths |= {Path(expanded_path) for expanded_path in glob(path_str)}  # noqa: PTH207
        else:
            expanded_paths.add(Path(path))
    return tuple(sorted(expanded_paths))

post_process_set_for_path(settings, path, *, box)

Turn off options and warn if no path.

Source code in comicbox/config/paths.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def post_process_set_for_path(
    settings: ComicboxSettings, path: str | Path | None, *, box: bool
) -> ComicboxSettings:
    """Turn off options and warn if no path."""
    if path or not box:
        return settings
    changes, need_file_opts = _no_path_changes(settings)
    if need_file_opts:
        plural = "s" if len(need_file_opts) > 1 else ""
        opts = ", ".join(need_file_opts)
        logger.warning(
            f"Cannot perform action{plural} '{opts}' without an archive path."
        )
    return replace(settings, **changes) if changes else settings