From 51585dbe5237f19c14004fb96adc559493c86781 Mon Sep 17 00:00:00 2001 From: MohammadAmin Baranzehi Date: Tue, 1 Sep 2026 16:11:06 +0330 Subject: [PATCH] Refactor: Move modules to module package, translate messages to English, and update main runner --- .gitignore | 1 + sciter.dll => data/sciter.dll | Bin extract_acc.py | 50 ------------------ main.py | 27 ++++++++++ module/__init__.py | 1 + .../downloader_copier.py | 30 +++++------ module/extract_acc.py | 50 ++++++++++++++++++ .../install_novindesk.py | 30 +++++------ run.py | 16 ------ 9 files changed, 109 insertions(+), 96 deletions(-) create mode 100644 .gitignore rename sciter.dll => data/sciter.dll (100%) delete mode 100644 extract_acc.py create mode 100644 main.py create mode 100644 module/__init__.py rename downloader_copier.py => module/downloader_copier.py (51%) create mode 100644 module/extract_acc.py rename install_novindesk.py => module/install_novindesk.py (54%) delete mode 100644 run.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5e4f15 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/__pycache__ \ No newline at end of file diff --git a/sciter.dll b/data/sciter.dll similarity index 100% rename from sciter.dll rename to data/sciter.dll diff --git a/extract_acc.py b/extract_acc.py deleted file mode 100644 index 8ad8b60..0000000 --- a/extract_acc.py +++ /dev/null @@ -1,50 +0,0 @@ -import os -import shutil -import zipfile - -def extract_acc_archive(base_drive: str = r"D:\\") -> str: - # تغییر نام پوشه اصلی به NovinPardazOne - base_dir = os.path.join(base_drive, "NovinPardazOne") - soft_dir = os.path.join(base_dir, "NovinSoft") - acc_dir = os.path.join(base_dir, "NovinAcc") - - target_zip_name = "NovinAcc.zip" - source_zip_path = os.path.join(soft_dir, target_zip_name) - target_zip_path = os.path.join(acc_dir, target_zip_name) - - # ۱. بررسی وجود پوشه NovinSoft - if not os.path.exists(soft_dir): - raise FileNotFoundError(f"[-] پوشه یافت نشد: {soft_dir}") - - # ۲. بررسی وجود فایل زیپ - if not os.path.exists(source_zip_path): - raise FileNotFoundError(f"[-] فایل {target_zip_name} در پوشه {soft_dir} پیدا نشد!") - - # ۳. ایجاد پوشه NovinAcc در صورت عدم وجود - os.makedirs(acc_dir, exist_ok=True) - - # ۴. انتقال فایل زیپ به NovinAcc - print(f"[+] در حال انتقال {target_zip_name} به پوشه NovinAcc...") - shutil.move(source_zip_path, target_zip_path) - print(" [✓] فایل زیپ منتقل شد.") - - # ۵. استخراج فایل از حالت فشرده - print(f"[+] در حال آنزیپ کردن در {acc_dir}...") - with zipfile.ZipFile(target_zip_path, 'r') as zip_ref: - zip_ref.extractall(acc_dir) - print(" [✓] تمام فایل‌ها با موفقیت آنزیپ شدند.") - - # ۶. حذف فایل زیپ موقت - if os.path.exists(target_zip_path): - os.remove(target_zip_path) - print(" [✓] فایل زیپ موقت پاک شد.") - - return acc_dir - -if __name__ == "__main__": - os.system("chcp 65001 > nul") - print("--- در حال اجرای ماژول انتقال و آنزیپ ---") - try: - extract_acc_archive(base_drive=r"D:\\") - except Exception as e: - print(e) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..fcdf480 --- /dev/null +++ b/main.py @@ -0,0 +1,27 @@ +import os +import sys +import subprocess + +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +MODULE_DIR = os.path.join(BASE_DIR, "module") + +scripts = [ + "downloader_copier.py", + "extract_acc.py", + "install_novindesk.py" +] + +for script in scripts: + script_path = os.path.join(MODULE_DIR, script) + print(f"[+] Running {script}...") + result = subprocess.run([sys.executable, script_path], capture_output=True, text=True) + + if result.returncode == 0: + print(f"[+] {script} executed successfully.\n") + else: + print(f"[-] Error running {script}:") + if result.stdout: + print(result.stdout) + if result.stderr: + print(result.stderr) + break diff --git a/module/__init__.py b/module/__init__.py new file mode 100644 index 0000000..46e58ea --- /dev/null +++ b/module/__init__.py @@ -0,0 +1 @@ +# Module package diff --git a/downloader_copier.py b/module/downloader_copier.py similarity index 51% rename from downloader_copier.py rename to module/downloader_copier.py index f01be76..4cf790f 100644 --- a/downloader_copier.py +++ b/module/downloader_copier.py @@ -3,7 +3,7 @@ import shutil def get_non_c_drive() -> str: """ - پیدا کردن اولین درایو دسترس غیر از C در سیستم مقصد + Find the first available non-C drive on the target system. """ possible_drives = [f"{letter}:\\" for letter in "DEFGH"] for drive in possible_drives: @@ -14,29 +14,29 @@ def get_non_c_drive() -> str: def setup_directories_and_copy(source_dir: str = r"C:\SoftwareNP", target_drive: str = None) -> str: """ - ایجاد پوشه‌ها در درایوی غیر از C و کپی فایل‌ها از مبدا به NovinSoft + Create directories on a non-C drive and copy files from source to NovinSoft. """ if not target_drive: base_drive = get_non_c_drive() else: base_drive = target_drive - # تغییر نام پوشه اصلی به NovinPardazOne + # Base target directory set to NovinPardazOne base_target_dir = os.path.join(base_drive, "NovinPardazOne") acc_dir = os.path.join(base_target_dir, "NovinAcc") soft_dir = os.path.join(base_target_dir, "NovinSoft") - print(f"[+] درایو مقصد انتخاب شده: {base_drive}") - print(f"[+] در حال ایجاد ساختار پوشه‌ها در مسیر {base_target_dir} ...") + print(f"[+] Selected target drive: {base_drive}") + print(f"[+] Creating directory structure at {base_target_dir} ...") - # ساخت پوشه‌های NovinAcc و NovinSoft + # Create NovinAcc and NovinSoft directories os.makedirs(acc_dir, exist_ok=True) os.makedirs(soft_dir, exist_ok=True) - print(" [✓] پوشه‌های NovinAcc و NovinSoft با موفقیت ایجاد شدند.") + print(" [+] NovinAcc and NovinSoft directories created successfully.") - # کپی محتویات پوشه مبدا به NovinSoft + # Copy contents of source directory to NovinSoft if os.path.exists(source_dir): - print(f"[+] در حال کپی فایل‌ها از {source_dir} به {soft_dir} ...") + print(f"[+] Copying files from {source_dir} to {soft_dir} ...") for item in os.listdir(source_dir): s = os.path.join(source_dir, item) @@ -47,17 +47,17 @@ def setup_directories_and_copy(source_dir: str = r"C:\SoftwareNP", else: shutil.copy2(s, d) - print(f" [✓] تمام فایل‌ها با موفقیت در پوشه {soft_dir} کپی شدند.") + print(f" [+] All files copied successfully to {soft_dir}.") return soft_dir else: - raise FileNotFoundError(f"[-] پوشه مبدا در مسیر {source_dir} یافت نشد!") + raise FileNotFoundError(f"[-] Source directory not found at {source_dir}!") if __name__ == "__main__": os.system("chcp 65001 > nul") - print("--- تست ماژول ایجاد پوشه‌ها و کپی نرم‌افزار ---") - + print("[+] Testing directory creation and software copy module ...") + try: target_path = setup_directories_and_copy(target_drive=r"D:\\") - print(f"\nعملیات با موفقیت به پایان رسید. مسیر نرم‌افزار: {target_path}") + print(f"\n[+] Operation completed successfully. Software path: {target_path}") except Exception as e: - print(f"\n[-] خطا: {e}") \ No newline at end of file + print(f"\n[-] Error: {e}") diff --git a/module/extract_acc.py b/module/extract_acc.py new file mode 100644 index 0000000..7b027cd --- /dev/null +++ b/module/extract_acc.py @@ -0,0 +1,50 @@ +import os +import shutil +import zipfile + +def extract_acc_archive(base_drive: str = r"D:\\") -> str: + # Base directory set to NovinPardazOne + base_dir = os.path.join(base_drive, "NovinPardazOne") + soft_dir = os.path.join(base_dir, "NovinSoft") + acc_dir = os.path.join(base_dir, "NovinAcc") + + target_zip_name = "NovinAcc.zip" + source_zip_path = os.path.join(soft_dir, target_zip_name) + target_zip_path = os.path.join(acc_dir, target_zip_name) + + # 1. Check if NovinSoft directory exists + if not os.path.exists(soft_dir): + raise FileNotFoundError(f"[-] Directory not found: {soft_dir}") + + # 2. Check if zip file exists + if not os.path.exists(source_zip_path): + raise FileNotFoundError(f"[-] File {target_zip_name} was not found in {soft_dir}!") + + # 3. Create NovinAcc directory if it doesn't exist + os.makedirs(acc_dir, exist_ok=True) + + # 4. Move zip file to NovinAcc + print(f"[+] Moving {target_zip_name} to NovinAcc directory...") + shutil.move(source_zip_path, target_zip_path) + print(" [+] Zip file moved successfully.") + + # 5. Extract archive + print(f"[+] Extracting archive to {acc_dir}...") + with zipfile.ZipFile(target_zip_path, 'r') as zip_ref: + zip_ref.extractall(acc_dir) + print(" [+] All files extracted successfully.") + + # 6. Remove temporary zip file + if os.path.exists(target_zip_path): + os.remove(target_zip_path) + print(" [+] Temporary zip file deleted.") + + return acc_dir + +if __name__ == "__main__": + os.system("chcp 65001 > nul") + print("[+] Running move and extract module ...") + try: + extract_acc_archive(base_drive=r"D:\\") + except Exception as e: + print(f"[-] Error: {e}") diff --git a/install_novindesk.py b/module/install_novindesk.py similarity index 54% rename from install_novindesk.py rename to module/install_novindesk.py index f07f76d..c1b3485 100644 --- a/install_novindesk.py +++ b/module/install_novindesk.py @@ -5,7 +5,7 @@ import time def install_novindesk(base_drive: str = r"D:\\") -> str: """ - استخراج و نصب خودکار NovinDesk با پیمایش دقیق فرم نصب + Extract and automatically install NovinDesk by navigating the installer UI. """ base_dir = os.path.join(base_drive, "NovinPardazOne") soft_dir = os.path.join(base_dir, "NovinSoft") @@ -15,14 +15,14 @@ def install_novindesk(base_drive: str = r"D:\\") -> str: extract_target_dir = os.path.join(soft_dir, "NovinDesk") if not os.path.exists(source_zip_path): - raise FileNotFoundError(f"[-] فایل {zip_filename} در پوشه {soft_dir} پیدا نشد!") + raise FileNotFoundError(f"[-] File {zip_filename} was not found in {soft_dir}!") os.makedirs(extract_target_dir, exist_ok=True) - print(f"[+] در حال آنزیپ کردن {zip_filename} ...") + print(f"[+] Extracting {zip_filename} ...") with zipfile.ZipFile(source_zip_path, 'r') as zip_ref: zip_ref.extractall(extract_target_dir) - print(" [✓] آنزیپ با موفقیت انجام شد.") + print(" [+] Extraction completed successfully.") exe_file = None for root, dirs, files in os.walk(extract_target_dir): @@ -32,40 +32,40 @@ def install_novindesk(base_drive: str = r"D:\\") -> str: break if not exe_file: - raise FileNotFoundError("[-] هیچ فایل اجرایی (.exe) یافت نشد!") + raise FileNotFoundError("[-] No executable file (.exe) found!") - print(f"[+] در حال اجرای فرم نصب {os.path.basename(exe_file)} ...") + print(f"[+] Launching installer {os.path.basename(exe_file)} ...") - # اجرای برنامه جهت نصب + # Launch application for installation subprocess.Popen([exe_file, "--install"]) - # ۵ ثانیه صبر برای بارگذاری کامل پنجره + # Wait 5 seconds for the window to fully load time.sleep(5) try: import pyautogui - # ۱. بسته شدن هرگونه پنجره جانبی فرعی + # 1. Close any secondary/side dialogs pyautogui.press('escape') time.sleep(0.5) - # ۲. پیمایش دقیق با ۴ بار Tab برای رسیدن مستقیم به دکمه «قبول و شروع نصب» + # 2. Press Tab 4 times to navigate directly to the 'Accept & Install' button for _ in range(4): pyautogui.press('tab') time.sleep(0.2) - # ۳. فشردن کلید Enter روی دکمه نصب + # 3. Press Enter on the install button pyautogui.press('enter') - print(" [✓] تایید و نصب خودکار شروع شد.") + print(" [+] Confirmation sent and automated installation started.") except Exception as err: - print(f" [-] خطای اتوماسیون: {err}") + print(f" [-] Automation error: {err}") return exe_file if __name__ == "__main__": os.system("chcp 65001 > nul") - print("--- اجرای ماژول نصب NovinDesk ---") + print("[+] Running NovinDesk installation module ...") try: install_novindesk(base_drive=r"D:\\") except Exception as e: - print(f"[-] خطا: {e}") \ No newline at end of file + print(f"[-] Error: {e}") diff --git a/run.py b/run.py deleted file mode 100644 index 6b96c2b..0000000 --- a/run.py +++ /dev/null @@ -1,16 +0,0 @@ -import subprocess - -# لیست فایل‌ها به ترتیب اجرا -scripts = ["downloader_copier.py", "extract_acc.py", "install_novindesk.py"] - -for script in scripts: - print(f"در حال اجرای {script}...") - # اجرای فایل و انتظار برای اتمام آن - result = subprocess.run(["python", script], capture_output=True, text=True) - - if result.returncode == 0: - print(f"{script} با موفقیت اجرا شد.\n") - else: - print(f"خطا در اجرای {script}:") - print(result.stderr) - break # اگر خطایی رخ داد، ادامه روند متوقف شود