Generic function to copy files or directories.
(source_path, dest_path, item_name, create_dest_dir=False)
| 72 | |
| 73 | |
| 74 | def copy_item(source_path, dest_path, item_name, create_dest_dir=False): |
| 75 | """Generic function to copy files or directories.""" |
| 76 | if not source_path.exists(): |
| 77 | print(f"Warning: {item_name} not found at {source_path}") |
| 78 | return True |
| 79 | |
| 80 | try: |
| 81 | if create_dest_dir: |
| 82 | dest_path.mkdir(parents=True, exist_ok=True) |
| 83 | |
| 84 | if source_path.is_file(): |
| 85 | shutil.copy2(source_path, dest_path) |
| 86 | elif source_path.is_dir(): |
| 87 | if dest_path.exists(): |
| 88 | # Copy contents into existing directory |
| 89 | for item in source_path.iterdir(): |
| 90 | if item.is_file(): |
| 91 | shutil.copy2(item, dest_path) |
| 92 | elif item.is_dir(): |
| 93 | shutil.copytree(item, dest_path / item.name) |
| 94 | else: |
| 95 | # Copy entire directory |
| 96 | shutil.copytree(source_path, dest_path) |
| 97 | |
| 98 | print(f"✓ Copied {item_name} to sandbox") |
| 99 | return True |
| 100 | except Exception as e: |
| 101 | print(f"Error copying {item_name}: {e}") |
| 102 | return False |
| 103 | |
| 104 | |
| 105 | def copy_project_contents(task_name, variant): |
no outgoing calls
no test coverage detected