99 lines
3.1 KiB
Python
99 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Скан ВСЕХ PDF Yealink на функции (pdftotext, быстро).
|
|
|
|
Устройство определяется по имени папки модели. Для каждой функции — цитата.
|
|
"""
|
|
import glob
|
|
import os
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
SRC = "/opt/work-hub/datasheets-src/Datasheet/Yealink"
|
|
BASE = "/opt/work-hub/compat"
|
|
|
|
FEATURES = {
|
|
"Dante": r"\bdante\b",
|
|
"AES67": r"aes\s*-?\s*67",
|
|
"AEC": r"\bAEC\b|acoustic echo cancellation",
|
|
"ANC": r"\bANC\b|active noise cancellation|noise suppression",
|
|
"HDBaseT": r"hd\s*base\s*t",
|
|
"PoE": r"\bPoE\b|802\.3af|802\.3at|802\.3bt",
|
|
"USB-C": r"USB[-\s]?C",
|
|
"H.323": r"H\.323",
|
|
"SIP": r"\bSIP\b",
|
|
"Bluetooth": r"bluetooth",
|
|
"Wi-Fi": r"wi-?fi",
|
|
"4K": r"\b4K\b",
|
|
"Zoom": r"Zoom Rooms|native Zoom",
|
|
"Teams": r"Microsoft Teams|Teams Rooms",
|
|
"AirPlay": r"airplay",
|
|
"Miracast": r"miracast",
|
|
"Presenter Tracking": r"presenter tracking",
|
|
"Auto Framing": r"auto[\s-]framing",
|
|
"Speaker Tracking": r"speaker tracking",
|
|
"SRTP": r"\bSRTP\b",
|
|
"802.1X": r"802\.1X",
|
|
"LLDP": r"\bLLDP\b",
|
|
"VLAN": r"\bVLAN\b",
|
|
"AVB": r"\bAVB\b",
|
|
"Biamp": r"biamp",
|
|
"Shure": r"shure",
|
|
"QSC": r"\bQSC\b",
|
|
}
|
|
|
|
|
|
def text_of(pdf):
|
|
try:
|
|
r = subprocess.run(["pdftotext", "-layout", pdf, "-"],
|
|
capture_output=True, text=True, timeout=90)
|
|
return r.stdout or ""
|
|
except Exception:
|
|
return ""
|
|
|
|
|
|
def main():
|
|
import yaml
|
|
pdfs = sorted(glob.glob(os.path.join(SRC, "*", "*.pdf")))
|
|
print("PDF всего:", len(pdfs))
|
|
devices = {}
|
|
scanned = 0
|
|
for p in pdfs:
|
|
folder = os.path.basename(os.path.dirname(p))
|
|
t = text_of(p)
|
|
if len(t) < 300:
|
|
continue
|
|
scanned += 1
|
|
dev = re.sub(r"\s*\(\d+\)?\s*$", "", folder).strip()
|
|
found = devices.setdefault(dev, {})
|
|
for key, pat in FEATURES.items():
|
|
if key in found:
|
|
continue
|
|
for ln in t.splitlines():
|
|
if re.search(pat, ln, re.I):
|
|
found[key] = re.sub(r"\s+", " ", ln).strip()[:140]
|
|
break
|
|
print("просканировано с текстом:", scanned)
|
|
print("устройств:", len(devices))
|
|
stat = {}
|
|
for d, v in devices.items():
|
|
for k in v:
|
|
stat[k] = stat.get(k, 0) + 1
|
|
print("\nраспространённость:")
|
|
for k, n in sorted(stat.items(), key=lambda x: -x[1]):
|
|
print(" %-20s %2d" % (k, n))
|
|
|
|
path = os.path.join(BASE, "protocols_all.yaml")
|
|
with open(path, "w", encoding="utf-8") as f:
|
|
yaml.safe_dump({"source": {"method": "pdftotext по всем PDF",
|
|
"files": len(pdfs)},
|
|
"devices": [{"device": d, "features": v}
|
|
for d, v in sorted(devices.items())]},
|
|
f, allow_unicode=True, sort_keys=False, width=200)
|
|
print("\nсохранено:", path)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|