comicbox.box

[docs] package comicbox.box

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
Comic Archive.

Reads and writes metadata via marshmallow schemas.
Reads and writes archive file data.
"""

from types import MappingProxyType

from loguru import logger

from comicbox.box.print import ComicboxPrint


class Comicbox(
    ComicboxPrint,
):
    """
    Represent a comic archive.

    Contains the compressed archive file and its parsed metadata
    """

    _CONFIG_ACTIONS = MappingProxyType(
        {
            "print": ComicboxPrint.print_out,
            "validate": ComicboxPrint.validate,
            "export": ComicboxPrint.export_files,
            "covers": ComicboxPrint.extract_covers,
        }
    )

    def _run_complex_actions(self) -> bool:
        noop = True
        if (self._config.index_from, self._config.index_to) != (None, None):
            self.extract_pages_config()
            noop = False
        if self._config.write or self._config.cbz or self._config.delete_all_tags:
            self.dump()
            noop = False
        return noop

    def run(self) -> None:
        """Perform archive actions."""
        noop = True
        for attr, method in self._CONFIG_ACTIONS.items():
            if getattr(self._config, attr):
                method(self)
                noop = False
        noop &= self._run_complex_actions()
        if self._config.rename:
            self.rename_file()
            noop = False

        if noop:
            logger.warning("No action performed")