/[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 4111 - (show annotations)
Fri Dec 14 01:46:13 2012 UTC (6 years, 5 months ago) by jfenwick
File MIME type: text/x-python
File size: 2571 byte(s)
Fixed the genrst script to be executable
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 startdir=sys.argv[1]
16 startpackage=sys.argv[2]
17 outdir=sys.argv[3]
18
19 def listmods():
20 W=os.walk(startdir,topdown=True)
21
22 main=open(os.path.join(outdir,'index.rst'),'w')
23 main.write('.. Generated by Joel\'s script\n\n')
24 main.write('Documentation for esys.escript\n')
25 main.write('==============================\n')
26 main.write('\n')
27 main.write('Contents:\n\n')
28 main.write('.. toctree::\n')
29 main.write(' :maxdepth: 4\n')
30 main.write('\n')
31
32 for z in W:
33 print "Beginning ",z[0]
34 # Now make the package name
35 n=startpackage+'.'.join(z[0][len(startdir):].split(os.path.sep))
36 main.write(" "+n+"\n")
37 #Now we need to create a page for this
38 pack=open(os.path.join(outdir,n+'.rst'),'w')
39 pack.write(n+' Package\n')
40 pack.write('='*len(n)+'========\n\n')
41 pack.write('.. py:module:: '+n+'\n\n')
42 #Automodule does not seem to do what we want so we need to drill down
43 exec('import '+n+' as PP')
44 clist=[]
45 flist=[]
46 vlist=[]
47 for (name, mem) in inspect.getmembers(PP):
48 if inspect.ismodule(mem):
49 #pack.write('Module '+name+'\n')
50 pass
51 elif inspect.isclass(mem):
52 clist+=[(name, mem)]
53 elif inspect.isfunction(mem):
54 flist+=[(name, mem)]
55 else:
56 if type(mem).__module__+'.'+type(mem).__name__=='Boost.Python.function':
57 flist+=[(name, mem)]
58 else:
59 vlist+=[(name, mem)]
60 pack.write('Classes\n')
61 pack.write('-------\n')
62 for (name, mem) in clist:
63 pack.write('* `'+name+'`\n')
64 pack.write('\n')
65 for (name, mem) in clist:
66 pack.write('.. autoclass:: '+name+'\n')
67 pack.write(' :members:\n :undoc-members:\n\n')
68 pack.write('\n')
69
70 pack.write('Functions\n')
71 pack.write('---------\n')
72 for (name, mem) in flist:
73 pack.write('.. autofunction:: '+name+'\n')
74 pack.write('\n')
75
76 pack.write('Others\n')
77 pack.write('------\n')
78 for (name, mem) in vlist:
79 pack.write('* '+name+'\n')
80 pack.write('\n')
81
82
83 for m in z[2]: #This will list the files
84 if m.split('.')[1]=='pyc' and m!='__init__.pyc':
85 print ".."+n+"."+m
86 pack.close()
87 main.write('\n')
88 main.write('Indicies and Tables\n')
89 main.write('===================\n')
90 main.write('\n')
91 main.write('* :ref:`genindex`\n')
92 main.write('* :ref:`modindex`\n')
93 main.write('\n')
94 main.close()
95
96
97 listmods()

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26