71 lines
3.1 KiB
Python
71 lines
3.1 KiB
Python
import os
|
|
import shutil
|
|
|
|
source_dir = "/Users/hamzaaleghwairyeen/development/App"
|
|
target_dir = "/Users/hamzaaleghwairyeen/development/App/Siro"
|
|
|
|
mappings = [
|
|
{"src": "Intaleq", "dst": "siro_rider", "old_pkg": "Intaleq", "new_pkg": "siro_rider"},
|
|
{"src": "intaleq_driver", "dst": "siro_driver", "old_pkg": "sefer_driver", "new_pkg": "siro_driver"},
|
|
{"src": "intaleq_admin", "dst": "siro_admin", "old_pkg": "sefer_admin1", "new_pkg": "siro_admin"},
|
|
{"src": "service_intaleq", "dst": "siro_service", "old_pkg": "service", "new_pkg": "siro_service"}
|
|
]
|
|
|
|
def copy_and_replace():
|
|
for m in mappings:
|
|
src_path = os.path.join(source_dir, m['src'])
|
|
dst_path = os.path.join(target_dir, m['dst'])
|
|
|
|
# 1. Delete destination lib and assets if exist
|
|
for folder in ['lib', 'assets', 'secure_string_operations']:
|
|
d_folder = os.path.join(dst_path, folder)
|
|
if os.path.exists(d_folder):
|
|
shutil.rmtree(d_folder)
|
|
|
|
# 2. Copy lib and assets
|
|
for folder in ['lib', 'assets', 'secure_string_operations']:
|
|
s_folder = os.path.join(src_path, folder)
|
|
d_folder = os.path.join(dst_path, folder)
|
|
if os.path.exists(s_folder):
|
|
shutil.copytree(s_folder, d_folder)
|
|
|
|
# 3. Copy pubspec.yaml
|
|
s_pubspec = os.path.join(src_path, "pubspec.yaml")
|
|
d_pubspec = os.path.join(dst_path, "pubspec.yaml")
|
|
if os.path.exists(s_pubspec):
|
|
shutil.copy2(s_pubspec, d_pubspec)
|
|
|
|
# 4. Replace package name in pubspec.yaml
|
|
if os.path.exists(d_pubspec):
|
|
with open(d_pubspec, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
# replace name: old_pkg with name: new_pkg
|
|
import re
|
|
content = re.sub(rf'^name:\s*{m["old_pkg"]}\s*$', f'name: {m["new_pkg"]}', content, flags=re.MULTILINE)
|
|
with open(d_pubspec, 'w', encoding='utf-8') as f:
|
|
f.write(content)
|
|
|
|
# 5. Replace imports in lib and test directories
|
|
for root_folder in ['lib', 'test']:
|
|
root_path = os.path.join(dst_path, root_folder)
|
|
if not os.path.exists(root_path): continue
|
|
|
|
for root, dirs, files in os.walk(root_path):
|
|
for file in files:
|
|
if file.endswith('.dart'):
|
|
file_path = os.path.join(root, file)
|
|
try:
|
|
with open(file_path, 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
new_content = content.replace(f"package:{m['old_pkg']}/", f"package:{m['new_pkg']}/")
|
|
if new_content != content:
|
|
with open(file_path, 'w', encoding='utf-8') as f:
|
|
f.write(new_content)
|
|
except Exception as e:
|
|
print(f"Error reading {file_path}: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
copy_and_replace()
|
|
print("Done")
|