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 #!/usr/bin/env python
"""Convert PEPs to (X)HTML - courtesy of /F """Convert PEPs to (X)HTML - courtesy of /F
Usage: %(PROGRAM)s [options] [peps] Usage: %(PROGRAM)s [options] [<peps> ...]
Options: Options:
-u/--user -u, --user
python.org username python.org username
-b/--browse -b, --browse
After generating the HTML, direct your web browser to view it After generating the HTML, direct your web browser to view it
(using the Python webbrowser module). If both -i and -b are (using the Python webbrowser module). If both -i and -b are
given, this will browse the on-line HTML; otherwise it will given, this will browse the on-line HTML; otherwise it will
browse the local HTML. If no pep arguments are given, this browse the local HTML. If no pep arguments are given, this
will browse PEP 0. will browse PEP 0.
-i/--install -i, --install
After generating the HTML, install it and the plaintext source file 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 (.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 and ssh commands, unless "-u username" is given (in which case, it is
used instead). Without -i, -u is ignored. used instead). Without -i, -u is ignored.
-l/--local -l, --local
Same as -i/--install, except install on the local machine. Use this Same as -i/--install, except install on the local machine. Use this
when logged in to the python.org machine (creosote). when logged in to the python.org machine (creosote).
-q/--quiet -q, --quiet
Turn off verbose messages. Turn off verbose messages.
-h/--help -h, --help
Print this help message and exit. 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 import sys
@ -81,9 +81,14 @@ COMMASPACE = ', '
def usage(code, msg=''): 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: if msg:
print >> sys.stderr, msg print >> out, msg
sys.exit(code) sys.exit(code)
@ -302,7 +307,9 @@ def fix_rst_pep(inpath, input_lines, outfile):
reader_name='pep', reader_name='pep',
parser_name='restructuredtext', parser_name='restructuredtext',
writer_name='pep_html', 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) outfile.write(output)
@ -423,7 +430,9 @@ def check_requirements():
'Docutils not present for "%(pep_type)s" PEP file %(inpath)s. ' 'Docutils not present for "%(pep_type)s" PEP file %(inpath)s. '
'See README.txt for installation.') 'See README.txt for installation.')
else: 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_DISPATCH['text/x-rst'] = None
PEP_TYPE_MESSAGES['text/x-rst'] = ( PEP_TYPE_MESSAGES['text/x-rst'] = (
'Docutils must be reinstalled for "%%(pep_type)s" PEP ' 'Docutils must be reinstalled for "%%(pep_type)s" PEP '