Skip to content

comicbox.formats.comet.transform.reprints

CoMet Reprints Transforms.

comet_reprints_transform_from_cb(is_version_of_tag)

Transform reprints to comet is_version_of.

Only the first reprint fits CoMet’s single tag.

Source code in comicbox/formats/comet/transform/reprints.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def comet_reprints_transform_from_cb(is_version_of_tag: str) -> MetaSpec:
    """
    Transform reprints to comet is_version_of.

    Only the first reprint fits CoMet's single tag.
    """

    def from_cb(comicbox_reprints: Any) -> str:
        if not comicbox_reprints:
            return ""
        reprint = comicbox_reprints[0]
        if name := reprint.get(NAME_KEY):
            return str(name)
        filename_dict = glom(reprint, dict(REPRINT_TO_FILENAME_SPECS))
        return dict2comicfn(filename_dict, ext=False) or ""

    return MetaSpec(key_map={is_version_of_tag: REPRINTS_KEY}, spec=from_cb)

comet_reprints_transform_to_cb(is_version_of_tag)

Transform comet is_version_of to reprints.

CoMet allows one isVersionOf, so this reads a single name.

Source code in comicbox/formats/comet/transform/reprints.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def comet_reprints_transform_to_cb(is_version_of_tag: str) -> MetaSpec:
    """
    Transform comet is_version_of to reprints.

    CoMet allows one isVersionOf, so this reads a single name.
    """

    def to_cb(comet_is_version_of: Any) -> list:
        if not comet_is_version_of:
            return []
        name = str(comet_is_version_of)
        # isVersionOf is the reprint's name, so it is stored as one. The
        # parsed fields are enrichment, as they are for MetronInfo.
        filename_dict = comicfn2dict(name)
        reprint = glom(filename_dict, dict(FILENAME_TO_REPRINT_SPECS))
        reprint[NAME_KEY] = name
        return [reprint]

    return MetaSpec(key_map={REPRINTS_KEY: is_version_of_tag}, spec=to_cb)