/[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 4576 - (show annotations)
Mon Dec 9 23:35:30 2013 UTC (5 years, 9 months ago) by sshaw
File MIME type: text/x-python
File size: 4050 byte(s)
python3ified things, replaced mixed whitespace and xrange calls
1 #!/usr/bin/env python
2
3 import os
4 import inspect
5 import sys
6
7 if len(sys.argv)!=4:
8 sys.stderr.write('Usage: startdir startpackage outputdirectory\n')
9 sys.exit(1)
10
11 #startdir='./esys'
12 #startpackage='esys'
13 #outdir='doctest'
14
15 pathdir=sys.argv[1]
16 startpackage=sys.argv[2]
17 startdir=os.path.join(pathdir, startpackage)
18 outdir=sys.argv[3]
19
20 def dumpPackage(mname, ignorelist, modset, banset):
21 modset.add(mname)
22 print "Starting dump on "+mname+' with ignore at '+str(ignorelist)
23 pack=open(os.path.join(outdir,mname+'.rst'),'w')
24 pack.write(mname+' Package\n')
25 pack.write('='*len(mname)+'========\n\n')
26 pack.write('.. py:module:: '+mname+'\n\n')
27 #Automodule does not seem to do what we want so we need to drill down
28 exec('import '+mname+' as PP')
29 clist=[]
30 flist=[]
31 vlist=[]
32 norecurse=[]
33 try:
34 norecurse=PP.__nodocorecursion
35 print "Supressing the following packages"
36 for n in norecurse:
37 print mname+'.'+n
38 banset.add(mname+'.'+n)
39 print '---------'
40 except AttributeError:
41 pass
42 # esys.escript.models does not get picked up by this loop
43 for (name, mem) in inspect.getmembers(PP):
44 print " "+name
45 if inspect.ismodule(mem):
46 if not name in ignorelist:
47 try:
48 ppfile=inspect.getfile(PP)
49 memfile=inspect.getfile(mem)
50 except:
51 continue #It will be a builtin module
52 ppdir=ppfile[:ppfile.rfind(os.path.sep)]
53 memdir=memfile[:memfile.rfind(os.path.sep)]
54 if ppdir==memdir:
55 if not mem.__name__ in modset:
56 if not mem.__name__ in banset:
57 print "About to dump "+name+"("+mem.__name__+")"
58 dumpPackage(mem.__name__, [], modset, banset)
59 print "Dump of "+mname+" complete"
60 #pack.write('Module '+name+'\n')
61 elif inspect.isclass(mem):
62 clist+=[(name, mem)]
63 elif inspect.isfunction(mem):
64 flist+=[(name, mem)]
65 else:
66 if type(mem).__module__+'.'+type(mem).__name__=='Boost.Python.function':
67 flist+=[(name, mem)]
68 else:
69 vlist+=[(name, mem)]
70 pack.write('Classes\n')
71 pack.write('-------\n')
72 for (name, mem) in clist:
73 pack.write('* `'+name+'`\n')
74 pack.write('\n')
75 for (name, mem) in clist:
76 pack.write('.. autoclass:: '+name+'\n')
77 pack.write(' :members:\n :undoc-members:\n\n')
78 pack.write('\n')
79
80 pack.write('Functions\n')
81 pack.write('---------\n')
82 for (name, mem) in flist:
83 pack.write('.. autofunction:: '+name+'\n')
84 pack.write('\n')
85
86 pack.write('Others\n')
87 pack.write('------\n')
88 for (name, mem) in vlist:
89 pack.write('* '+name+'\n')
90 pack.write('\n')
91 pack.close()
92
93 def listmods():
94 W=os.walk(startdir,topdown=True)
95 sys.path.append(pathdir)
96 main=open(os.path.join(outdir,'index.rst'),'w')
97 main.write('.. Generated by Joel\'s script\n\n')
98 main.write('Documentation for esys.escript\n')
99 main.write('==============================\n')
100 main.write('\n')
101 main.write('Contents:\n\n')
102 main.write('.. toctree::\n')
103 main.write(' :maxdepth: 4\n')
104 main.write('\n')
105 modset=set()
106 banset=set()
107 for z in W:
108 if z[0].endswith('__pycache__'): continue
109 #if z[0].find('escript')==-1: continue
110 print "Beginning ",z[0]
111 # Now make the package name
112 n=startpackage+'.'.join(z[0][len(startdir):].split(os.path.sep))
113 dumpPackage(n, z[1], modset, banset)
114 print "-------------"+n
115
116 for m in z[2]: #This will list the files
117 if m.split('.')[1]=='pyc' and m!='__init__.pyc':
118 print ".."+n+"."+m
119 print ".."+(n+'.'+m)[:-4]
120 if not (n+'.'+m)[:-4] in banset:
121 dumpPackage((n+'.'+m)[:-4],[],modset, banset)
122 l=list(modset)
123 l.sort()
124 for n in l:
125 main.write(" "+n+"\n")
126 main.write('\n')
127 main.write('Indices and Tables\n')
128 main.write('==================\n')
129 main.write('\n')
130 main.write('* :ref:`genindex`\n')
131 main.write('* :ref:`modindex`\n')
132 main.write('\n')
133 main.close()
134
135
136 listmods()

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26