Пример #1
0
def get_template_data(elm: ElmType) -> str:
    assert isinstance(elm, ElmType)

    path = _get_filename(elm)
    data = read_file(path)

    if elm in WITH_PLOT:
        plot = read_file(_get_filename(ElmType.PLOT))
        return data.replace('{PLOT}', rid_rn(plot))
    elif ElmType.PROJECT is elm:
        return data.replace('{VERSION}', VERSION).replace('{EDITOR}', DEFAULT_EDITOR)
    else:
        return data
Пример #2
0
def _get_data_from(elm: ElmType, fname: str) -> dict:
    assert isinstance(elm, ElmType)
    assert isinstance(fname, str)

    raw_data = read_file(filepath_of(elm, fname))

    if ElmType.BOOK is elm:
        return read_yaml_data(raw_data)
    else:
        return read_markdown_data_as_yaml(raw_data)
Пример #3
0
def _append_tag(data: dict, elm: ElmType, path: str) -> bool:
    assert isinstance(data, dict)
    assert isinstance(elm, ElmType)
    assert isinstance(path, str)

    elm_data = read_markdown_data_as_yaml(read_file(path))
    val = elm_data[str(TAG_VALUE_ELMS[elm])]
    with_prefix = f"{TAG_PREFIX_ELMS[elm]}_{basename_of(path)}"

    return _append_key_and_value(data, basename_of(path), val) \
            or _append_key_and_value(data, with_prefix, val)
Пример #4
0
def person_item_of(fname: str, item: PersonItem) -> Any:
    assert isinstance(fname, str)
    assert isinstance(item, PersonItem)

    data = read_markdown_data_as_yaml(
        read_file(filepath_of(ElmType.PERSON, fname)))
    if str(item) in data:
        return data[str(item)]
    else:
        logger.warning(
            msg.ERR_FAIL_INVALID_DATA.format(data=f"{item} in {PROC}"))
        return ""
Пример #5
0
def _append_person_fullname(data: dict, path: str) -> bool:
    assert isinstance(data, dict)
    assert isinstance(path, str)

    elm_data = read_markdown_data_as_yaml(read_file(path))
    basetag = basename_of(path)
    name = elm_data[str(PersonItem.NAME)]
    fullname = elm_data[str(PersonItem.FULLNAE)]
    last, first = fullname.split(',') if ',' in fullname else ('', name)

    return _append_key_and_value(data, f"fn_{basetag}", first) \
            and _append_key_and_value(data, f"ln_{basetag}", last) \
            and _append_key_and_value(data, f"full_{basetag}", f"{last}{first}") \
            and _append_key_and_value(data, f"efull_{basetag}", f"{first}・{last}")
Пример #6
0
def get_basefile_data(elm: ElmType) -> dict:
    assert isinstance(elm, ElmType)

    if not elm in BASE_FILES:
        logger.warning(
            msg.ERR_FAIL_INVALID_DATA.format(data=f"element type in {PROC}"))
        return {}

    data = read_file(filepath_of(elm, ''))

    if EXT_TABLE[elm] is MARKDOWN_EXT:
        return read_markdown_data_as_yaml(data)
    else:
        return read_yaml_data(data)
Пример #7
0
def story_data_from(args: Namespace) -> StoryData:
    assert isinstance(args, Namespace)

    logger.debug(msg.PROC_START.format(proc=PROC))

    order_data = read_yaml_data(read_file(filepath_of(ElmType.ORDER, '')))

    if not order_data:
        logger.error(
            msg.ERR_FAIL_MISSING_DATA.format(data=f"order data in {PROC}"))
        return None

    elmpart = assertion.is_instance(
        _get_elm_part(args.part if args.part else ""), ElmPart)

    serialized = assertion.is_list(
        serialized_filenames_from_order(
            order_data,
            elmpart.chapter[0],
            elmpart.chapter[1],
            elmpart.episode[0],
            elmpart.episode[1],
            elmpart.scene[0],
            elmpart.scene[1],
        ))

    if not serialized:
        logger.error(
            msg.ERR_FAIL_MISSING_DATA.format(
                data=f"serialized data in {PROC}"))
        return None

    story_data_base = _conv_story_data_from(serialized)
    if not story_data_base:
        logger.error(
            msg.ERR_FAIL_MISSING_DATA.format(
                data=f"story data base in {PROC}"))
        return None

    updated = update_story_data_if_same_or_next_tag(StoryData(story_data_base))

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return updated
Пример #8
0
def _get_project_raw_data() -> dict:
    data = read_file(filepath_of(ElmType.PROJECT, ''))
    return yaml.safe_load(data)
Пример #9
0
def get_time_data() -> dict:
    return read_yaml_data(read_file(filepath_of(ElmType.TIME, '')))
Пример #10
0
def get_person_data(fname: str) -> dict:
    assert isinstance(fname, str)

    return read_markdown_data_as_yaml(
        read_file(filepath_of(ElmType.PERSON, fname)))
Пример #11
0
def get_order_data() -> dict:
    data = read_file(filepath_of(ElmType.ORDER, ''))
    return read_yaml_data(data)[str(OrderItem.BOOK)]
Пример #12
0
def get_mob_data() -> dict:
    return read_yaml_data(read_file(filepath_of(ElmType.MOB, '')))
Пример #13
0
def get_order_data() -> dict:
    data = read_file(filepath_of(ElmType.ORDER, ''))

    return yaml.safe_load(data)