Some checks failed
Android CI Build / check (push) Has been cancelled
Android CI Build / package-apks (push) Has been cancelled
Docs Deploy / build (push) Has been cancelled
Module Market Check / Validate modules/ (push) Has been cancelled
Module Market Publish / Generate submissions.json (push) Has been cancelled
Docs Deploy / deploy (push) Has been cancelled
- Package rename com.webtoapp -> br.com.drukstech.codeapp - Product rename WebToApp/web-to-app -> DruksCode/drukscode - Design system Wta* -> Dkc* - applicationId br.com.drukstech.codeapp (.play for gplay flavor) - rootProject.name DruksCode - Fresh git history (upstream kept as remote for sync)
259 lines
9.2 KiB
Python
259 lines
9.2 KiB
Python
#!/usr/bin/env python3
|
|
"""DruksCodeV2 identity rename script.
|
|
Replaces: br.com.drukstech.codeapp → br.com.drukstech.codeapp,
|
|
DruksCode → DruksCode, Dkc → Dkc in all project files."""
|
|
|
|
import os
|
|
import re
|
|
import sys
|
|
|
|
ROOT = "/opt/DruksCodeV2"
|
|
|
|
# Directories to process (source code + configs)
|
|
TARGET_DIRS = {
|
|
"app/src/main/java/br/com/drukstech/codeapp": "app/src/main/java/br/com/drukstech/codeapp",
|
|
"app/src/test/java/br/com/drukstech/codeapp": "app/src/test/java/br/com/drukstech/codeapp",
|
|
"shell/src/main/java/br/com/drukstech/codeapp": "shell/src/main/java/br/com/drukstech/codeapp",
|
|
"clone-host/src/main/java/br/com/drukstech/codeapp": "clone-host/src/main/java/br/com/drukstech/codeapp",
|
|
}
|
|
|
|
# File renames (old basename → new basename)
|
|
FILE_RENAMES = {
|
|
"DruksCodeApplication.kt": "DruksCodeApplication.kt",
|
|
"DruksCodeContent.kt": "DruksCodeContent.kt",
|
|
}
|
|
|
|
# Content replacements (order matters: longer patterns first)
|
|
CONTENT_REPLACEMENTS = [
|
|
# Package namespaces
|
|
("br.com.drukstech.codeapp", "br.com.drukstech.codeapp"),
|
|
("br/com/drukstech/codeapp", "br/com/drukstech/codeapp"),
|
|
("br.com.drukstech.codeapp.play", "br.com.drukstech.codeapp.play"),
|
|
# Design system prefix (order: PascalCase first, then UPPER, then lowercase)
|
|
("Dkc", "Dkc"),
|
|
("DKC", "DKC"),
|
|
("dkc", "dkc"),
|
|
# Product name (order: PascalCase, camelCase, UPPER, kebab, then specific class)
|
|
("DruksCodeApplication", "DruksCodeApplication"),
|
|
("DruksCodeContent", "DruksCodeContent"),
|
|
("DruksCode", "DruksCode"),
|
|
("druksCode", "druksCode"),
|
|
("DRUKSCODE", "DRUKSCODE"),
|
|
("drukscode", "drukscode"),
|
|
]
|
|
|
|
# File extensions to process as text
|
|
TEXT_EXTS = {
|
|
".kt", ".java", ".xml", ".gradle", ".kts", ".json", ".md", ".html",
|
|
".js", ".ts", ".yaml", ".yml", ".properties", ".pro", ".cfg",
|
|
".toml", ".txt", ".sh", ".bat", ".py", ".css", ".scss",
|
|
}
|
|
|
|
# Files to skip (binary, generated, or irrelevant)
|
|
SKIP_FILES = {
|
|
"gradle-wrapper.jar", "gradlew.bat", "LICENSE",
|
|
}
|
|
SKIP_DIRS = {
|
|
".git", ".gradle", "build", ".idea", ".vscode",
|
|
"sample_projects", "node_modules", ".zcode", ".workbuddy",
|
|
}
|
|
|
|
|
|
def is_text_file(path):
|
|
ext = os.path.splitext(path)[1].lower()
|
|
return ext in TEXT_EXTS
|
|
|
|
|
|
def replace_content(text):
|
|
"""Apply all content replacements, avoiding upstream URLs."""
|
|
result = text
|
|
for old, new in CONTENT_REPLACEMENTS:
|
|
if old == "drukscode":
|
|
# Preserve actual GitHub upstream URLs
|
|
result = re.sub(
|
|
r'(?<!github\.com/shiaho777/)(?<!shiaho777\.github\.io/)drukscode',
|
|
new, result
|
|
)
|
|
else:
|
|
result = result.replace(old, new)
|
|
return result
|
|
|
|
|
|
def rename_dirs_bottom_up(root):
|
|
"""Rename directories from deepest to shallowest."""
|
|
for dirpath, dirnames, filenames in os.walk(root, topdown=False):
|
|
# Skip ignored directories
|
|
dirnames[:] = [d for d in dirnames if d not in SKIP_DIRS]
|
|
|
|
# Check for package directory renames
|
|
rel = os.path.relpath(dirpath, root)
|
|
for old_pkg, new_pkg in TARGET_DIRS.items():
|
|
if rel == old_pkg or rel.startswith(old_pkg + "/"):
|
|
break
|
|
|
|
# Rename files first
|
|
for fname in filenames:
|
|
if fname in SKIP_FILES:
|
|
continue
|
|
new_fname = FILE_RENAMES.get(fname, fname)
|
|
if new_fname != fname:
|
|
old_path = os.path.join(dirpath, fname)
|
|
new_path = os.path.join(dirpath, new_fname)
|
|
os.rename(old_path, new_path)
|
|
print(f" FILE: {fname} → {new_fname}")
|
|
|
|
# Rename Dkc* → Dkc* in filenames
|
|
for fname in list(os.listdir(dirpath)):
|
|
if fname.startswith("Dkc") and fname.endswith(".kt"):
|
|
new_fname = "Dkc" + fname[3:]
|
|
old_path = os.path.join(dirpath, fname)
|
|
new_path = os.path.join(dirpath, new_fname)
|
|
if os.path.exists(old_path) and not os.path.exists(new_path):
|
|
os.rename(old_path, new_path)
|
|
print(f" FILE: {fname} → {new_fname}")
|
|
|
|
|
|
def process_files(root):
|
|
"""Replace content in all text files."""
|
|
count = 0
|
|
for dirpath, dirnames, filenames in os.walk(root):
|
|
dirnames[:] = [d for d in dirnames if d not in SKIP_DIRS]
|
|
|
|
for fname in filenames:
|
|
if fname in SKIP_FILES:
|
|
continue
|
|
fpath = os.path.join(dirpath, fname)
|
|
|
|
if not os.path.isfile(fpath):
|
|
continue
|
|
if not is_text_file(fpath):
|
|
continue
|
|
|
|
try:
|
|
with open(fpath, "r", encoding="utf-8", errors="ignore") as f:
|
|
content = f.read()
|
|
except Exception:
|
|
continue
|
|
|
|
new_content = replace_content(content)
|
|
if new_content != content:
|
|
with open(fpath, "w", encoding="utf-8") as f:
|
|
f.write(new_content)
|
|
count += 1
|
|
rel = os.path.relpath(fpath, root)
|
|
print(f" EDITED: {rel}")
|
|
return count
|
|
|
|
|
|
def rename_package_dirs(root):
|
|
"""Rename br/com/drukstech/codeapp → br/com/drukstech/codeapp directories."""
|
|
for old_pkg, new_pkg in TARGET_DIRS.items():
|
|
old_dir = os.path.join(root, old_pkg)
|
|
new_dir = os.path.join(root, new_pkg)
|
|
|
|
if not os.path.isdir(old_dir):
|
|
print(f" SKIP (not found): {old_pkg}")
|
|
continue
|
|
|
|
# Ensure parent dirs exist
|
|
os.makedirs(os.path.dirname(new_dir), exist_ok=True)
|
|
|
|
if os.path.exists(new_dir):
|
|
# Merge if both exist
|
|
for item in os.listdir(old_dir):
|
|
src = os.path.join(old_dir, item)
|
|
dst = os.path.join(new_dir, item)
|
|
if not os.path.exists(dst):
|
|
os.rename(src, dst)
|
|
os.rmdir(old_dir) if not os.listdir(old_dir) else None
|
|
else:
|
|
os.rename(old_dir, new_dir)
|
|
|
|
print(f" DIR: {old_pkg} → {new_pkg}")
|
|
|
|
|
|
def main():
|
|
print("=== DruksCodeV2 Identity Rename ===")
|
|
print(f"Root: {ROOT}")
|
|
|
|
print("\n[1/4] Renaming files...")
|
|
rename_dirs_bottom_up(ROOT)
|
|
|
|
print("\n[2/4] Replacing content in text files...")
|
|
edited = process_files(ROOT)
|
|
print(f" Total files edited: {edited}")
|
|
|
|
print("\n[3/4] Renaming package directories...")
|
|
rename_package_dirs(ROOT)
|
|
|
|
print("\n[4/4] Updating root configs...")
|
|
|
|
# Update settings.gradle.kts
|
|
settings = os.path.join(ROOT, "settings.gradle.kts")
|
|
if os.path.exists(settings):
|
|
with open(settings, "r") as f:
|
|
c = f.read()
|
|
c = c.replace("rootProject.name = \"DruksCode\"", "rootProject.name = \"DruksCode\"")
|
|
c = c.replace("rootProject.name = \"drukscode\"", "rootProject.name = \"DruksCode\"")
|
|
with open(settings, "w") as f:
|
|
f.write(c)
|
|
print(" settings.gradle.kts updated")
|
|
|
|
# Update app/build.gradle.kts - applicationId
|
|
app_gradle = os.path.join(ROOT, "app/build.gradle.kts")
|
|
if os.path.exists(app_gradle):
|
|
with open(app_gradle, "r") as f:
|
|
c = f.read()
|
|
c = c.replace('"br.com.drukstech.codeapp"', '"br.com.drukstech.codeapp"')
|
|
c = c.replace('"br.com.drukstech.codeapp.play"', '"br.com.drukstech.codeapp.play"')
|
|
c = c.replace('"br.com.drukstech.codeapp.play"', '"br.com.drukstech.codeapp.play"')
|
|
with open(app_gradle, "w") as f:
|
|
f.write(c)
|
|
print(" app/build.gradle.kts updated")
|
|
|
|
# Update AndroidManifest.xml (applicationId)
|
|
for manifest in ["app/src/main/AndroidManifest.xml", "shell/src/main/AndroidManifest.xml"]:
|
|
mp = os.path.join(ROOT, manifest)
|
|
if os.path.exists(mp):
|
|
with open(mp, "r") as f:
|
|
c = f.read()
|
|
c = c.replace("br.com.drukstech.codeapp", "br.com.drukstech.codeapp")
|
|
with open(mp, "w") as f:
|
|
f.write(c)
|
|
print(f" {manifest} updated")
|
|
|
|
# Update res/values/strings.xml - app_name
|
|
strings = os.path.join(ROOT, "app/src/main/res/values/strings.xml")
|
|
if os.path.exists(strings):
|
|
with open(strings, "r") as f:
|
|
c = f.read()
|
|
c = c.replace(">DruksCode<", ">DruksCode<")
|
|
c = c.replace("DruksCode", "DruksCode")
|
|
with open(strings, "w") as f:
|
|
f.write(c)
|
|
print(" res/values/strings.xml updated")
|
|
|
|
# Update themes.xml
|
|
for theme_path in [
|
|
"app/src/main/res/values/themes.xml",
|
|
"app/src/main/res/values-night/themes.xml",
|
|
]:
|
|
tp = os.path.join(ROOT, theme_path)
|
|
if os.path.exists(tp):
|
|
with open(tp, "r") as f:
|
|
c = f.read()
|
|
if "DruksCode" in c or "dkc" in c.lower():
|
|
c = c.replace("DruksCode", "DruksCode")
|
|
c = c.replace("Dkc", "Dkc")
|
|
c = c.replace("dkc", "dkc")
|
|
with open(tp, "w") as f:
|
|
f.write(c)
|
|
print(f" {theme_path} updated")
|
|
|
|
print("\n=== DONE ===")
|
|
print("Verify: grep -r 'com\.webtoapp\|DruksCode\|Dkc' --include='*.kt' --include='*.xml' --include='*.kts' app/src/main/java/ shell/src/main/java/ | head -20")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|