44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Build `## Authors — EN → RU` table for a section SUMMARY from AUTHORS-EN.md + dossiers.
|
|
Usage: python3 tools/make_authors_table.py <section>"""
|
|
import re, sys, os
|
|
|
|
def ru_name_of(dossier):
|
|
if not os.path.exists(dossier):
|
|
return '—'
|
|
c = open(dossier, encoding='utf-8').read()
|
|
# bold field forms
|
|
for m in re.finditer(r'\*\*RU name[^:]*:\*\* (.+)', c):
|
|
return m.group(1).strip()
|
|
# section forms
|
|
m = re.search(r'^(?:## |\*\*)?RU name[^:*\n]*:?\*\*?\n(.+)', c, re.M)
|
|
if m:
|
|
return m.group(1).strip()
|
|
m = re.search(r'^## [^\n]*RU name[^\n]*\n+(.+)', c, re.M | re.I)
|
|
if m:
|
|
return m.group(1).strip()
|
|
return '—'
|
|
|
|
def main():
|
|
sec = sys.argv[1]
|
|
idx = f'sections/{sec}/AUTHORS-EN.md'
|
|
c = open(idx).read()
|
|
rows = []
|
|
for l in c.split('\n'):
|
|
if l.startswith('|') and not re.match(r'^\|\s*item', l) and not re.match(r'^\|[-\s|]+\|', l):
|
|
cells = [x.strip() for x in l.strip().strip('|').split('|')]
|
|
if len(cells) >= 3:
|
|
items, en, d = cells[0], cells[1], cells[2]
|
|
if d.startswith('..'):
|
|
d = os.path.normpath(os.path.join('sections', sec, d))
|
|
else:
|
|
d = d.lstrip('./')
|
|
rows.append((items, en, ru_name_of(d)))
|
|
out = ['| item(s) | EN author | RU name | verified via |',
|
|
'|---------|-----------|---------|--------------|']
|
|
for items, en, ru in rows:
|
|
out.append(f'| {items} | {en} | {ru} | dossier |')
|
|
print('\n'.join(out))
|
|
|
|
if __name__ == '__main__':
|
|
main()
|