#!/usr/bin/env python3 """Server-local administrative runner. Loads credentials without printing them.""" import os from pathlib import Path import shlex import subprocess import sys root = Path('/opt/lingniu-gzev/current') env = os.environ.copy() for path in [Path('/opt/lingniu-go-native/env/base.env'), Path('/opt/lingniu-vehicle-platform/env/platform.env'), Path('/opt/lingniu-gzev/env/gzev.env')]: for line in path.read_text(encoding="utf-8").splitlines(): line = line.strip() if not line or line.startswith('#'): continue key, sep, value = line.partition('=') if not sep: raise SystemExit('Invalid environment file assignment') # Existing service env files use single-line assignments, optionally quoted. if value.startswith(('"', "'")): parts = shlex.split(value, comments=False) if len(parts) != 1: raise SystemExit('Invalid quoted environment value') value = parts[0] env[key.strip()] = value if len(sys.argv) > 1 and sys.argv[1] == 'migrate': args = [str(root / 'platform-migrate'), str(root / '049_gzev_daily_mileage.sql')] else: args = [str(root / 'gzev-mileage')] + sys.argv[1:] raise SystemExit(subprocess.call(args, env=env))