def copy_files( filepath: Path, ctx: dict, out_dir: str, relative_to: Optional[str] = None ): out_dir = Path(out_dir) if relative_to is not None: new_filepath = Path(out_dir) / filepath.relative_to(relative_to) else: new_filepath = Path(out_dir) / filepath if filepath.is_file(): new_filepath.parent.mkdir(parents=True, exist_ok=True) shutil.copy2(filepath, new_filepath) elif filepath.is_dir(): if new_filepath.exists(): shutil.rmtree(new_filepath) shutil.copytree(filepath, new_filepath) return ctx
def write_text_to_file( filepath: Path, ctx: dict, text: str, out_dir: str, ext: Optional[str] = None, relative_to: Optional[str] = None, ): if relative_to is not None: filepath = filepath.relative_to(relative_to) new_filepath = Path(out_dir) / filepath new_filepath.parent.mkdir(parents=True, exist_ok=True) if ext is not None: new_filepath = new_filepath.with_suffix(ext) with open(new_filepath, "w") as f: f.write(text) return ctx