Refactor: Move modules to module package, translate messages to English, and update main runner

This commit is contained in:
2026-09-01 16:11:06 +03:30
parent bafae4b212
commit 51585dbe52
9 changed files with 109 additions and 96 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
**/__pycache__

View File

@@ -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)

27
main.py Normal file
View File

@@ -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

1
module/__init__.py Normal file
View File

@@ -0,0 +1 @@
# Module package

View File

@@ -3,7 +3,7 @@ import shutil
def get_non_c_drive() -> str: 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"] possible_drives = [f"{letter}:\\" for letter in "DEFGH"]
for drive in possible_drives: 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", def setup_directories_and_copy(source_dir: str = r"C:\SoftwareNP",
target_drive: str = None) -> str: 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: if not target_drive:
base_drive = get_non_c_drive() base_drive = get_non_c_drive()
else: else:
base_drive = target_drive base_drive = target_drive
# تغییر نام پوشه اصلی به NovinPardazOne # Base target directory set to NovinPardazOne
base_target_dir = os.path.join(base_drive, "NovinPardazOne") base_target_dir = os.path.join(base_drive, "NovinPardazOne")
acc_dir = os.path.join(base_target_dir, "NovinAcc") acc_dir = os.path.join(base_target_dir, "NovinAcc")
soft_dir = os.path.join(base_target_dir, "NovinSoft") soft_dir = os.path.join(base_target_dir, "NovinSoft")
print(f"[+] درایو مقصد انتخاب شده: {base_drive}") print(f"[+] Selected target drive: {base_drive}")
print(f"[+] در حال ایجاد ساختار پوشه‌ها در مسیر {base_target_dir} ...") 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(acc_dir, exist_ok=True)
os.makedirs(soft_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): 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): for item in os.listdir(source_dir):
s = os.path.join(source_dir, item) s = os.path.join(source_dir, item)
@@ -47,17 +47,17 @@ def setup_directories_and_copy(source_dir: str = r"C:\SoftwareNP",
else: else:
shutil.copy2(s, d) shutil.copy2(s, d)
print(f" [] تمام فایل‌ها با موفقیت در پوشه {soft_dir} کپی شدند.") print(f" [+] All files copied successfully to {soft_dir}.")
return soft_dir return soft_dir
else: else:
raise FileNotFoundError(f"[-] پوشه مبدا در مسیر {source_dir} یافت نشد!") raise FileNotFoundError(f"[-] Source directory not found at {source_dir}!")
if __name__ == "__main__": if __name__ == "__main__":
os.system("chcp 65001 > nul") os.system("chcp 65001 > nul")
print("--- تست ماژول ایجاد پوشه‌ها و کپی نرم‌افزار ---") print("[+] Testing directory creation and software copy module ...")
try: try:
target_path = setup_directories_and_copy(target_drive=r"D:\\") 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: except Exception as e:
print(f"\n[-] خطا: {e}") print(f"\n[-] Error: {e}")

50
module/extract_acc.py Normal file
View File

@@ -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}")

View File

@@ -5,7 +5,7 @@ import time
def install_novindesk(base_drive: str = r"D:\\") -> str: 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") base_dir = os.path.join(base_drive, "NovinPardazOne")
soft_dir = os.path.join(base_dir, "NovinSoft") 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") extract_target_dir = os.path.join(soft_dir, "NovinDesk")
if not os.path.exists(source_zip_path): 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) 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: with zipfile.ZipFile(source_zip_path, 'r') as zip_ref:
zip_ref.extractall(extract_target_dir) zip_ref.extractall(extract_target_dir)
print(" [] آنزیپ با موفقیت انجام شد.") print(" [+] Extraction completed successfully.")
exe_file = None exe_file = None
for root, dirs, files in os.walk(extract_target_dir): for root, dirs, files in os.walk(extract_target_dir):
@@ -32,40 +32,40 @@ def install_novindesk(base_drive: str = r"D:\\") -> str:
break break
if not exe_file: 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"]) subprocess.Popen([exe_file, "--install"])
# ۵ ثانیه صبر برای بارگذاری کامل پنجره # Wait 5 seconds for the window to fully load
time.sleep(5) time.sleep(5)
try: try:
import pyautogui import pyautogui
# ۱. بسته شدن هرگونه پنجره جانبی فرعی # 1. Close any secondary/side dialogs
pyautogui.press('escape') pyautogui.press('escape')
time.sleep(0.5) time.sleep(0.5)
# ۲. پیمایش دقیق با ۴ بار Tab برای رسیدن مستقیم به دکمه «قبول و شروع نصب» # 2. Press Tab 4 times to navigate directly to the 'Accept & Install' button
for _ in range(4): for _ in range(4):
pyautogui.press('tab') pyautogui.press('tab')
time.sleep(0.2) time.sleep(0.2)
# ۳. فشردن کلید Enter روی دکمه نصب # 3. Press Enter on the install button
pyautogui.press('enter') pyautogui.press('enter')
print(" [] تایید و نصب خودکار شروع شد.") print(" [+] Confirmation sent and automated installation started.")
except Exception as err: except Exception as err:
print(f" [-] خطای اتوماسیون: {err}") print(f" [-] Automation error: {err}")
return exe_file return exe_file
if __name__ == "__main__": if __name__ == "__main__":
os.system("chcp 65001 > nul") os.system("chcp 65001 > nul")
print("--- اجرای ماژول نصب NovinDesk ---") print("[+] Running NovinDesk installation module ...")
try: try:
install_novindesk(base_drive=r"D:\\") install_novindesk(base_drive=r"D:\\")
except Exception as e: except Exception as e:
print(f"[-] خطا: {e}") print(f"[-] Error: {e}")

16
run.py
View File

@@ -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 # اگر خطایی رخ داد، ادامه روند متوقف شود