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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 4344 by jfenwick, Wed Feb 27 03:42:40 2013 UTC revision 4345 by jfenwick, Fri Mar 29 07:09:41 2013 UTC
# Line 17  startpackage=sys.argv[2] Line 17  startpackage=sys.argv[2]
17  startdir=os.path.join(pathdir, startpackage)  startdir=os.path.join(pathdir, startpackage)
18  outdir=sys.argv[3]  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():  def listmods():
80    W=os.walk(startdir,topdown=True)    W=os.walk(startdir,topdown=True)
81    sys.path.append(pathdir)    sys.path.append(pathdir)
# Line 29  def listmods(): Line 88  def listmods():
88    main.write('.. toctree::\n')    main.write('.. toctree::\n')
89    main.write('   :maxdepth: 4\n')    main.write('   :maxdepth: 4\n')
90    main.write('\n')    main.write('\n')
91        modset=set()
92    for z in W:    for z in W:
93        if z[0].endswith('__pycache__'): continue
94      print "Beginning ",z[0]      print "Beginning ",z[0]
95      # Now make the package name      # Now make the package name
96      n=startpackage+'.'.join(z[0][len(startdir):].split(os.path.sep))      n=startpackage+'.'.join(z[0][len(startdir):].split(os.path.sep))
97      main.write("   "+n+"\n")      dumpPackage(n, z[1], modset)
98      #Now we need to create a page for this      print "-------------"+n
     pack=open(os.path.join(outdir,n+'.rst'),'w')  
     pack.write(n+' Package\n')  
     pack.write('='*len(n)+'========\n\n')  
     pack.write('.. py:module:: '+n+'\n\n')  
     #Automodule does not seem to do what we want so we need to drill down  
     exec('import '+n+' as PP')  
     clist=[]  
     flist=[]  
     vlist=[]  
     for (name, mem) in inspect.getmembers(PP):  
       if inspect.ismodule(mem):  
     #pack.write('Module '+name+'\n')  
     pass  
       elif inspect.isclass(mem):  
     clist+=[(name, mem)]  
       elif inspect.isfunction(mem):  
     flist+=[(name, mem)]  
       else:  
     if type(mem).__module__+'.'+type(mem).__name__=='Boost.Python.function':  
       flist+=[(name, mem)]  
     else:  
       vlist+=[(name, mem)]  
     pack.write('Classes\n')  
     pack.write('-------\n')  
     for (name, mem) in clist:  
       pack.write('* `'+name+'`\n')  
     pack.write('\n')  
     for (name, mem) in clist:  
       pack.write('.. autoclass:: '+name+'\n')  
       pack.write('   :members:\n   :undoc-members:\n\n')  
     pack.write('\n')  
       
     pack.write('Functions\n')  
     pack.write('---------\n')  
     for (name, mem) in flist:  
       pack.write('.. autofunction:: '+name+'\n')  
     pack.write('\n')  
       
     pack.write('Others\n')  
     pack.write('------\n')  
     for (name, mem) in vlist:  
       pack.write('* '+name+'\n')  
     pack.write('\n')  
       
99            
100      for m in z[2]:  #This will list the files      for m in z[2]:  #This will list the files
101        if m.split('.')[1]=='pyc' and m!='__init__.pyc':        if m.split('.')[1]=='pyc' and m!='__init__.pyc':
102      print ".."+n+"."+m      print ".."+n+"."+m
103      pack.close()    l=list(modset)
104      l.sort()
105      for n in l:
106          main.write("   "+n+"\n")
107    main.write('\n')    main.write('\n')
108    main.write('Indices and Tables\n')    main.write('Indices and Tables\n')
109    main.write('==================\n')    main.write('==================\n')

Legend:
Removed from v.4344  
changed lines
  Added in v.4345

  ViewVC Help
Powered by ViewVC 1.1.26