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
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)
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)
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 ""
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}")
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)
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
def _get_project_raw_data() -> dict: data = read_file(filepath_of(ElmType.PROJECT, '')) return yaml.safe_load(data)
def get_time_data() -> dict: return read_yaml_data(read_file(filepath_of(ElmType.TIME, '')))
def get_person_data(fname: str) -> dict: assert isinstance(fname, str) return read_markdown_data_as_yaml( read_file(filepath_of(ElmType.PERSON, fname)))
def get_order_data() -> dict: data = read_file(filepath_of(ElmType.ORDER, '')) return read_yaml_data(data)[str(OrderItem.BOOK)]
def get_mob_data() -> dict: return read_yaml_data(read_file(filepath_of(ElmType.MOB, '')))
def get_order_data() -> dict: data = read_file(filepath_of(ElmType.ORDER, '')) return yaml.safe_load(data)