Files

100 lines
3.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Извлекает реальные интерфейсы (порты) устройств из даташитов.
Ищет строки вида «1 x HDMI out», «2 x USB 2.0 Type C», «1 x RJ45» и т.п.
Пишет interfaces.yaml: устройство -> {in: [...], out: [...], raw: [...]}.
"""
import glob
import os
import re
import sys
BASE = "/opt/work-hub/compat"
DEV = "/opt/work-hub/devices/yealink"
# тип разъёма -> каноническое имя
TYPES = [
(r"hdmi", "HDMI"), (r"usb[\s-]?c|type[\s-]?c", "USB-C"),
(r"usb", "USB"), (r"vch", "VCH"), (r"rj[\s-]?45|ethernet|lan", "LAN"),
(r"dp|displayport", "DP"), (r"3\.5\s*mm|line", "3.5mm"),
(r"rj[\s-]?9", "RJ-9"), (r"poe", "PoE"),
]
def canon(s):
s = s.lower()
for pat, name in TYPES:
if re.search(pat, s):
return name
return None
def parse(lines):
"""Возвращает (in, out) списки портов."""
ins, outs = [], []
for ln in lines:
m = re.search(r"(\d+)\s*[x×]\s*([^,;]+)", ln, re.I)
if not m:
continue
n = int(m.group(1))
desc = m.group(2)
t = canon(desc)
if not t or n < 1 or n > 12:
continue
direction = None
d = desc.lower()
if re.search(r"\bout(put)?\b", d):
direction = "out"
elif re.search(r"\bin(put)?\b", d) or "video input" in d:
direction = "in"
if direction == "out":
outs += [t] * n
elif direction == "in":
ins += [t] * n
else:
ins += [t] * n # по умолчанию вход
return ins, outs
def main():
import yaml
result = {}
for f in glob.glob(os.path.join(DEV, "*.yaml")):
try:
d = yaml.safe_load(open(f, encoding="utf-8"))["device"]
except Exception:
continue
model = re.sub(r"\s*\(\d+\)?\s*$", "", d.get("model") or "").strip()
lines = []
for k, vals in (d.get("specs") or {}).items():
lines += [str(v) for v in vals]
ins, outs = parse(lines)
if not ins and not outs:
continue
prev = result.get(model)
if prev and (len(prev["in"]) + len(prev["out"])) >= (len(ins) + len(outs)):
continue
result[model] = {"in": ins[:8], "out": outs[:8],
"evidence": [ln for ln in lines
if re.search(r"\d+\s*[x×]", ln)][:4]}
path = os.path.join(BASE, "interfaces.yaml")
with open(path, "w", encoding="utf-8") as f:
yaml.safe_dump({"source": "даташиты support.yealink.com",
"devices": [{"device": k, **v}
for k, v in sorted(result.items())]},
f, allow_unicode=True, sort_keys=False, width=180)
print("устройств с интерфейсами:", len(result))
for k in ("VCH51 Pro", "VCH51", "WPP30", "AP08", "MeetingEye 500", "UVC86"):
v = result.get(k)
if v:
print(" %-16s in=%-18s out=%s" % (k, ",".join(v["in"]) or "-", ",".join(v["out"]) or "-"))
else:
print(" %-16s нет данных" % k)
print("\nсохранено:", path)
return 0
if __name__ == "__main__":
sys.exit(main())