예제 #1
0
def stage_infos_from(infos_data: InfosData) -> InfosData:
    assert isinstance(infos_data, InfosData)

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

    tmp = []
    index = 0
    current = None

    tmp.append(get_record_as_splitter())
    tmp.append(get_record_as_data_title('STAGE INFOS'))

    for record in infos_data.get_data():
        assert isinstance(record, InfoRecord)
        if InfoType.ACTION is record.type:
            ret = _record_as_stage_info_from(index, current, record)
            if ret:
                tmp.append(ret)
        elif InfoType.TITLE_EPISODE is record.type:
            tmp.append(_get_record_as_splitter())
        elif InfoType.TITLE_SCENE is record.type:
            index += 1
        elif InfoType.SCENE_HEAD is record.type:
            info = assertion.is_instance(record.note, SceneInfo)
            current = info.stage
        else:
            continue

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

    return InfosData(tmp)
예제 #2
0
파일: adder.py 프로젝트: NovelLab/stobu
def add_story_source(args: Namespace) -> bool:
    assert isinstance(args, Namespace)
    assert has_cmd_of(args, CmdType.ADD)

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

    if not is_enable_elm_in(args, ENABLE_ELMS):
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(data=f"element type in {PROC}"))
        return False

    elm = elm_from(args)
    fname = _get_new_filename(elm, args.option)
    if not fname:
        logger.error(msg.ERR_FAIL_INVALID_DATA)
        return False

    path = filepath_of(elm, fname)
    data = get_template_data(elm)

    if not write_file(path, data):
        logger.error(
            msg.ERR_FAIL_CANNOT_CREATE_DATA.format(
                data=f"new {elm} file in {PROC}"))

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return True
예제 #3
0
def rename_story_source(args: Namespace) -> bool:
    assert isinstance(args, Namespace)
    assert has_cmd_of(args, CmdType.RENAME)
    logger.debug(msg.PROC_START.format(proc=PROC))

    if not is_enable_elm_in(args, ENABLE_ELMS):
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(data=f"element type in {PROC}"))
        return False

    elm = elm_from(args)
    fname = _get_rename_filename(elm, args.option)
    if not fname:
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(
                data=f"delete filename in {PROC}"))
        return False

    newname = _get_renamed_name(elm)
    if not newname:
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(data=f"rename name in {PROC}"))
        return False

    if not _rename_file(elm, fname, newname):
        logger.error(
            msg.ERR_FAIL_CANNOT_REMOVE_DATA.format(
                data=f"rename file in {PROC}"))
        return False

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return True
예제 #4
0
def set_project_data(args: Namespace) -> bool:
    assert isinstance(args, Namespace)
    assert has_cmd_of(args, CmdType.SET)

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

    if not _is_enable_setelm(args):
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(
                data=f"set element type in {PROC}"))
        return False

    elm = _setelm_from(args)
    is_succeeded = False

    if SetElmType.EDITOR is elm:
        is_succeeded = set_editor()
    else:
        logger.warning(
            msg.ERR_FAIL_INVALID_DATA.format(
                data=f"set element type in {PROC}"))

    if not is_succeeded:
        logger.error(msg.ERR_FAIL_SUBPROCESS.format(proc=f"in {PROC}"))
        return False

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return True
예제 #5
0
def knowledge_infos_from(infos_data: InfosData) -> InfosData:
    assert isinstance(infos_data, InfosData)

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

    tmp = []
    index = 0

    tmp.append(get_record_as_splitter())
    tmp.append(get_record_as_data_title('KNOWLEDGE INFOS'))

    for record in infos_data.get_data():
        assert isinstance(record, InfoRecord)
        if InfoType.ACTION is record.type:
            ret = _record_as_knowledge_info_from(index, record)
            if ret:
                tmp.append(ret)
        elif InfoType.TITLE_EPISODE is record.type:
            tmp.append(_get_record_as_splitter())
        elif InfoType.TITLE_SCENE is record.type:
            index += 1
        else:
            continue

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

    return InfosData(tmp)
예제 #6
0
def _base_stage_status_data_from(infos_data: InfosData) -> list:
    assert isinstance(infos_data, InfosData)

    _PROC = f"{PROC}: base stage data"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    tmp = []
    index = 0
    stage = 'None'

    for record in infos_data.get_data():
        assert isinstance(record, InfoRecord)
        if InfoType.ACTION is record.type:
            ret = _record_as_stage_info_from(index, stage, record)
            if ret:
                tmp.append(ret)
        elif InfoType.TITLE_SCENE is record.type:
            index += 1
        elif InfoType.SCENE_HEAD is record.type:
            info = assertion.is_instance(record.note, SceneInfo)
            stage = info.stage
        else:
            continue

    logger.debug(msg.PROC_SUCCESS.format(proc=_PROC))

    return tmp
예제 #7
0
def flag_infos_from(infos_data: InfosData) -> InfosData:
    assert isinstance(infos_data, InfosData)

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

    tmp = []
    index = 0

    tmp.append(get_record_as_splitter())
    tmp.append(get_record_as_data_title('SCENE FLAG INFOS'))

    for record in infos_data.get_data():
        assert isinstance(record, InfoRecord)
        if InfoType.ACTION is record.type:
            continue
        elif InfoType.FLAG_FORESHADOW is record.type:
            tmp.append(_record_as_flag_info_from(record, index, FlagType.FLAG))
        elif InfoType.FLAG_PAYOFF is record.type:
            tmp.append(
                _record_as_flag_info_from(record, index, FlagType.DEFLAG))
        elif InfoType.TITLE_EPISODE is record.type:
            tmp.append(_get_record_as_flag_info_split())
        elif InfoType.TITLE_SCENE is record.type:
            index += 1
        else:
            continue

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

    return InfosData(tmp)
예제 #8
0
def scene_transition_data_from(infos_data: InfosData) -> InfosData:
    assert isinstance(infos_data, InfosData)

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

    tmp = []
    cache = SceneInfo()

    tmp.append(get_record_as_splitter())
    tmp.append(
        InfoRecord(InfoType.DATA_TITLE, ActType.DATA, '## SCENE TRANSITIONS',
                   '', ''))

    for record in infos_data.get_data():
        assert isinstance(record, InfoRecord)
        if InfoType.SCENE_HEAD is record.type:
            tmp.append(_record_of_scene_transition_from(record, cache))
            tmp.append(
                InfoRecord(InfoType.SCENE_TRANSITION, record.act,
                           record.subject, record.outline, record.note))
            cache = record.note
        elif InfoType.TITLE_EPISODE is record.type:
            tmp.append(_get_record_as_transition_split())
        elif InfoType.TITLE_SCENE is record.type:
            continue
        else:
            continue

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

    return InfosData(tmp)
예제 #9
0
파일: pusher.py 프로젝트: NovelLab/stobu
def push_story_source(args: Namespace) -> bool:
    assert isinstance(args, Namespace)
    assert has_cmd_of(args, CmdType.PUSH)

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

    if not is_enable_elm_in(args, ENABLE_ELMS):
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(data=f"element type in {PROC}"))
        return False

    elm = elm_from(args)
    fname = _get_push_filename(elm, args.option)
    if not fname:
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(data=f"push filename in {PROC}"))
        return False

    parent = 'book'

    if ElmType.CHAPTER is not elm:
        parent = _get_push_parent_filename(elm)
        if not parent:
            logger.error(
                msg.ERR_FAIL_INVALID_DATA.format(
                    data=f"push parent filename in {PROC}"))
            return False

    if not _push_file(elm, fname, parent):
        logger.error(
            msg.ERR_FAIL_CANNOT_WRITE_DATA.format(data=f"push file in {PROC}"))
        return False

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return True
예제 #10
0
def actions_data_from(story_data: StoryData, tags: dict) -> ActionsData:
    assert isinstance(story_data, StoryData)
    assert isinstance(tags, dict)

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

    actions = conv_base_action_data_from(story_data)
    if not actions:
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(
                data=f"base action data in {PROC}"))
        return None

    updated = update_actions_data_if_same(actions)
    if not updated or not updated.has_data():
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(
                data=f"update action data in {PROC}"))
        return None

    applied = actions_data_apply_instructions(updated, tags)
    if not applied or not isinstance(applied,
                                     ActionsData) or not applied.has_data():
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(
                data=f"apply action data in {PROC}"))
        return None

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return applied
예제 #11
0
def _base_data_from(actions_data: ActionsData) -> list:
    assert isinstance(actions_data, ActionsData)

    _PROC = f"{PROC}: base data"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    tmp = []
    cache = SceneInfo()

    for record in actions_data.get_data():
        assert isinstance(record, ActionRecord)
        if ActType.DATA is record.type:
            if record.subtype in TITLE_ACTIONS:
                tmp.append(_record_as_title_from(record))
            elif ActDataType.SCENE_CAMERA is record.subtype:
                cache.camera = record.subject
            elif ActDataType.SCENE_STAGE is record.subtype:
                cache.stage = record.subject
            elif ActDataType.SCENE_YEAR is record.subtype:
                cache.year = record.subject
            elif ActDataType.SCENE_DATE is record.subtype:
                cache.date = record.subject
            elif ActDataType.SCENE_TIME is record.subtype:
                cache.time = record.subject
            elif ActDataType.SCENE_START is record.subtype:
                tmp.append(_record_as_scene_head_from(cache.cloned()))
            elif ActDataType.SCENE_END is record.subtype:
                tmp.append(_get_record_as_scene_end())
                cache.reset()
            elif ActDataType.COMMENT is record.subtype:
                tmp.append(_record_as_comment_from(record))
            elif ActDataType.FORESHADOW is record.subtype:
                tmp.append(_record_as_foreshadow_from(record))
            elif ActDataType.PAYOFF is record.subtype:
                tmp.append(_record_as_payoff_from(record))
            elif record.subtype in [ActDataType.BR,
                    ActDataType.PARAGRAPH_START,
                    ActDataType.PARAGRAPH_END,
                    ActDataType.INSTRUCTION]:
                continue
            elif ActDataType.TEXT is record.subtype:
                continue
            else:
                logger.warning(msg.ERR_FAIL_INVALID_DATA.format(data=f"act data type in {PROC}"))
                continue
        elif record.type in NORMAL_ACTIONS:
            tmp.append(_record_as_action_from(record))
        elif ActType.NONE is record.type:
            continue
        elif ActType.SAME is record.type:
            logger.warning(msg.ERR_FAIL_INVALID_DATA.format(data=f"same act type in {PROC}"))
            continue
        else:
            continue

    logger.debug(msg.PROC_SUCCESS.format(proc=_PROC))
    return tmp
예제 #12
0
def _safe_create_directory(dirpath: str) -> bool:
    assert isinstance(dirpath, str)

    if not is_exists_path(dirpath):
        os.makedirs(dirpath)
    else:
        logger.debug(msg.PROC_MESSAGE.format(proc=f"Already exists {dirpath} in {PROC}"))

    return True
예제 #13
0
def _init_commandline_parser() -> ArgumentParser:
    _PROC = "init commandline parser"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    parser = ArgumentParser(
        prog=PROGRAM_NAME,
        description=DESCRIPTION,
    )

    logger.debug(msg.PROC_DONE.format(proc=_PROC))
    return parser
예제 #14
0
def check_and_create_directories() -> bool:
    _PROC = f"{PROC}: check and create dirs"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    for elm, dirpath in DIRS_TABLE.items():
        if dirpath:
            if not _safe_create_directory(dirpath_of(elm)):
                logger.error(msg.ERR_FAIL_CANNOT_CREATE_DATA.format(data=f"{dirpath} in {_PROC}"))
                return False

    logger.debug(msg.PROC_SUCCESS.format(proc=_PROC))
    return True
예제 #15
0
    def run(self) -> int:
        logger.debug(msg.PROC_START.format(proc=PROC))

        args = get_commandline_arguments()

        if not args:
            logger.error(msg.ERR_FAIL_MISSING_DATA.format(data=f"commandline args in {PROC}"))
            return os.EX_NOINPUT

        if has_cmd_of(args, CmdType.INIT):
            if not init_project(args):
                logger.error(msg.ERR_FAIL_CANNOT_INITIALIZE.format(data='project'))
                return os.EX_SOFTWARE
            return os.EX_OK

        is_succeeded = False

        if has_cmd_of(args, CmdType.BUILD):
            is_succeeded = build_project(args)
        elif has_cmd_of(args, CmdType.NONE) or has_cmd_of(args, CmdType.INIT):
            is_succeeded = True
        else:
            if not _is_valid_args(args):
                return os.EX_NOINPUT

            if has_cmd_of(args, CmdType.ADD):
                is_succeeded = add_story_source(args)
            elif has_cmd_of(args, CmdType.COPY):
                is_succeeded = copy_story_source(args)
            elif has_cmd_of(args, CmdType.DELETE):
                is_succeeded = delete_story_source(args)
            elif has_cmd_of(args, CmdType.EDIT):
                is_succeeded = edit_story_source(args)
            elif has_cmd_of(args, CmdType.LIST):
                is_succeeded = show_list_of_story_sources(args)
            elif has_cmd_of(args, CmdType.PUSH):
                is_succeeded = push_story_source(args)
            elif has_cmd_of(args, CmdType.REJECT):
                is_succeeded = reject_story_source(args)
            elif has_cmd_of(args, CmdType.RENAME):
                is_succeeded = rename_story_source(args)
            elif has_cmd_of(args, CmdType.SET):
                is_succeeded = set_project_data(args)
            else:
                logger.error(msg.ERR_FAIL_INVALID_DATA.format(data=f"command type in {PROC}"))

        if not is_succeeded:
            logger.error(msg.ERR_FAILED_PROC.format(proc=PROC))
            return os.EX_SOFTWARE

        logger.debug(msg.PROC_DONE.format(proc=PROC))
        return os.EX_OK
예제 #16
0
def stage_status_info_from(infos_data: InfosData) -> InfosData:
    assert isinstance(infos_data, InfosData)

    _PROC = f"{PROC}: stage status"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    base_data = _base_stage_status_data_from(infos_data)

    reordered = _reorder_each_stages(base_data)

    logger.debug(msg.PROC_SUCCESS.format(proc=_PROC))

    return InfosData(reordered)
예제 #17
0
def outputs_data_from_scripts_data(scripts_data: ScriptsData, tags: dict,
        is_comment: bool = False) -> OutputsData:
    assert isinstance(scripts_data, ScriptsData)
    assert isinstance(tags, dict)

    _PROC = f"{PROC}: convert outputs data"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    formatted = format_scripts_data(scripts_data, is_comment)

    translated = translate_tags_text_list(formatted, tags)

    logger.debug(msg.PROC_SUCCESS.format(proc=_PROC))
    return OutputsData(translated)
예제 #18
0
def novels_data_from(actions_data: ActionsData, tags: dict) -> NovelsData:
    assert isinstance(actions_data, ActionsData)
    assert isinstance(tags, dict)

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

    base_data = _base_novels_data_from(actions_data)

    updated = update_data_tags(base_data, tags)

    eliminated = _eliminate_empty_records(updated)

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return NovelsData(eliminated)
예제 #19
0
def check_and_create_default_files() -> bool:
    _PROC = f"{PROC}: check and create files"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    for elm in BASE_FILES:
        path = filepath_of(elm, BASE_FILE_TABLE[elm])
        if not is_exists_path(path):
            data = get_template_data(elm)
            if not write_file(path, data):
                logger.warning(msg.ERR_FAIL_CANNOT_CREATE_DATA.format(data=f"{str(elm)} in {_PROC}"))
                return False
        else:
            logger.debug(msg.PROC_MESSAGE.format(proc=f"Already exists {str(elm)} file in {PROC}"))
            continue

    for elm in DEFAULT_FILES:
        path = filepath_of(elm, 'main')
        if not is_exists_path(path):
            data = get_template_data(elm)
            if not write_file(path, data):
                logger.warning(msg.ERR_FAIL_CANNOT_CREATE_DATA.format(data=f"{str(elm)} in {_PROC}"))
                return False
        else:
            logger.debug(msg.PROC_MESSAGE.format(proc=f"Already exists {str(elm)} file in {PROC}"))
            continue

    logger.debug(msg.PROC_SUCCESS.format(proc=_PROC))
    return True
예제 #20
0
def serialized_filenames_from_order(order_data: dict, ch_start: int,
                                    ch_end: int, ep_start: int, ep_end: int,
                                    sc_start: int, sc_end: int) -> list:
    assert isinstance(order_data, dict)
    assert isinstance(ch_start, int)
    assert isinstance(ch_end, int)
    assert isinstance(ep_start, int)
    assert isinstance(ep_end, int)
    assert isinstance(sc_start, int)
    assert isinstance(sc_end, int)

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

    if not _is_valid_order_data(order_data):
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(proc=f"order data: {PROC}"))
        return []

    tmp = []
    ch_idx, ep_idx, sc_idx = 0, 0, 0

    for ch_record in assertion.is_list(order_data[str(OrderItem.BOOK)]):
        # in Chapter
        if ch_idx >= ch_start and (ch_idx <= ch_end or ch_end < 0):
            assert isinstance(ch_record, dict)
            for key in ch_record.keys():
                tmp.append(key)
            # in Episode
            for ch_data in ch_record.values():
                assert isinstance(ch_data, list)
                for ep_record in ch_data:
                    if ep_idx >= ep_start and (ep_idx <= ep_end or ep_end < 0):
                        assert isinstance(ep_record, dict)
                        for key in ep_record.keys():
                            tmp.append(key)
                        # in Scene
                        for ep_data in ep_record.values():
                            assert isinstance(ep_data, list)
                            for sc_record in ep_data:
                                if sc_idx >= sc_start and (sc_idx <= sc_end
                                                           or sc_end < 0):
                                    assert isinstance(sc_record, str)
                                    tmp.append(sc_record)
                                sc_idx += 1
                    ep_idx += 1
        ch_idx += 1

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return tmp
예제 #21
0
def outputs_data_from_status_infos_data(infos_data: InfosData, tags: dict,
        is_comment: bool = False) -> OutputsData:
    assert isinstance(infos_data, InfosData)
    assert isinstance(tags, dict)
    assert isinstance(is_comment, bool)

    _PROC = f"INFO STATUS: convert outputs data"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    formatted = format_status_info_data(infos_data, is_comment)

    translated = translate_tags_text_list(formatted, tags)

    logger.debug(msg.PROC_SUCCESS.format(proc=_PROC))
    return OutputsData(translated)
예제 #22
0
파일: structer.py 프로젝트: NovelLab/stobu
def structs_data_from(actions_data: ActionsData, tags: dict) -> StructsData:
    assert isinstance(actions_data, ActionsData)
    assert isinstance(tags, dict)

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

    base_data = _base_structs_data_from(actions_data)

    updated = update_data_tags(base_data, tags)

    data_updated = update_scene_info(updated)

    eliminated = _eliminate_empty_records(data_updated)

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return StructsData(eliminated)
예제 #23
0
def init_project(args: Namespace) -> bool:
    assert isinstance(args, Namespace)
    assert has_cmd_of(args, CmdType.INIT)

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

    if not check_and_create_directories():
        logger.error(msg.ERR_FAIL_SUBPROCESS.format(proc=f"check and create dirs in {PROC}"))
        return False

    if not check_and_create_default_files():
        logger.error(msg.ERR_FAIL_SUBPROCESS.format(proc=f"check and create files in {PROC}"))
        return False

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return True
예제 #24
0
파일: outline.py 프로젝트: NovelLab/stobu
def format_outlines_data(outlines_data: OutlinesData) -> list:
    assert isinstance(outlines_data, OutlinesData)

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

    tmp = []
    current = ElmType.NONE

    for record in outlines_data.get_data():
        assert isinstance(record, OutlineRecord)
        if current is not record.type:
            tmp.append(head_string_from_elm(record.type, 'outlines'))
            current = record.type
        tmp.extend(_conv_output_record(record))

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return tmp
예제 #25
0
def _get_info_data_set(base_data: InfosData) -> InfosData:
    assert isinstance(base_data, InfosData)

    _PROC = f"{PROC}: info data set"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    transitions = scene_transition_data_from(base_data)
    if not transitions or not transitions.has_data():
        logger.warning(msg.ERR_FAIL_INVALID_DATA.format(data=f"transition data in {_PROC}"))
        return None

    flags = flag_infos_from(base_data)
    if not flags or not flags.has_data():
        logger.warning(msg.ERR_FAIL_INVALID_DATA.format(data=f"flag data in {_PROC}"))
        return None

    persons = person_infos_from(base_data)
    if not persons or not persons.has_data():
        logger.warning(msg.ERR_FAIL_INVALID_DATA.format(data=f"person data in {_PROC}"))
        return None

    fashions = fashion_infos_from(base_data)
    if not fashions or not fashions.has_data():
        logger.warning(msg.ERR_FAIL_INVALID_DATA.format(data=f"fashion data in {_PROC}"))
        return None

    knowledges = knowledge_infos_from(base_data)
    if not knowledges or not knowledges.has_data():
        logger.warning(msg.ERR_FAIL_INVALID_DATA.format(data=f"knowledge data in {_PROC}"))
        return None

    stages = stage_infos_from(base_data)
    if not stages or not stages.has_data():
        logger.warning(msg.ERR_FAIL_INVALID_DATA.format(data=f"stage data in {_PROC}"))
        return None

    items = item_infos_from(base_data)
    if not items or not items.has_data():
        logger.warning(msg.ERR_FAIL_INVALID_DATA.format(data=f"item data in {_PROC}"))
        return None

    data_set = transitions + flags + persons + fashions + knowledges + stages + items
    assert isinstance(data_set, InfosData)

    logger.debug(msg.PROC_SUCCESS.format(proc=_PROC))
    return data_set
예제 #26
0
파일: plotter.py 프로젝트: NovelLab/stobu
def outputs_data_from_plots_data(plots_data: PlotsData,
                                 tags: dict) -> OutputsData:
    assert isinstance(plots_data, PlotsData)
    assert isinstance(tags, dict)

    _PROC = f"{PROC}: convert outputs data"
    logger.debug(msg.PROC_START.format(proc=_PROC))

    formatted = format_plots_data(plots_data)
    if not formatted:
        logger.error(
            msg.ERR_FAIL_INVALID_DATA.format(data=f"outputs data in {PROC}"))
        return None

    translated = translate_tags_text_list(formatted, tags)

    logger.debug(msg.PROC_SUCCESS.format(proc=_PROC))
    return OutputsData(translated)
예제 #27
0
def get_commandline_arguments() -> Namespace:
    logger.debug(msg.PROC_START.format(proc=PROC))

    parser = assertion.is_instance(_init_commandline_parser(), ArgumentParser)

    if not parser:
        return None

    if not _set_parser_options(parser):
        logger.warning(msg.ERR_FAIL_SET_DATA.format(data='arg parser options'))
        return None

    args = parser.parse_args()

    if not args:
        return None

    logger.debug(msg.PROC_DONE.format(proc=PROC))
    return args
예제 #28
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
예제 #29
0
def actions_data_apply_instructions(actions_data: ActionsData,
                                    tags: dict) -> ActionsData:
    assert isinstance(actions_data, ActionsData)
    assert isinstance(tags, dict)

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

    tmp = []
    alias = {}

    # TODO: パラグラフはパラグラフのActDataTypeで制御し、インデントやBRはここでは命令分以外は入れない
    for record in actions_data.get_data():
        assert isinstance(record, ActionRecord)
        if ActDataType.INSTRUCTION is record.subtype:
            if record.subject in INST_PARAGRAPH_START:
                tmp.append(_get_record_as_paragraph_start())
            elif record.subject in INST_PARAGRAPH_END:
                tmp.append(_get_record_as_paragraph_end())
            elif record.subject in INST_BREAK:
                tmp.append(_get_record_as_br())
            elif record.subject in INST_ALIAS:
                short, origin = record.outline.split('=')
                alias[short] = origin
            elif record.subject in INST_FORESHADOW:
                tmp.append(_record_as_foreshadow_from(record, tags))
            elif record.subject in INST_PAYOFF:
                tmp.append(_record_as_payoff_from(record, tags))
            else:
                logger.warning(
                    msg.ERR_FAIL_INVALID_DATA.format(
                        data=f"instruction type in {PROC}"))
                continue
        elif ActDataType.SCENE_START is record.subtype:
            alias = {}
            tmp.append(record)
        elif record.type in NORMAL_ACTIONS:
            tmp.append(_conv_shorter_by_alias(record, alias))
        else:
            tmp.append(record)

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return ActionsData(tmp)
예제 #30
0
파일: editor.py 프로젝트: NovelLab/stobu
def edit_story_source(args: Namespace) -> bool:
    assert isinstance(args, Namespace)
    assert has_cmd_of(args, CmdType.EDIT)

    logger.debug(msg.PROC_START.format(proc=PROC))
    if not is_enable_elm_in(args, ENABLE_ELMS):
        logger.error(msg.ERR_FAIL_INVALID_DATA.format(data=f"element type in {PROC}"))
        return False

    elm = elm_from(args)
    fname = _get_edit_filename(elm, args.option)
    if not fname:
        logger.error(msg.ERR_FAIL_INVALID_DATA.format(data=f"copy filename in {PROC}"))
        return False

    if not _edit_file(elm, fname):
        logger.error(msg.ERR_FAIL_SUBPROCESS.format(proc=f"edit {elm} file in {PROC}"))

    logger.debug(msg.PROC_SUCCESS.format(proc=PROC))
    return True