in scripts/merge_local_staging.py [0:0]
def copy_and_append_index(target, source):
for src_dir in source.iterdir():
if src_dir.is_dir():
dst_dir = target / src_dir.name
dst_dir.mkdir(parents=True, exist_ok=True)
src_path = src_dir / ".index"
dst_path = dst_dir / ".index"
if src_path.exists():
with src_path.open("r") as src, dst_path.open("a") as dst:
print(f"Appending {src_path} to {dst_path}")
dst.write(src.read())
for item in src_dir.iterdir():
if item.name != ".index": # Avoid copying the .index file twice
print(f"Copying {item} to {dst_dir}")
if item.is_dir():
shutil.copytree(item, dst_dir / item.name, dirs_exist_ok=True)
else:
shutil.copy2(item, dst_dir / item.name)