3 # Copyright (C) 2010-2012 Chris Ball <cjb@laptop.org>
4 # W. Trevor King <wking@tremily.us>
6 # This file is part of Bugs Everywhere.
8 # Bugs Everywhere is free software: you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by the Free
10 # Software Foundation, either version 2 of the License, or (at your option) any
13 # Bugs Everywhere is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 # You should have received a copy of the GNU General Public License along with
19 # Bugs Everywhere. If not, see <http://www.gnu.org/licenses/>.
21 """Auto-generate reStructuredText of the libbe module tree for Sphinx.
27 sys.path.insert(0, os.path.abspath('..'))
28 from test import python_tree
31 t = ':py:mod:`%s`' % modname
33 return '\n'.join([delim, t, delim, '', ''])
35 def automodule(modname):
37 '.. automodule:: %s' % modname,
42 def toctree(children):
43 if len(children) == 0:
50 ' %s.txt' % c for c in sorted(children)
53 def make_module_txt(modname, children, subdir='libbe'):
54 filename = os.path.join(subdir, '%s.txt' % modname)
55 if not os.path.exists(subdir):
57 if os.path.exists(filename):
58 return None # don't overwrite potentially hand-written files.
59 f = file(filename, 'w')
60 f.write(title(modname))
61 f.write(automodule(modname))
62 f.write(toctree(children))
65 if __name__ == '__main__':
66 pt = python_tree(root_path='../libbe', root_modname='libbe')
67 for node in pt.traverse():
68 make_module_txt(node.modname, [c.modname for c in node])