Copy a single file or directory.
(
src_path: pathlib.Path,
lib_path: pathlib.Path,
verbose: bool = True,
)
| 17 | |
| 18 | |
| 19 | def _copy_single( |
| 20 | src_path: pathlib.Path, |
| 21 | lib_path: pathlib.Path, |
| 22 | verbose: bool = True, |
| 23 | ) -> None: |
| 24 | """Copy a single file or directory.""" |
| 25 | # Remove existing file/directory |
| 26 | if lib_path.exists(): |
| 27 | if lib_path.is_dir(): |
| 28 | if verbose: |
| 29 | print(f"Removing directory: {lib_path}") |
| 30 | shutil.rmtree(lib_path) |
| 31 | else: |
| 32 | if verbose: |
| 33 | print(f"Removing file: {lib_path}") |
| 34 | lib_path.unlink() |
| 35 | |
| 36 | # Copy |
| 37 | if src_path.is_dir(): |
| 38 | if verbose: |
| 39 | print(f"Copying directory: {src_path} -> {lib_path}") |
| 40 | lib_path.parent.mkdir(parents=True, exist_ok=True) |
| 41 | shutil.copytree(src_path, lib_path) |
| 42 | else: |
| 43 | if verbose: |
| 44 | print(f"Copying file: {src_path} -> {lib_path}") |
| 45 | lib_path.parent.mkdir(parents=True, exist_ok=True) |
| 46 | shutil.copy2(src_path, lib_path) |
| 47 | |
| 48 | |
| 49 | def copy_lib( |