fix logic error

This commit is contained in:
MLH
2024-12-10 02:10:45 +01:00
parent c72a06b149
commit 2605923e17

View File

@ -44,7 +44,7 @@ def ensureDirectory(path):
def copySources(config, destinationDirectory): def copySources(config, destinationDirectory):
"""Copy files and folders according to copy rules.""" """Copy files and folders according to copy rules."""
print("Starting source file/folder copy and replace process...") print("Starting source file & folder copy and replace process...")
for rule in config.get('copy_rules', []): for rule in config.get('copy_rules', []):
for source in rule.get('sources', []): for source in rule.get('sources', []):
try: try:
@ -103,7 +103,7 @@ def copySources(config, destinationDirectory):
shutil.copytree(sourcePath, targetPath) shutil.copytree(sourcePath, targetPath)
results['copies'] += 1 results['copies'] += 1
else: else:
print(f"Skipping directory: {sourcePath} -> {targetPath} (already exists)") print(f"Skipping directory copy: {sourcePath} -> {targetPath} (already exists)")
errorList['copyWarnings'] += 1 errorList['copyWarnings'] += 1
else: else:
if not os.path.exists(targetPath): if not os.path.exists(targetPath):
@ -111,7 +111,7 @@ def copySources(config, destinationDirectory):
shutil.copy2(sourcePath, targetPath) shutil.copy2(sourcePath, targetPath)
results['copies'] += 1 results['copies'] += 1
else: else:
print(f"Skipping file: {sourcePath} -> {targetPath} (already exists)") print(f"Skipping file copy: {sourcePath} -> {targetPath} (already exists)")
errorList['copyWarnings'] += 1 errorList['copyWarnings'] += 1
except FileNotFoundError as e: except FileNotFoundError as e:
@ -187,7 +187,7 @@ def modifyFiles(config, destinationDirectory):
if 'old_text' in insertRule: if 'old_text' in insertRule:
old_text = insertRule['old_text'] old_text = insertRule['old_text']
new_text = insertRule['new_text'] new_text = insertRule['new_text']
if old_text not in content: if old_text not in content and new_text not in content:
raise ValueError(f"Text '{old_text}' not found in file: {filePath}") raise ValueError(f"Text '{old_text}' not found in file: {filePath}")
elif new_text not in content: elif new_text not in content:
print(f" Replacing text: {old_text} -> {new_text}") print(f" Replacing text: {old_text} -> {new_text}")
@ -249,8 +249,8 @@ def main():
if errorList["copies"] > 0 or errorList["modifications"] > 0: if errorList["copies"] > 0 or errorList["modifications"] > 0:
print("Errors occurred during the process. Check the output for details.") print("Errors occurred during the process. Check the output for details.")
print(f"{errorList['copies']} copy errors.") print(f"Total copy errors: {errorList['copies']}")
print(f"{errorList['modifications']} modification errors.") print(f"Total modification errors: {errorList['modifications']}")
elif errorList["copyWarnings"] > 0 or errorList["modWarnings"] > 0: elif errorList["copyWarnings"] > 0 or errorList["modWarnings"] > 0:
print(f"All operations in {destinationDirectory} from {configPath} completed successfully! But there were {errorList['modWarnings'] + errorList['copyWarnings']} warnings. Mybe you should check them.") print(f"All operations in {destinationDirectory} from {configPath} completed successfully! But there were {errorList['modWarnings'] + errorList['copyWarnings']} warnings. Mybe you should check them.")
else: else: