Files

69 lines
2.3 KiB
Python

"""Print config status (no browser). Run: python scripts/validate_config.py"""
from __future__ import annotations
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT / "src"))
from config import ( # noqa: E402
CONFIG_FILE,
DEFAULT_PLANNER_URL,
EXPECTED_FACILITY_COUNT,
credentials_setup_message,
missing_onedrive_credentials,
read_app_config,
read_facility_list,
)
from totp_utils import validate_totp_secret # noqa: E402
def main() -> int:
path = CONFIG_FILE if CONFIG_FILE.exists() else ROOT / "Input" / "input.xlsx.example"
if not path.exists():
print(f"[FAIL] Missing {path}")
print(" copy Input\\input.xlsx.example Input\\input.xlsx")
return 1
cfg = read_app_config(path)
missing = missing_onedrive_credentials(
cfg.onedrive_username,
cfg.onedrive_password,
cfg.microsoft_totp_secret,
)
if missing and path == CONFIG_FILE:
print("[FAIL] Credentials not configured:")
print(credentials_setup_message(missing))
return 1
try:
validate_totp_secret(cfg.microsoft_totp_secret or "JBSWY3DPEHPK3PXP")
except ValueError as exc:
if cfg.microsoft_totp_secret:
print(f"[FAIL] TOTP secret: {exc}")
return 1
print(f"[WARN] TOTP not set — format check skipped ({exc})")
facilities = read_facility_list(path, warn_if_not_expected_count=True)
planner = cfg.planner_url or DEFAULT_PLANNER_URL
if not planner.startswith("https://"):
print(f"[FAIL] Planner URL must be https — got: {planner[:80]}")
return 1
print(f"[OK] Config file: {path.name}")
if cfg.onedrive_username:
print(f"[OK] Credentials set for {cfg.onedrive_username}")
else:
print("[OK] Template mode (no credentials in example file)")
print(f"[OK] Planner URL: {planner[:70]}...")
print(f"[OK] PDF folder: {cfg.pdf_folder_path or '(default Input/PDFs)'}")
print(f"[OK] {len(facilities)} facilities (expected {EXPECTED_FACILITY_COUNT})")
if len(facilities) != EXPECTED_FACILITY_COUNT:
print("[WARN] Facility count differs from expected 54 — verify Facilities sheet")
return 0
if __name__ == "__main__":
raise SystemExit(main())