From 05c1191be29c78454c3487999cad4ffa5e834741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Thu, 8 Aug 2024 13:01:33 +0200 Subject: [PATCH] feat: goog sync --- common/sync.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/common/sync.py b/common/sync.py index 85dd0dc..40119d1 100644 --- a/common/sync.py +++ b/common/sync.py @@ -1,2 +1,31 @@ +from glob import glob +import shutil +import os + def sync(stuff: list[str]): + for pattern in stuff: + normalized_pattern = pattern.removeprefix("~") + normalized_pattern = normalized_pattern.removeprefix("/") + pattern_prefix = pattern[:2] if pattern.startswith("~") else pattern[0] + overwrite = False + + for path in glob(normalized_pattern, recursive=True): + + system_path = os.path.expanduser(pattern_prefix + path) + if os.path.isdir(path): + os.makedirs(system_path, exist_ok=True) + else: + print(f"Copying {path} to {system_path}") + if os.path.exists(system_path) and not overwrite: + print(f"Path {system_path} already exists. Do you want to overwrite it with {path}? y/n/a") + + ask = input() + if ask not in ("y", "a"): + continue + + overwrite = ask == "a" + + shutil.copy2(path, system_path) + + exit(1)