import os
import shutil
import filecmp
def compare_files(file1, file2):
try:
return filecmp.cmp(file1, file2, shallow=False)
except:
return False
def sync_directory(src_dir, dst_dir):
operations = []
conflicts = []
for root, dirs, files in os.walk(src_dir):
rel_path = os.path.relpath(root, src_dir)
if rel_path == ".":
rel_path = ""
dst_root = os.path.join(dst_dir, rel_path)
if not os.path.exists(dst_root):
os.makedirs(dst_root, exist_ok=True)
operations.append(f"CREATED DIR: {dst_root}")
for file in files:
src_file = os.path.join(root, file)
dst_file = os.path.join(dst_root, file)
if os.path.exists(dst_file):
if compare_files(src_file, dst_file):
new_name = file.replace(".rs", ".new.rs")
new_src_file = os.path.join(root, new_name)
shutil.move(src_file, new_src_file)
operations.append(
f"RENAMED (identical): {src_file} -> {new_src_file}"
)
else:
new_name = file.replace(".rs", ".new.rs")
new_src_file = os.path.join(root, new_name)
shutil.move(src_file, new_src_file)
operations.append(
f"RENAMED (different): {src_file} -> {new_src_file}"
)
else:
shutil.copy2(src_file, dst_file)
operations.append(f"COPIED: {src_file} -> {dst_file}")
return operations, conflicts
def main():
src_dir = os.path.abspath(
os.path.join("..", "..", "..", "async-openai", "async-openai", "src")
)
dst_dir = os.path.abspath(
os.path.join("..", "..", "outfox", "crates", "openai", "src")
)
print("=== Step 3: Syncing files ===")
print(f"Source: {src_dir}")
print(f"Destination: {dst_dir}")
if not os.path.exists(src_dir):
print(f"Error: Source directory {src_dir} not found")
return
if not os.path.exists(dst_dir):
print(f"Note: Destination directory {dst_dir} doesn't exist, will be created")
os.makedirs(dst_dir, exist_ok=True)
operations, conflicts = sync_directory(src_dir, dst_dir)
print("\n=== Operations ===")
for op in operations:
print(f" {op}")
print(f"\n=== Summary ===")
print(f"Operations performed: {len(operations)}")
print(f"Conflicts: {len(conflicts)}")
if conflicts:
print("\nConflicts:")
for conflict in conflicts:
print(f" {conflict}")
if __name__ == "__main__":
main()