1 | from __future__ import with_statement |
---|
2 | import os.path |
---|
3 | |
---|
4 | MODULE_TEMPLATE=""".. Autogenerated by genmods.py |
---|
5 | |
---|
6 | ****************************************************************************** |
---|
7 | %(name)s |
---|
8 | ****************************************************************************** |
---|
9 | |
---|
10 | :mod:`%(package)s.%(module)s` |
---|
11 | ============================================================================== |
---|
12 | |
---|
13 | .. automodule:: %(package)s.%(module)s |
---|
14 | :members: |
---|
15 | :undoc-members: |
---|
16 | :inherited-members: |
---|
17 | :show-inheritance: |
---|
18 | :special-members: |
---|
19 | :private-members: |
---|
20 | """ |
---|
21 | |
---|
22 | INDEX_TEMPLATE=""".. Autogenerated by genmods.py |
---|
23 | |
---|
24 | .. _api-index: |
---|
25 | |
---|
26 | ############################################################################## |
---|
27 | %(package_name)s |
---|
28 | ############################################################################## |
---|
29 | |
---|
30 | .. only:: html |
---|
31 | |
---|
32 | :Release: |version| |
---|
33 | :Date: |today| |
---|
34 | |
---|
35 | .. toctree:: |
---|
36 | |
---|
37 | %(rsts)s |
---|
38 | """ |
---|
39 | |
---|
40 | |
---|
41 | def genfiles(package, package_name, modules, dir='api'): |
---|
42 | |
---|
43 | if not os.path.exists(dir): |
---|
44 | os.makedirs(dir) |
---|
45 | |
---|
46 | for module,name in modules: |
---|
47 | with open(os.path.join(dir,module+'.rst'), 'w') as f: |
---|
48 | f.write(MODULE_TEMPLATE%locals()) |
---|
49 | |
---|
50 | rsts = "\n ".join(module+'.rst' for module,name in modules) |
---|
51 | with open(os.path.join(dir,'index.rst'),'w') as f: |
---|
52 | f.write(INDEX_TEMPLATE%locals()) |
---|
53 | |
---|
54 | modules = [] |
---|
55 | path = os.path.dirname(os.path.join('..', '..', 'sanscalculator')) |
---|
56 | path = os.path.join(path, 'src', 'sans', 'calculator') |
---|
57 | list = os.listdir(path) |
---|
58 | |
---|
59 | for item in list: |
---|
60 | toks = os.path.splitext(os.path.basename(item)) |
---|
61 | if toks[1]=='.py' and toks[0] not in ["__init__"]: |
---|
62 | exec "module = ('%s', '%s')"%(toks[0], toks[0]) |
---|
63 | modules.append(module) |
---|
64 | |
---|
65 | package='sans.calculator' |
---|
66 | package_name='Reference' |
---|
67 | genfiles(package, package_name, modules) |
---|
68 | |
---|
69 | if __name__ == "__main__": |
---|
70 | genfiles(package, package_name, modules, dir='api') |
---|
71 | print "Sphinx: generate .rst files complete..." |
---|