/[escript]/trunk/doc/sphinx_api/genrst.py
ViewVC logotype

Contents of /trunk/doc/sphinx_api/genrst.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5707 - (show annotations)
Mon Jun 29 03:59:06 2015 UTC (3 years, 8 months ago) by sshaw
File MIME type: text/x-python
File size: 4945 byte(s)
adding copyright headers to files without copyright info, moved header to top of file in some cases where it wasn't
1 #!/usr/bin/env python
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2015 by The University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 from __future__ import division, print_function
18
19 import os
20 import inspect
21 import sys
22
23 if len(sys.argv)!=4:
24 sys.stderr.write('Usage: startdir startpackage outputdirectory\n')
25 sys.exit(1)
26
27 #startdir='./esys'
28 #startpackage='esys'
29 #outdir='doctest'
30
31 pathdir=sys.argv[1]
32 startpackage=sys.argv[2]
33 startdir=os.path.join(pathdir, startpackage)
34 outdir=sys.argv[3]
35
36 def dumpPackage(mname, ignorelist, modset, banset):
37 try:
38 exec('import '+mname+' as PP')
39 except ImportError:
40 return
41 modset.add(mname)
42 print("Starting dump on "+mname+' with ignore at '+str(ignorelist))
43 pack=open(os.path.join(outdir,mname+'.rst'),'w')
44 pack.write(mname+' Package\n')
45 pack.write('='*len(mname)+'========\n\n')
46 # pack.write('.. py:module:: '+mname+'\n\n')
47 moddoc = inspect.getdoc(PP)
48 if moddoc:
49 pack.write(".. automodule:: %s\n :synopsis: %s\n"%(mname, "".join(moddoc.replace("\n\n", "\n").replace("\n", " "))))
50 #Automodule does not seem to do what we want so we need to drill down
51 clist=[]
52 flist=[]
53 vlist=[]
54 norecurse=[]
55 try:
56 norecurse=PP.__nodocorecursion
57 print("Supressing the following packages")
58 for n in norecurse:
59 print(mname+'.'+n)
60 banset.add(mname+'.'+n)
61 print('---------')
62 except AttributeError:
63 pass
64 # esys.escript.models does not get picked up by this loop
65 for (name, mem) in inspect.getmembers(PP):
66 print(" "+name)
67 if inspect.ismodule(mem):
68 if not name in ignorelist:
69 try:
70 ppfile=inspect.getfile(PP)
71 memfile=inspect.getfile(mem)
72 except:
73 continue #It will be a builtin module
74 ppdir=ppfile[:ppfile.rfind(os.path.sep)]
75 memdir=memfile[:memfile.rfind(os.path.sep)]
76 if ppdir==memdir:
77 if not mem.__name__ in modset:
78 if not mem.__name__ in banset:
79 print("About to dump "+name+"("+mem.__name__+")")
80 dumpPackage(mem.__name__, [], modset, banset)
81 print("Dump of "+mname+" complete")
82 #pack.write('Module '+name+'\n')
83 elif inspect.isclass(mem):
84 clist+=[(name, mem)]
85 elif inspect.isfunction(mem):
86 flist+=[(name, mem)]
87 else:
88 if type(mem).__module__+'.'+type(mem).__name__=='Boost.Python.function':
89 flist+=[(name, mem)]
90 else:
91 vlist+=[(name, mem)]
92 pack.write('\nClasses\n')
93 pack.write('-------\n')
94 for (name, mem) in clist:
95 pack.write('* `'+name+'`\n')
96 pack.write('\n')
97 for (name, mem) in clist:
98 pack.write('.. autoclass:: '+name+'\n')
99 pack.write(' :members:\n :undoc-members:\n\n .. automethod:: __init__\n\n')
100 pack.write('\n')
101
102 pack.write('Functions\n')
103 pack.write('---------\n')
104 for (name, mem) in flist:
105 pack.write('.. autofunction:: '+name+'\n')
106 pack.write('\n')
107
108 pack.write('Others\n')
109 pack.write('------\n')
110 for (name, mem) in vlist:
111 pack.write('* '+name+'\n')
112 pack.write('\n')
113 pack.close()
114
115 def listmods():
116 W=os.walk(startdir,topdown=True)
117 sys.path.append(pathdir)
118 main=open(os.path.join(outdir,'index.rst'),'w')
119 main.write('.. Generated by Joel\'s script\n\n')
120 main.write('Documentation for esys.escript\n')
121 main.write('==============================\n')
122 main.write('\n')
123 main.write('Contents:\n\n')
124 main.write('.. toctree::\n')
125 main.write(' :maxdepth: 4\n')
126 main.write('\n')
127 modset=set()
128 banset=set()
129 for z in W:
130 if z[0].endswith('__pycache__'): continue
131 #if z[0].find('escript')==-1: continue
132 print("Beginning ",z[0])
133 # Now make the package name
134 n=startpackage+'.'.join(z[0][len(startdir):].split(os.path.sep))
135 dumpPackage(n, z[1], modset, banset)
136 print("-------------"+n)
137
138 for m in z[2]: #This will list the files
139 if m.split('.')[1]=='pyc' and m!='__init__.pyc':
140 print(".."+n+"."+m)
141 print(".."+(n+'.'+m)[:-4])
142 if not (n+'.'+m)[:-4] in banset:
143 dumpPackage((n+'.'+m)[:-4],[],modset, banset)
144 l=list(modset)
145 l.sort()
146 for n in l:
147 main.write(" "+n+"\n")
148 main.write('\n')
149 main.write('Indices and Tables\n')
150 main.write('==================\n')
151 main.write('\n')
152 main.write('* :ref:`genindex`\n')
153 main.write('* :ref:`modindex`\n')
154 main.write('\n')
155 main.close()
156
157
158 listmods()

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26