File: make.py

package info (click to toggle)
python-dbutils 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 560 kB
  • sloc: python: 4,369; makefile: 6
file content (36 lines) | stat: -rwxr-xr-x 1,010 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python3.11

"""Build HTML from reST files."""

from pathlib import Path

from docutils.core import publish_file

print("Creating the documentation...")

for rst_file in Path().glob('*.rst'):
    rst_path = Path(rst_file)
    name = Path(rst_file).stem
    lang = Path(name).suffix
    if lang.startswith('.'):
        lang = lang[1:]
        if lang == 'zh':
            lang = 'zh_cn'
    else:
        lang = 'en'
    html_path = Path(name + '.html')
    print(name, lang)

    with rst_path.open(encoding='utf-8-sig') as source, \
            html_path.open('w', encoding='utf-8') as destination:
        output = publish_file(
            writer_name='html5', source=source, destination=destination,
            enable_exit_status=True,
            settings_overrides={
                "stylesheet_path": 'doc.css',
                "embed_stylesheet": False,
                "toc_backlinks": False,
                "language_code": lang,
                "exit_status_level": 2})

print("Done.")