def create_default_files(cls) -> bool: dir_asset = os.path.join(DIR_PROJECT, DEFAULT_ASSET_DIR) dir_src = os.path.join(DIR_PROJECT, DEFAULT_SRC_DIR) dir_temp = os.path.join(DIR_PROJECT, DEFAULT_TEMP_DIR) for fname in SAMPLE_DATA: _fname = add_extention(fname, EXT_YAML) data_path = os.path.join(DIR_EXAMPLE, _fname) data = read_file(data_path) path = os.path.join(dir_asset, _fname) if is_exists_path(path): logger.debug( msg.PROC_MESSAGE.format(proc=f"Already exists {path}")) continue if write_file(path, data): logger.debug(msg.PROC_MESSAGE.format(proc=f"Create {path}")) else: logger.warning( msg.ERR_FAIL_CANNOT_WRITE_DATA.format(data=f"{path}")) return False for fname in SAMPLE_SRC: _fname = add_extention(fname, EXT_MARKDOWN) data_path = os.path.join(DIR_EXAMPLE, _fname) data = read_file(data_path) path = os.path.join(dir_src, _fname) if is_exists_path(path): logger.debug( msg.PROC_MESSAGE.format(proc=f"Already exists {path}")) continue if write_file(path, data): logger.debug(msg.PROC_MESSAGE.format(proc=f"Create {path}")) else: logger.warning( msg.ERR_FAIL_CANNOT_WRITE_DATA.format(data=f"{path}")) return False for fname in TEMP_FILES: data_path = os.path.join(DIR_TEMP, fname) data = read_file(data_path) path = os.path.join(dir_temp, fname) if write_file(path, data): logger.debug(msg.PROC_MESSAGE.format(proc=f"Create {path}")) else: logger.warning( msg.ERR_FAIL_CANNOT_WRITE_DATA.format(data=f"{path}")) return False return True
def create_common_files(cls) -> bool: dir_asset = os.path.join(DIR_PROJECT, DEFAULT_ASSET_DIR) dir_common = os.path.join(dir_asset, DEFAULT_COMMON) for fname in COMMON_FILES: _fname = add_extention(fname, EXT_YAML) data_path = os.path.join(DIR_COMMON, _fname) data = read_file(data_path) path = os.path.join(dir_common, _fname) if is_exists_path(path): logger.debug( msg.PROC_MESSAGE.format(proc=f"Already exists {path}")) continue if write_file(path, data): logger.debug(msg.PROC_MESSAGE.format(proc=f"Create {path}")) else: logger.warning( msg.ERR_FAIL_CANNOT_WRITE_DATA.format(data=f"{path}")) return False return True
def _get_build_path(fname: str) -> str: assert isinstance(fname, str) dir_name = os.path.join(DIR_PROJECT, DIR_BUILD_NAME) return os.path.join(dir_name, add_extention(fname, EXT_MARKDOWN))
'word', 'rubi', ] SAMPLE_SRC = [ 'main', ] SAMPLE_DATA = [ 'taro', 'hana', 'Classroom', ] TEMP_FILES = [ add_extention('scene', EXT_MARKDOWN), add_extention('person', EXT_YAML), add_extention('item', EXT_YAML), add_extention('stage', EXT_YAML), ] # Main def init_project() -> bool: logger.debug(msg.PROC_START.format(proc=PROC)) if not DirCreator.create_default_dirs(): return False if not FileCreator.create_base_project_files():
def test_add_extention(fname, ext, expect): assert add_extention(fname, ext) == expect