-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_docs.py
executable file
·126 lines (91 loc) · 2.83 KB
/
write_docs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
'''
Space Telescope Science Institute
Synopsis:
Find all of the python files in a directory and write out html
pydoc documentation of them in the current working directory
Command line usage (if any):
write_docs.py directory_name
Description:
The routine finds all of the .py files in the named directory and
generates a shell script which runs pydocs to create html help
files for each .py file. It then creates a another html file
with the rootname of each of the individual files.
Primary routines:
Notes:
If you want to get an html help for a specfic package the python
command is simply
pydocs package_name
The help html files have links to the packages such as pyfits
but these are incorrect because pydocs assumes all the help
files are in the current working directory, which they are likely
not.
The does not delete help fro routines that have been deleted, which is
a problem. One could fix this, but one would then need to keep some
kind of database so that you knew what files should exist.
History:
100805 ksl Coding begun
'''
import sys
import os
import glob
import markup
def make_toplevel(dirname,names):
'''
Create an html page to point to all
of the individual help pages that have
been made
'''
# First get the name of the directory
dirname=dirname.replace('/',' ')
dirname=dirname.strip()
dirname=dirname.split()
dirname=dirname[len(dirname)-1]
print dirname
html_name='doc_'+dirname+'.html'
# Start a page
page = markup.page( )
page.init( title="Documentation for %s" % dirname)
page.h1("Documentation for python scripts in the directory %s" % dirname)
items=[]
for name in names:
item=markup.oneliner.a(name,href="./%s.html" % name)
items.append(item)
page.ul(class_='mylist' )
page.li( items, class_='myitem' )
page.ul.close( )
page.p('Warning: This page is rewritten every whenever write_docs.py is run on this directoryand so this page should not be edited')
g=open(html_name,'w')
g.write('%s' % page)
g.close()
def write_docs(dirname='../persistence'):
'''
Locate all of the .py files in dirname and
write out help in the current working directory
using pydocs
'''
search_name=dirname+'/*.py'
names=glob.glob(search_name)
print names
g=open('DoDocs','w')
roots=[]
for name in names:
words=name.split('/')
filename=words[len(words)-1]
words=filename.split('.')
root=words[0]
roots.append(root)
g.write('pydoc -w %s\n' % root)
g.close()
os.system('source DoDocs')
# Now make a page that points to all the html pages
# that have already been made
make_toplevel(dirname,roots)
# Next lines permit one to run the routine from the command line
if __name__ == "__main__":
import sys
if len(sys.argv)>1:
# doit(int(sys.argv[1]))
write_docs(sys.argv[1])
else:
print 'usage: write_docs.py dirname'