SHA256
56 lines
2.5 KiB
Python
56 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Проверка локальных ссылок документации и индекса публичных WS-операций."""
|
|
from pathlib import Path
|
|
import re
|
|
import sys
|
|
from urllib.parse import unquote
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
DOCS = ROOT / 'docs'
|
|
REGISTRY = ROOT / 'SHiNE-server/shine-server-net-protocol/src/main/java/server/logic/ws_protocol/JSON/JsonHandlerRegistry.java'
|
|
INDEX = DOCS / 'API/09_Operations_Index.md'
|
|
LINK = re.compile(r'\[[^\]]+\]\(([^)]+)\)')
|
|
OP = re.compile(r'Map\.entry\("([A-Za-z0-9_]+)"')
|
|
INDEX_OP = re.compile(r'^\| `([A-Za-z0-9_]+)` \|', re.MULTILINE)
|
|
|
|
|
|
def check_links():
|
|
errors = []
|
|
files = [ROOT / 'README.md', ROOT / 'AGENTS.md', ROOT / 'deploy/README.md', *DOCS.rglob('*.md')]
|
|
for page in files:
|
|
for raw in LINK.findall(page.read_text(encoding='utf-8')):
|
|
target = unquote(raw.strip('<>').split('#', 1)[0].split('?', 1)[0])
|
|
if not target or '://' in target or target.startswith(('mailto:', '/')):
|
|
continue
|
|
if not (page.parent / target).exists():
|
|
errors.append(f'{page.relative_to(ROOT)}: отсутствует {target}')
|
|
return errors
|
|
|
|
|
|
def check_operations():
|
|
source = REGISTRY.read_text(encoding='utf-8')
|
|
source = '\n'.join(line for line in source.splitlines() if not line.lstrip().startswith('//'))
|
|
handlers_part, request_part = source.split('private static final Map<String, Class<? extends Net_Request>> REQUEST_TYPES', 1)
|
|
handlers = set(OP.findall(handlers_part))
|
|
requests = set(OP.findall(request_part))
|
|
documented = set(INDEX_OP.findall(INDEX.read_text(encoding='utf-8')))
|
|
return ([f'Нет request type для WS-операции: {op}' for op in sorted(handlers - requests)]
|
|
+ [f'Нет handler для request type: {op}' for op in sorted(requests - handlers)]
|
|
+ [f'Нет в индексе API: {op}' for op in sorted(handlers - documented)]
|
|
+ [f'Нет в реестре WS: {op}' for op in sorted(documented - handlers)])
|
|
|
|
|
|
def main():
|
|
errors = check_links() + check_operations()
|
|
for error in errors:
|
|
print(error, file=sys.stderr)
|
|
if errors:
|
|
print(f'Ошибок документации: {len(errors)}', file=sys.stderr)
|
|
return 1
|
|
print('Ссылки документации и индекс WS-операций согласованы с файлами проекта.')
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
raise SystemExit(main())
|