Optimized show logic

This commit is contained in:
Kevin Veen-Birkenbach 2023-11-14 12:56:24 +01:00
parent f854e46511
commit 9e815c6854
2 changed files with 36 additions and 2 deletions

34
create_file_structure.py Normal file
View File

@ -0,0 +1,34 @@
import os
import shutil
import hashlib
import random
import string
def create_test_directory(base_dir, num_files=5, duplicate_files=2, depth=1):
os.makedirs(base_dir, exist_ok=True)
subdirs = [os.path.join(base_dir, f"subdir_{i}") for i in range(depth)]
for subdir in subdirs:
os.makedirs(subdir, exist_ok=True)
for dir in [base_dir] + subdirs:
file_names = [f"file_{i}.txt" for i in range(num_files)]
for file_name in file_names:
with open(os.path.join(dir, file_name), 'w') as f:
content = ''.join(random.choices(string.ascii_lowercase, k=20))
f.write(content)
for i in range(min(duplicate_files, num_files)):
original = os.path.join(dir, file_names[i])
for dup_num in range(1, duplicate_files+1):
duplicate = os.path.join(dir, f"dup_{dup_num}_{file_names[i]}")
shutil.copyfile(original, duplicate)
def create_file_structure(depth, num_files, duplicate_files):
base_dirs = ['test_dir1', 'test_dir2']
for base_dir in base_dirs:
create_test_directory(base_dir, num_files, duplicate_files, depth)
print("Test file structure created.")
if __name__ == "__main__":
create_file_structure(depth=2, num_files=5, duplicate_files=3)

View File

@ -42,7 +42,7 @@ def handle_modification(files, modification, mode, apply_to):
for duplicate_file in files:
if duplicate_file != original_file:
if duplicate_file.startswith(tuple(apply_to)):
if mode == 'preview':
if mode == 'preview' and modification != 'show':
print(f"Would perform {modification} on {duplicate_file}")
elif mode == 'act':
handle_file_modification(original_file, duplicate_file, modification)
@ -52,7 +52,7 @@ def handle_modification(files, modification, mode, apply_to):
handle_file_modification(original_file, duplicate_file, modification)
else:
print(f"Duplicate file (unmodified): {duplicate_file}")
else:
elif modification != 'show':
print(f"Original file kept: {original_file}")
print()