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
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
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
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