/[escript]/branches/doubleplusgood/doc/sphinx_api/genrst.py
ViewVC logotype

Contents of /branches/doubleplusgood/doc/sphinx_api/genrst.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4345 - (show annotations)
Fri Mar 29 07:09:41 2013 UTC (5 years, 11 months ago) by jfenwick
File MIME type: text/x-python
File size: 3329 byte(s)
Spelling fixes
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):
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 for (name, mem) in inspect.getmembers(PP):
33 if inspect.ismodule(mem):
34 if not name in ignorelist:
35 try:
36 ppfile=inspect.getfile(PP)
37 memfile=inspect.getfile(mem)
38 except:
39 continue #It will be a builtin module
40 ppdir=ppfile[:ppfile.rfind(os.path.sep)]
41 memdir=memfile[:memfile.rfind(os.path.sep)]
42 if ppdir==memdir:
43 print "About to dump "+name
44 dumpPackage(mem.__name__, [], modset)
45 print "Dump of "+mname+" complete"
46 #pack.write('Module '+name+'\n')
47 elif inspect.isclass(mem):
48 clist+=[(name, mem)]
49 elif inspect.isfunction(mem):
50 flist+=[(name, mem)]
51 else:
52 if type(mem).__module__+'.'+type(mem).__name__=='Boost.Python.function':
53 flist+=[(name, mem)]
54 else:
55 vlist+=[(name, mem)]
56 pack.write('Classes\n')
57 pack.write('-------\n')
58 for (name, mem) in clist:
59 pack.write('* `'+name+'`\n')
60 pack.write('\n')
61 for (name, mem) in clist:
62 pack.write('.. autoclass:: '+name+'\n')
63 pack.write(' :members:\n :undoc-members:\n\n')
64 pack.write('\n')
65
66 pack.write('Functions\n')
67 pack.write('---------\n')
68 for (name, mem) in flist:
69 pack.write('.. autofunction:: '+name+'\n')
70 pack.write('\n')
71
72 pack.write('Others\n')
73 pack.write('------\n')
74 for (name, mem) in vlist:
75 pack.write('* '+name+'\n')
76 pack.write('\n')
77 pack.close()
78
79 def listmods():
80 W=os.walk(startdir,topdown=True)
81 sys.path.append(pathdir)
82 main=open(os.path.join(outdir,'index.rst'),'w')
83 main.write('.. Generated by Joel\'s script\n\n')
84 main.write('Documentation for esys.escript\n')
85 main.write('==============================\n')
86 main.write('\n')
87 main.write('Contents:\n\n')
88 main.write('.. toctree::\n')
89 main.write(' :maxdepth: 4\n')
90 main.write('\n')
91 modset=set()
92 for z in W:
93 if z[0].endswith('__pycache__'): continue
94 print "Beginning ",z[0]
95 # Now make the package name
96 n=startpackage+'.'.join(z[0][len(startdir):].split(os.path.sep))
97 dumpPackage(n, z[1], modset)
98 print "-------------"+n
99
100 for m in z[2]: #This will list the files
101 if m.split('.')[1]=='pyc' and m!='__init__.pyc':
102 print ".."+n+"."+m
103 l=list(modset)
104 l.sort()
105 for n in l:
106 main.write(" "+n+"\n")
107 main.write('\n')
108 main.write('Indices and Tables\n')
109 main.write('==================\n')
110 main.write('\n')
111 main.write('* :ref:`genindex`\n')
112 main.write('* :ref:`modindex`\n')
113 main.write('\n')
114 main.close()
115
116
117 listmods()

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26