90 lines
3.1 KiB
Python
90 lines
3.1 KiB
Python
import os
|
|
|
|
# Target directories relative to script
|
|
TARGET_DIRS = ["dashboards/admin", "dashboards/service"]
|
|
|
|
# Text replacements
|
|
REPLACEMENTS = {
|
|
"Siro": "Tripz",
|
|
"siro": "tripz",
|
|
"SIRO": "TRIPZ",
|
|
"Intaleq": "Tripz",
|
|
"intaleq": "tripz",
|
|
"INTALEQ": "TRIPZ",
|
|
"سيرو": "تريبز",
|
|
"انطلق": "تريبز"
|
|
}
|
|
|
|
# Directories and files to ignore
|
|
IGNORE_DIRS = {
|
|
".git", ".dart_tool", "build", "Pods", ".symlinks", ".pub-cache",
|
|
"node_modules", "vendor", ".gradle", "xcuserdata", ".idea"
|
|
}
|
|
|
|
IGNORE_EXTS = {
|
|
".png", ".jpg", ".jpeg", ".gif", ".webp", ".ttf", ".otf", ".woff", ".woff2",
|
|
".mp3", ".mp4", ".mov", ".zip", ".tar", ".gz", ".pdf", ".so", ".dylib", ".dll",
|
|
".class", ".jar", ".keystore", ".jks", ".dex", ".o", ".a"
|
|
}
|
|
|
|
def rename_files_and_dirs(root_dir):
|
|
# Pass 1: Rename files and directories bottom-up
|
|
for root, dirs, files in os.walk(root_dir, topdown=False):
|
|
# Skip if in ignored directory path
|
|
if any(ignored in root.split(os.sep) for ignored in IGNORE_DIRS):
|
|
continue
|
|
|
|
for name in files + dirs:
|
|
new_name = name
|
|
for old, new in REPLACEMENTS.items():
|
|
# For filenames, mostly focus on english names
|
|
if old in ["Siro", "siro", "SIRO", "Intaleq", "intaleq", "INTALEQ"]:
|
|
new_name = new_name.replace(old, new)
|
|
|
|
if new_name != name:
|
|
old_path = os.path.join(root, name)
|
|
new_path = os.path.join(root, new_name)
|
|
print(f"Renaming: {old_path} -> {new_path}")
|
|
os.rename(old_path, new_path)
|
|
|
|
def replace_in_files(root_dir):
|
|
for root, dirs, files in os.walk(root_dir):
|
|
# Modify dirs in-place to skip ignored directories
|
|
dirs[:] = [d for d in dirs if d not in IGNORE_DIRS]
|
|
|
|
for file in files:
|
|
ext = os.path.splitext(file)[1].lower()
|
|
if ext in IGNORE_EXTS:
|
|
continue
|
|
|
|
file_path = os.path.join(root, file)
|
|
|
|
try:
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
except UnicodeDecodeError:
|
|
# Might be a binary file without known extension, skip it
|
|
continue
|
|
except Exception as e:
|
|
print(f"Could not read {file_path}: {e}")
|
|
continue
|
|
|
|
new_content = content
|
|
for old, new in REPLACEMENTS.items():
|
|
new_content = new_content.replace(old, new)
|
|
|
|
if new_content != content:
|
|
print(f"Updating content in: {file_path}")
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|
f.write(new_content)
|
|
|
|
if __name__ == "__main__":
|
|
for d in TARGET_DIRS:
|
|
print(f"Processing {d}...")
|
|
abs_d = os.path.join("/Users/hamzaaleghwairyeen/development/App/Tripz", d)
|
|
if os.path.exists(abs_d):
|
|
rename_files_and_dirs(abs_d)
|
|
replace_in_files(abs_d)
|
|
|
|
print("Replacement complete.")
|