From: Andrew M. Kuchling Date: Wed, 28 Feb 2001 20:55:10 +0000 (+0000) Subject: Add script form of pydoc so that it's present in beta1. Currently X-Git-Tag: v2.1b1~125 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b68ef5081dcdd75c38f84c451038785df44a0c42;p=python Add script form of pydoc so that it's present in beta1. Currently this just copies the __name__=='__main__' logic from pydoc.py. ?!ng can decide whether he wants to create a main() in pydoc, or rip it out of pydoc.py completely. --- diff --git a/Tools/scripts/pydoc b/Tools/scripts/pydoc new file mode 100755 index 0000000000..a1dcbcc307 --- /dev/null +++ b/Tools/scripts/pydoc @@ -0,0 +1,78 @@ +#!/usr/bin/env python + +# -------------------------------------------------- command-line interface + +import sys, os, pydoc +from string import lower + +if __name__ == '__main__': + import getopt + class BadUsage: pass + + try: + opts, args = getopt.getopt(sys.argv[1:], 'k:p:w') + writing = 0 + + for opt, val in opts: + if opt == '-k': + pydoc.apropos(lower(val)) + break + if opt == '-p': + try: + port = int(val) + except ValueError: + raise BadUsage + def ready(port=port): + print 'server ready at http://127.0.0.1:%d/' % port + pydoc.serve(('127.0.0.1', port), ready) + break + if opt == '-w': + if not args: raise BadUsage + writing = 1 + else: + if args: + for arg in args: + try: + if os.path.isfile(arg): + arg = pydoc.importfile(arg) + if writing: + if os.path.isdir(arg): pydoc.writedocs(arg) + else: pydoc.writedoc(arg) + else: pydoc.man(arg) + except pydoc.DocImportError, value: + print 'problem in %s - %s' % ( + value.filename, value.args) + else: + if sys.platform in ['mac', 'win', 'win32', 'nt']: + # GUI platforms with threading + import threading + ready = threading.Event() + address = ('127.0.0.1', 12346) + threading.Thread( + target=pydoc.serve, args=(address, ready.set)).start() + ready.wait() + import webbrowser + webbrowser.open('http://127.0.0.1:12346/') + else: + raise BadUsage + + except (getopt.error, BadUsage): + print """%s ... + Show documentation on something. + may be the name of a Python function, module, or package, + or a dotted reference to a class or function within a module or + module in a package, or the filename of a Python module to import. + +%s -k + Search for a keyword in the synopsis lines of all modules. + +%s -p + Start an HTTP server on the given port on the local machine. + +%s -w ... + Write out the HTML documentation for a module to a file. + +%s -w + Write out the HTML documentation for all modules in the tree + under a given directory to files in the current directory. +""" % ((sys.argv[0],) * 5)