sync: HP_BOWEI 2026-10-15
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""读 ~/skills_env.md 里的本机路径(KICAD_ROOT 等),不在脚本里写死。"""
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
|
||||
_ENV = None
|
||||
|
||||
|
||||
def env(key, default=None):
|
||||
global _ENV
|
||||
if _ENV is None:
|
||||
_ENV = {}
|
||||
p = os.path.join(os.path.expanduser("~"), "skills_env.md")
|
||||
if os.path.exists(p):
|
||||
for line in io.open(p, encoding="utf-8", errors="replace"):
|
||||
m = re.match(r"^\s*([A-Z0-9_]+)\s*=\s*(.+?)\s*$", line)
|
||||
if m:
|
||||
_ENV.setdefault(m.group(1), re.split(r"\s+#", m.group(2))[0].strip())
|
||||
return os.environ.get(key) or _ENV.get(key) or default
|
||||
|
||||
|
||||
def kicad_root():
|
||||
r = env("KICAD_ROOT")
|
||||
if not r:
|
||||
raise SystemExit("~/skills_env.md 里没有 KICAD_ROOT")
|
||||
return r
|
||||
|
||||
|
||||
def kicad_cli():
|
||||
return os.path.join(kicad_root(), "bin", "kicad-cli.exe")
|
||||
|
||||
|
||||
def kicad_symbol_dir():
|
||||
return os.path.join(kicad_root(), "share", "kicad", "symbols")
|
||||
|
||||
|
||||
def kicad_footprint_dir():
|
||||
return os.path.join(kicad_root(), "share", "kicad", "footprints")
|
||||
|
||||
|
||||
def chrome():
|
||||
"""headless 渲染框图用。skills_env 里可配 CHROME_EXE;否则按常见位置找 Chrome / Edge。"""
|
||||
c = env("CHROME_EXE")
|
||||
cands = [c] if c else []
|
||||
cands += [r"C:\Program Files\Google\Chrome\Application\chrome.exe",
|
||||
r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe",
|
||||
r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
|
||||
r"C:\Program Files\Microsoft\Edge\Application\msedge.exe"]
|
||||
for p in cands:
|
||||
if p and os.path.exists(p):
|
||||
return p
|
||||
raise SystemExit("找不到 Chrome/Edge,请在 ~/skills_env.md 里配 CHROME_EXE")
|
||||
Reference in New Issue
Block a user