#!/usr/bin/env python """ """ __author__ = "David Nolden, Ka-Ping Yee " __version__ = "6 April 2006" import sys, imp, os, stat, re, types, cgi from repr import Repr from string import expandtabs, find, join, lower, split, strip, rstrip import pydoc def cleanlinks(string): """Changes the links to work with the pydoc:-notation""" finalstring = "" string = str(string).replace(".html","") pos = 0 mark = " __maxdepth): notprocessed.append(path) return dir = path for file in os.listdir(dir): path = os.path.join(dir, file) if os.path.isdir(path): writedocs(path, file + '.' + pkgpath, depth) if os.path.isfile(path): writedocs(path, pkgpath, depth) if os.path.isfile(path): modname = pydoc.inspect.getmodulename(path) if modname: writedoc(pkgpath + modname) if(depth == 1): if(len(notprocessed) != 0): print "
the following paths were not processed because they are deeper than the maximum depth of " + str(__maxdepth) + ":
" for x in notprocessed: print cgi.escape(x) + "
" def writedoc(key,top=False): """Write HTML documentation to a file in the current directory.""" if(type(key) == str and (key == "modules" or key == "/.")): heading = pydoc.html.heading( '
 ' 'Python: Index of Modules' '', '#ffffff', '#7799ee') builtins = [] for name in sys.builtin_module_names: builtins.append('
%s' % (cgi.escape(name,quote=True), cgi.escape(name))) indices = ['

Built-in modules: ' + cgi.escape(join(builtins, ', '))] seen = {} for dir in pydoc.pathdirs(): indices.append(pydoc.html.index(dir, seen)) print cleanlinks(heading + join(indices)) return if(type(key) != types.ModuleType): object = pydoc.locate(key) if(object == None and top): print "could not locate module/object for key " + \ cgi.escape(key) + "
go to index"; else: object = key if object: print cleanlinks(pydoc.html.page(pydoc.describe(object), pydoc.html.document(object))) if __name__ == '__main__': import getopt class BadUsage: pass try: opts, args = getopt.getopt(sys.argv[1:], 'k:p:w') print "" print "" print "" if args: for arg in args: try: if os.path.isdir(arg): writedocs(arg) if os.path.isfile(arg): arg = pydoc.importfile(arg) writedoc(arg, True) except pydoc.ErrorDuringImport, value: print 'problem in %s - %s' % ( cgi.escape(value.filename), cgi.escape(value.exc)) else: raise BadUsage except (getopt.error, BadUsage): print "need parameters\n"