5
__author__ = "David Nolden<david.kde@art-master.de>, Ka-Ping Yee <ping@lfw.org>"
6
__version__ = "6 April 2006"
8
import sys, imp, os, stat, re, types, cgi
10
from string import expandtabs, find, join, lower, split, strip, rstrip
16
def cleanlinks(string):
17
"""Changes the links to work with the pydoc:-notation"""
19
string = str(string).replace(".html","")
25
pos = string.find(mark, pos)
27
finalstring += string[opos:]
29
finalstring += string[opos:pos+l]
31
if(string[pos] == '#' or string.find(":/",pos, pos+10) != -1): #leave local jumps or external references untouched
33
finalstring += "pydoc:"
34
if(string[pos] == "." and string[pos+1] == "\""):
36
finalstring += "modules"
41
#This maximum depth was introduced because the program needs a very long time to
42
#complete the task in big file-system-trees(like my home), and can be invoked by a simple pydoc:.
43
#and cannot be stopped through the browser(just by killing python)
46
def writedocs(path, pkgpath='', depth=0, notprocessed=[]):
52
if os.path.isdir(path):
53
if(depth > __maxdepth):
54
notprocessed.append(path)
57
for file in os.listdir(dir):
58
path = os.path.join(dir, file)
59
if os.path.isdir(path):
60
writedocs(path, file + '.' + pkgpath, depth)
61
if os.path.isfile(path):
62
writedocs(path, pkgpath, depth)
63
if os.path.isfile(path):
64
modname = pydoc.inspect.getmodulename(path)
66
writedoc(pkgpath + modname)
69
if(len(notprocessed) != 0):
70
print "<br> the following paths were not processed because they are deeper than the maximum depth of " + str(__maxdepth) + ":<br>"
71
for x in notprocessed:
72
print cgi.escape(x) + " <br>"
74
def writedoc(key,top=False):
75
"""Write HTML documentation to a file in the current directory."""
76
if(type(key) == str and (key == "modules" or key == "/.")):
77
heading = pydoc.html.heading(
78
'<br><big><big><strong> '
79
'Python: Index of Modules'
80
'</strong></big></big>',
83
for name in sys.builtin_module_names:
84
builtins.append('<a href="%s">%s</a>' % (cgi.escape(name,quote=True), cgi.escape(name)))
85
indices = ['<p>Built-in modules: ' + cgi.escape(join(builtins, ', '))]
87
for dir in pydoc.pathdirs():
88
indices.append(pydoc.html.index(dir, seen))
89
print cleanlinks(heading + join(indices))
92
if(type(key) != types.ModuleType):
93
object = pydoc.locate(key)
94
if(object == None and top):
95
print "could not locate module/object for key " + \
96
cgi.escape(key) + "<br><a href=\"pydoc:modules\">go to index</a>";
101
print cleanlinks(pydoc.html.page(pydoc.describe(object), pydoc.html.document(object)))
105
if __name__ == '__main__':
110
opts, args = getopt.getopt(sys.argv[1:], 'k:p:w')
113
print "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
114
print "</head><body>"
119
if os.path.isdir(arg): writedocs(arg)
121
if os.path.isfile(arg):
122
arg = pydoc.importfile(arg)
124
except pydoc.ErrorDuringImport, value:
125
print 'problem in %s - %s' % (
126
cgi.escape(value.filename), cgi.escape(value.exc))
130
except (getopt.error, BadUsage):
131
print "need parameters\n"