fix logic error
This commit is contained in:
@ -44,7 +44,7 @@ def ensureDirectory(path):
|
||||
|
||||
def copySources(config, destinationDirectory):
|
||||
"""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 source in rule.get('sources', []):
|
||||
try:
|
||||
@ -103,7 +103,7 @@ def copySources(config, destinationDirectory):
|
||||
shutil.copytree(sourcePath, targetPath)
|
||||
results['copies'] += 1
|
||||
else:
|
||||
print(f"Skipping directory: {sourcePath} -> {targetPath} (already exists)")
|
||||
print(f"Skipping directory copy: {sourcePath} -> {targetPath} (already exists)")
|
||||
errorList['copyWarnings'] += 1
|
||||
else:
|
||||
if not os.path.exists(targetPath):
|
||||
@ -111,7 +111,7 @@ def copySources(config, destinationDirectory):
|
||||
shutil.copy2(sourcePath, targetPath)
|
||||
results['copies'] += 1
|
||||
else:
|
||||
print(f"Skipping file: {sourcePath} -> {targetPath} (already exists)")
|
||||
print(f"Skipping file copy: {sourcePath} -> {targetPath} (already exists)")
|
||||
errorList['copyWarnings'] += 1
|
||||
|
||||
except FileNotFoundError as e:
|
||||
@ -187,7 +187,7 @@ def modifyFiles(config, destinationDirectory):
|
||||
if 'old_text' in insertRule:
|
||||
old_text = insertRule['old_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}")
|
||||
elif new_text not in content:
|
||||
print(f" Replacing text: {old_text} -> {new_text}")
|
||||
@ -249,8 +249,8 @@ def main():
|
||||
|
||||
if errorList["copies"] > 0 or errorList["modifications"] > 0:
|
||||
print("Errors occurred during the process. Check the output for details.")
|
||||
print(f"{errorList['copies']} copy errors.")
|
||||
print(f"{errorList['modifications']} modification errors.")
|
||||
print(f"Total copy errors: {errorList['copies']}")
|
||||
print(f"Total modification errors: {errorList['modifications']}")
|
||||
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.")
|
||||
else:
|
||||
|
Reference in New Issue
Block a user