# coding=utf-8 """一键启动总服务器中心 API。 用法(在本目录或项目根均可):: python start.py python -m central_server 双击 start.bat """ from __future__ import annotations import os import sys _HERE = os.path.dirname(os.path.abspath(__file__)) _ROOT = os.path.dirname(_HERE) for p in (_HERE, _ROOT): if p not in sys.path: sys.path.insert(0, p) def load_env(path): if not os.path.isfile(path): return with open(path, "r", encoding="utf-8-sig") as fh: for raw in fh: line = raw.strip() if not line or line.startswith("#") or "=" not in line: continue key, value = line.split("=", 1) key = key.strip() value = value.strip().strip('"').strip("'") if key and key not in os.environ: os.environ[key] = value def main(): load_env(os.path.join(_HERE, ".env")) os.chdir(_HERE) try: from api_server import serve except ImportError: from central_server.api_server import serve serve() if __name__ == "__main__": main()