/
Sangak
/
ardupilot_wiki
Обзор
Документация
Войти
/
Sangak
/
ardupilot_wiki
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
scripts/cap_params.py
32 строки
955 B
Christian Clauss
Python shebangs: /usr/bin/env python3
14 апр 2026, 01:06
14 апр 2026, 01:06
f40e753
Код
Авторство
О чём код?
#!/usr/bin/env python3 ''' script to find and optionally replace param refs in rst files ''' import re from argparse import ArgumentParser parser = ArgumentParser('find and optionally replace parameters') parser.add_argument("--change", action='store_true', help="change matches to use param markup") parser.add_argument("files", nargs='+') args = parser.parse_args() for f in args.files: print(f"Processing {f}") txt = open(f, 'r').read() matches = re.findall(r'[,.\s][A-Z][A-Z0-9]+_[A-Z_]+[,.\s]', txt) matches = re.findall(r'[,.\s][A-Z]+_[A-Z_]+[,.\s]', txt) changed = False for m in matches: s = str(m) param = s.strip() s2 = f"{s[0]}:ref:`{param}<{param}>`{s[-1]}" if args.change: txt = txt.replace(s, s2) changed = True print(f"Replaced [{s}] with [{s2}]") else: print(f"Found [{s}]") if changed: open(f, 'w').write(txt)