Files
pricing_review/release_entry.py
2026-10-11 10:52:01 +08:00

59 lines
1.7 KiB
Python

"""Entry point for the portable Windows distribution."""
import os
import sqlite3
import sys
ROOT = os.path.dirname(os.path.abspath(sys.executable if getattr(sys, "frozen", False) else __file__))
APP = os.path.join(ROOT, "CostReview", "app")
for part in (APP, os.path.join(APP, "server"), os.path.join(APP, "core")):
sys.path.insert(0, part)
# Explicit imports keep PyInstaller from omitting modules loaded by the launcher.
import webview
import api_server
import shell
def check():
data = os.path.join(ROOT, "CostReview", "data")
paths = (os.path.join(APP, "ui", "workbench.html"),
os.path.join(APP, "store", "schema.sql"),
os.path.join(data, "history.db"))
for path in paths:
if not os.path.isfile(path):
raise FileNotFoundError(path)
if not os.path.isdir(data):
raise FileNotFoundError(data)
probe = os.path.join(data, ".write_test")
try:
with open(probe, "w", encoding="ascii") as f:
f.write("ok")
os.remove(probe)
except Exception as exc:
raise OSError("Data directory is not writable: %s" % data) from exc
db = sqlite3.connect("file:%s?mode=ro" % paths[-1].replace("\\", "/"), uri=True)
try:
count = db.execute("SELECT COUNT(*) FROM lmes").fetchone()[0]
finally:
db.close()
print("Package OK; history LME records: %s" % count, flush=True)
def main():
if "--check" in sys.argv:
check()
return
if "--serve" in sys.argv:
api_server.run()
return
return shell.main()
if __name__ == "__main__":
try:
sys.exit(main())
except Exception as exc:
print("[ERROR] %s" % exc, file=sys.stderr, flush=True)
sys.exit(1)