Files

83 lines
2.8 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
"""Кронштейны из официального листа Mounts & Bracket -> рёбра графа.
Формат таблиц: строки = кронштейны, столбцы = устройства, в ячейке √/× + пояснение.
"""
import glob
import os
import re
import sys
BASE = "/opt/work-hub/compat"
def fix(s):
if s is None:
return ""
s = str(s)
for enc in ("cp1251", "cp866"):
try:
return s.encode(enc).decode("utf-8")
except Exception:
continue
return s
def main():
import yaml
files = glob.glob(os.path.join(BASE, "raw", "mounts-bracket-compatibility-lists-*.yaml"))
if not files:
print("нет файла mounts-bracket")
return 1
d = yaml.safe_load(open(files[0], encoding="utf-8"))
edges, mounts, devices = [], set(), set()
for table in d.get("tables") or []:
if not table:
continue
header = [fix(c).strip() for c in table[0]]
for row in table[1:]:
if not row:
continue
mount = fix(row[0]).strip()
if not mount:
continue
mounts.add(mount)
for i, cell in enumerate(row[1:], start=1):
dev = re.sub(r"\s+", " ", fix(header[i])).strip() if i < len(header) else ""
if not dev:
continue
c = fix(cell).strip()
if not c:
continue
supported = bool(re.search(r"[√✓✔]", c))
if not supported:
continue
devices.add(dev)
note = re.sub(r"^[√✓✔×✗✘\s]+", "", c)[:120]
edges.append({"host": dev, "mount": mount, "note": note or None})
print("кронштейнов:", len(mounts))
for m in sorted(mounts):
n = sum(1 for e in edges if e["mount"] == m)
print(" %-26s совместим с %d устройствами" % (m[:26], n))
print("\nустройств:", len(devices))
print("рёбер:", len(edges))
path = os.path.join(BASE, "mounts.yaml")
with open(path, "w", encoding="utf-8") as f:
yaml.safe_dump({"source": {"file": os.path.basename(files[0]),
"kind": "official_support_page", "verified": True},
"mounts": sorted(mounts), "edges": edges},
f, allow_unicode=True, sort_keys=False, width=200)
print("\nсохранено:", path)
# показываем пару примеров
for dev in ("MeetingBar A50", "MeetingBar A40", "UVC86"):
rows = [e["mount"] for e in edges if e["host"] == dev]
if rows:
print(" %s: %s" % (dev, ", ".join(rows[:6])))
return 0
if __name__ == "__main__":
sys.exit(main())