]> git.openstreetmap.org Git - nominatim.git/blob - docs/mk_install_instructions.py
Merge pull request #3975 from kad-link/fix/utf8-encoding-clean
[nominatim.git] / docs / mk_install_instructions.py
1 # SPDX-License-Identifier: GPL-3.0-or-later
2 #
3 # This file is part of Nominatim. (https://nominatim.org)
4 #
5 # Copyright (C) 2024 by the Nominatim developer community.
6 from pathlib import Path
7
8 import mkdocs_gen_files
9
10 VAGRANT_PATH = Path(__file__, '..', '..', 'vagrant').resolve()
11
12 for infile in VAGRANT_PATH.glob('Install-on-*.sh'):
13     outfile = f"admin/{infile.stem}.md"
14     title = infile.stem.replace('-', ' ')
15
16     with mkdocs_gen_files.open(outfile, "w", encoding='utf-8') as outfd, \
17             infile.open(encoding='utf-8') as infd:
18         print("#", title, file=outfd)
19         has_empty = False
20         for line in infd:
21             line = line.rstrip()
22             docpos = line.find('#DOCS:')
23             if docpos >= 0:
24                 line = line[docpos + 6:]
25             elif line == '#' or line.startswith('#!'):
26                 line = ''
27             elif line.startswith('# '):
28                 line = line[2:]
29             if line or not has_empty:
30                 print(line, file=outfd)
31                 has_empty = not bool(line)
32
33     mkdocs_gen_files.set_edit_path(outfile, "docs/mk_install_instructions.py")