File: generate.py

package info (click to toggle)
ecbuild 3.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,068 kB
  • sloc: sh: 1,404; perl: 732; f90: 472; cpp: 466; python: 383; ansic: 304; fortran: 43; makefile: 15
file content (27 lines) | stat: -rw-r--r-- 788 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python

"""Generate sphinx documentation tree for ecBuild CMake macros."""

from glob import glob
from os import makedirs, path
import sys

TOC = [('macros', 'ecbuild*.cmake'),
       ('find', 'Find*.cmake'),
       ('contrib', 'contrib/*.cmake')]

CWD = path.abspath(path.dirname(__file__))


def generate(basedir):
    for section, pattern in TOC:
        section = path.join(CWD, section)
        if not path.exists(section):
            makedirs(section)
        for m in sorted(glob(path.join(basedir, pattern))):
            base = path.splitext(path.basename(m))[0]
            with open(path.join(section, base) + '.rst', 'w') as c:
                c.write('.. cmake-module :: %s\n' % path.relpath(m, section))

if __name__ == '__main__':
    generate(sys.argv[1])