dotfiles/common/dump.py

24 lines
683 B
Python
Raw Normal View History

2024-08-08 12:28:10 +02:00
from glob import glob
import shutil
2024-08-08 12:31:06 +02:00
import os
2024-08-08 12:28:10 +02:00
def dump(stuff: list[str]):
for pattern in stuff:
2024-08-08 12:31:06 +02:00
expand = os.path.expanduser(pattern)
2024-08-08 12:28:10 +02:00
for path in glob(expand, recursive=True):
2024-08-08 12:31:06 +02:00
normalized_path = path.removeprefix(os.path.expanduser("~/"))
if os.path.isdir(path):
if os.path.exists(normalized_path):
shutil.rmtree(normalized_path)
os.makedirs(normalized_path)
else:
dirname = os.path.dirname(normalized_path)
if dirname:
os.makedirs(dirname, exist_ok=True)
2024-08-08 12:28:10 +02:00
shutil.copy2(path, normalized_path)
2024-08-07 22:46:13 +02:00
exit(1)