changes from Docutils project: reformatted docstring/help; send -h/--help output to stdout not stderr; enable exception tracebacks from Docutils; improved version checking

This commit is contained in:
David Goodger 2004-04-02 19:20:13 +00:00
parent 298122a4e5
commit 0a9b3b929c
1 changed files with 35 additions and 26 deletions

View File

@ -1,37 +1,37 @@
#!/usr/bin/env python
"""Convert PEPs to (X)HTML - courtesy of /F
Usage: %(PROGRAM)s [options] [peps]
Usage: %(PROGRAM)s [options] [<peps> ...]
Options:
-u/--user
python.org username
-u, --user
python.org username
-b/--browse
After generating the HTML, direct your web browser to view it
(using the Python webbrowser module). If both -i and -b are
given, this will browse the on-line HTML; otherwise it will
browse the local HTML. If no pep arguments are given, this
will browse PEP 0.
-b, --browse
After generating the HTML, direct your web browser to view it
(using the Python webbrowser module). If both -i and -b are
given, this will browse the on-line HTML; otherwise it will
browse the local HTML. If no pep arguments are given, this
will browse PEP 0.
-i/--install
After generating the HTML, install it and the plaintext source file
(.txt) on python.org. In that case the user's name is used in the scp
and ssh commands, unless "-u username" is given (in which case, it is
used instead). Without -i, -u is ignored.
-i, --install
After generating the HTML, install it and the plaintext source file
(.txt) on python.org. In that case the user's name is used in the scp
and ssh commands, unless "-u username" is given (in which case, it is
used instead). Without -i, -u is ignored.
-l/--local
Same as -i/--install, except install on the local machine. Use this
when logged in to the python.org machine (creosote).
-l, --local
Same as -i/--install, except install on the local machine. Use this
when logged in to the python.org machine (creosote).
-q/--quiet
Turn off verbose messages.
-q, --quiet
Turn off verbose messages.
-h/--help
Print this help message and exit.
-h, --help
Print this help message and exit.
The optional argument `peps' is a list of either pep numbers or .txt files.
The optional arguments ``peps`` are either pep numbers or .txt files.
"""
import sys
@ -81,9 +81,14 @@ COMMASPACE = ', '
def usage(code, msg=''):
print >> sys.stderr, __doc__ % globals()
"""Print usage message and exit. Uses stderr if code != 0."""
if code == 0:
out = sys.stdout
else:
out = sys.stderr
print >> out, __doc__ % globals()
if msg:
print >> sys.stderr, msg
print >> out, msg
sys.exit(code)
@ -302,7 +307,9 @@ def fix_rst_pep(inpath, input_lines, outfile):
reader_name='pep',
parser_name='restructuredtext',
writer_name='pep_html',
settings=docutils_settings)
settings=docutils_settings,
# Allow Docutils traceback if there's an exception:
settings_overrides={'traceback': 1})
outfile.write(output)
@ -423,7 +430,9 @@ def check_requirements():
'Docutils not present for "%(pep_type)s" PEP file %(inpath)s. '
'See README.txt for installation.')
else:
if docutils.__version__ < REQUIRES['docutils']:
installed = [int(part) for part in docutils.__version__.split('.')]
required = [int(part) for part in REQUIRES['docutils'].split('.')]
if installed < required:
PEP_TYPE_DISPATCH['text/x-rst'] = None
PEP_TYPE_MESSAGES['text/x-rst'] = (
'Docutils must be reinstalled for "%%(pep_type)s" PEP '