Migrate doc/make_target_table.py to Catalyst 2.x and Python 2.x
[catalyst.git] / doc / make_target_table.py
1 #!/usr/bin/env python
2 # Copyright (C) 2012 W. Trevor King <wking@drexel.edu>
3 # Copyright (C) 2012 Sebastian Pipping <sebastian@pippin.org>
4 # Licensed under GPL v2 or later
5
6 # This script should be run from the root of the catalyst source.
7
8 from __future__ import print_function
9
10 import sys as _sys
11
12 _sys.path.insert(0, 'modules')  # so we can find the `catalyst` module
13
14 import glob
15 import re
16
17
18 if __name__ == '__main__':
19         extractor = re.compile('^modules/(([^ ]+)_target).py$')
20         for filename in sorted(glob.glob('modules/*_target.py')):
21                 if 'generic' in filename:
22                         continue
23
24                 match = extractor.match(filename)
25                 target_name = match.group(2).replace('_', '-')
26                 module_name = match.group(1)
27
28                 __import__(module_name)
29                 module = _sys.modules[module_name]
30
31                 print('`%s`;;' % target_name)
32                 # Replace blank lines with `+` (asciidoc list item continuation)
33                 print(module.__doc__.strip().replace('\n\n', '\n+\n'))
34                 print('')