summaryrefslogtreecommitdiff
path: root/cmake/list-manpages.py
blob: 42bf0d83093253a59cc2a96c25436af93bc3baf6 (plain)
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
#!/usr/bin/env python

# Find manual pages to be generated
# argv1 = doc dir containing conf.py
# argv2 = manpage directory to contain generated manpages

import importlib.util
import os.path
import pathlib
import sys

if __name__ == "__main__":

    if len(sys.argv) != 3:
        print("Usage: {} sphinx-srcdir sphinx-builddir".format(sys.argv[0]), file=sys.stderr)
        sys.exit(2)

    conf_dir = os.path.abspath(sys.argv[1])
    conf_path = os.path.join(conf_dir, 'conf.py')
    spec = importlib.util.spec_from_file_location('conf', conf_path)
    conf = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(conf)

    if hasattr(conf, 'man_pages'):
        for man in conf.man_pages:
            man_path = os.path.join(sys.argv[2], "%s.%s" % (man[1], man[4]))
            man_path_posix = pathlib.PureWindowsPath(man_path).as_posix()
            print(man_path_posix)
    else:
        print("No man_pages array in {}".format(conf_path), file=sys.stderr)
        sys.exit(3)