feat(core): rewrite installer with modular config, dynamic drive resolver, and clean orchestration
This commit is contained in:
@@ -1,50 +1,75 @@
|
||||
"""
|
||||
Archive extractor module for NovinAcc accounting software.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
from typing import Optional
|
||||
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")
|
||||
from module.config import InstallerConfig, detect_target_drive
|
||||
|
||||
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)
|
||||
logger = logging.getLogger("acc_installer")
|
||||
|
||||
# 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}!")
|
||||
def extract_acc_archive(config: Optional[InstallerConfig] = None,
|
||||
archive_name: str = "NovinAcc.zip") -> Path:
|
||||
"""
|
||||
Locates NovinAcc archive in NovinSoft, moves it to NovinAcc, and extracts its contents.
|
||||
"""
|
||||
if config is None:
|
||||
config = InstallerConfig()
|
||||
|
||||
# 3. Create NovinAcc directory if it doesn't exist
|
||||
os.makedirs(acc_dir, exist_ok=True)
|
||||
source_zip = config.soft_dir / archive_name
|
||||
target_zip = config.acc_dir / archive_name
|
||||
|
||||
# 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.")
|
||||
config.ensure_directories()
|
||||
|
||||
# 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.")
|
||||
if config.dry_run:
|
||||
print(f" [DRY-RUN] Would locate {archive_name} in {config.soft_dir}, move to {config.acc_dir} and extract.")
|
||||
return config.acc_dir
|
||||
|
||||
# 6. Remove temporary zip file
|
||||
if os.path.exists(target_zip_path):
|
||||
os.remove(target_zip_path)
|
||||
print(" [+] Temporary zip file deleted.")
|
||||
# Check if archive exists in soft_dir or already in acc_dir
|
||||
archive_to_extract = None
|
||||
if source_zip.exists():
|
||||
archive_to_extract = source_zip
|
||||
elif target_zip.exists():
|
||||
archive_to_extract = target_zip
|
||||
else:
|
||||
raise FileNotFoundError(
|
||||
f"Archive '{archive_name}' was not found in either {config.soft_dir} or {config.acc_dir}!"
|
||||
)
|
||||
|
||||
# Move archive to target NovinAcc directory if not already there
|
||||
if archive_to_extract != target_zip:
|
||||
print(f"[+] Moving {archive_name} to NovinAcc directory...")
|
||||
shutil.move(str(source_zip), str(target_zip))
|
||||
print(" [+] Zip archive moved successfully.")
|
||||
|
||||
# Extract archive
|
||||
print(f"[+] Extracting {archive_name} into {config.acc_dir} ...")
|
||||
with zipfile.ZipFile(target_zip, 'r') as zip_ref:
|
||||
zip_ref.extractall(config.acc_dir)
|
||||
print(" [+] All archive files extracted successfully.")
|
||||
|
||||
# Remove temporary zip file
|
||||
if target_zip.exists():
|
||||
target_zip.unlink()
|
||||
print(" [+] Temporary zip archive cleaned up.")
|
||||
|
||||
return config.acc_dir
|
||||
|
||||
return acc_dir
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.system("chcp 65001 > nul")
|
||||
print("[+] Running move and extract module ...")
|
||||
import sys
|
||||
logging.basicConfig(level=logging.INFO, format="%(message)s")
|
||||
print("[*] Running NovinAcc archive extractor standalone ...")
|
||||
try:
|
||||
extract_acc_archive(base_drive=r"D:\\")
|
||||
cfg = InstallerConfig(target_drive=detect_target_drive())
|
||||
extract_acc_archive(cfg)
|
||||
print("[+] NovinAcc extraction completed successfully.")
|
||||
except Exception as e:
|
||||
print(f"[-] Error: {e}")
|
||||
print(f"[-] Error: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user