Skip to content

comicbox.config.formats ΒΆ

Transform config format keys to MetadataFormats.

split_keep(keys) ΒΆ

Take the keep keyword out of format keys; say whether it was there.

Source code in comicbox/config/formats.py
95
96
97
98
99
def split_keep(keys: Iterable[Any]) -> tuple[list[str], bool]:
    """Take the ``keep`` keyword out of format keys; say whether it was there."""
    stripped = [str(key).strip() for key in keys]
    formats = [key for key in stripped if key.lower() != KEEP_KEYWORD]
    return formats, len(formats) != len(stripped)

transform_keys_to_formats(config) ΒΆ

Transform schema config keys to format enums.

Source code in comicbox/config/formats.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
def transform_keys_to_formats(config: Subview) -> None:
    """Transform schema config keys to format enums."""
    if config["write"]["delete_all_tags"].get(bool):
        config["read"]["formats"].set(frozenset())
        config["write"]["formats"].set(frozenset())
        # Deleting all tags wins over keeping them. Set either way: the key
        # has no default in the YAML, and compute_config reads it.
        config["write"]["keep_formats"].set(False)
        config["convert"]["export_formats"].set(frozenset())
        return

    read_fmts = _resolve_formats(config["read"]["formats"], "read")
    read_except = config["read"]["except"].get()
    if read_except and (
        except_fmts := _resolve_formats(config["read"]["except"], "read-except")
    ):
        read_fmts -= except_fmts
    config["read"]["formats"].set(read_fmts)

    write_keys, keep = split_keep(_raw_or_empty(config["write"]["formats"]))
    config["write"]["formats"].set(write_keys)
    write_fmts = _resolve_formats(config["write"]["formats"], "write")
    config["write"]["formats"].set(write_fmts)
    # Only the keyword sets it, whatever a config file says.
    config["write"]["keep_formats"].set(keep)

    export_fmts = _resolve_formats(
        config["convert"]["export_formats"], "convert.export_formats"
    )
    config["convert"]["export_formats"].set(export_fmts)