78 lines
2.6 KiB
Python
78 lines
2.6 KiB
Python
import os
|
|
import shutil
|
|
|
|
SRC_DIR = "src"
|
|
HOME_DIR = os.path.expanduser("~")
|
|
|
|
CHOICES = {
|
|
'.config/hypr/monitors.conf': ['.config/hypr/monitors-1.conf', '.config/hypr/monitors-2.conf']
|
|
}
|
|
|
|
|
|
def ask_override(path):
|
|
resp = input(f"'{path}' already exists. Override? (Y/N): ").strip().lower()
|
|
return resp == 'y'
|
|
|
|
|
|
def choice_files(src_root, dst_root, choices_map, override_all=False):
|
|
for final_name, options in choices_map.items():
|
|
existing_options = [f for f in options if os.path.exists(os.path.join(src_root, f))]
|
|
if not existing_options:
|
|
print(f"No source file found among options for {final_name}. Skipping.")
|
|
continue
|
|
|
|
if len(existing_options) == 1:
|
|
chosen = existing_options[0]
|
|
else:
|
|
print(f"Choose which file to copy as '{final_name}':")
|
|
for idx, opt in enumerate(existing_options, 1):
|
|
print(f"{idx}: {opt}")
|
|
while True:
|
|
try:
|
|
choice_idx = int(input(f"Enter number (1-{len(existing_options)}): "))
|
|
if 1 <= choice_idx <= len(existing_options):
|
|
chosen = existing_options[choice_idx - 1]
|
|
break
|
|
except ValueError:
|
|
pass
|
|
print("Invalid choice, try again.")
|
|
|
|
src_file = os.path.join(src_root, chosen)
|
|
dst_file = os.path.join(dst_root, final_name)
|
|
|
|
if os.path.exists(dst_file):
|
|
if not override_all and not ask_override(dst_file):
|
|
print(f"Skipped overriding {dst_file}")
|
|
continue
|
|
|
|
shutil.copy2(src_file, dst_file)
|
|
print(f"Copied {chosen} -> {final_name}")
|
|
|
|
def copy_with_structure(src_root, dst_root, override_all=False):
|
|
for root, dirs, files in os.walk(src_root):
|
|
rel_path = os.path.relpath(root, src_root)
|
|
target_dir = os.path.join(dst_root, rel_path)
|
|
|
|
os.makedirs(target_dir, exist_ok=True)
|
|
|
|
for file in files:
|
|
src_file = os.path.join(root, file)
|
|
dst_file = os.path.join(target_dir, file)
|
|
|
|
if os.path.exists(dst_file):
|
|
if not override_all and not ask_override(dst_file):
|
|
continue
|
|
|
|
shutil.copy2(src_file, dst_file)
|
|
print(f"Copied: {src_file} -> {dst_file}")
|
|
|
|
def main():
|
|
override_all = input('Override all existing files? (Y/N): ').strip().lower() == 'y'
|
|
|
|
choice_files(SRC_DIR, HOME_DIR, CHOICES, override_all)
|
|
|
|
copy_with_structure(SRC_DIR, HOME_DIR, override_all)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|