[Python-checkins] CVS: python/nondist/peps pep2html.py,1.9,1.10
Barry Warsaw
python-dev@python.org
Mon, 14 Aug 2000 22:53:22 -0700
Update of /cvsroot/python/python/nondist/peps
In directory slayer.i.sourceforge.net:/tmp/cvs-serv26324
Modified Files:
pep2html.py
Log Message:
Changed the sense of the default behavior. No longer installs the
.html files in SF by default; you must explicitly include the
-i/--install option in order to upload.
Also, added -h/--help and migrated to getopt for switch parsing.
Included a usage() function.
Some cosmetic changes.
Index: pep2html.py
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep2html.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** pep2html.py 2000/08/11 22:18:04 1.9
--- pep2html.py 2000/08/15 05:53:19 1.10
***************
*** 3,25 ****
convert PEP's to (X)HTML - courtesy of /F
! Syntax: pep2html [-n] [sf_username]
! The user name 'sf_username' is used to upload the converted files
! to the web pages at source forge.
! If -n is given, the script doesn't actually try to install the
! generated HTML at SourceForge.
"""
! import cgi, glob, os, re, sys
- # this doesn't validate -- you cannot use <hr> and <h3> inside <pre>
- # tags. but if I change that, the result doesn't look very nice...
! HOST = "shell.sourceforge.net" # host for update
! HDIR = "/home/groups/python/htdocs/peps" # target host directory
LOCALVARS = "Local Variables:"
DTD = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"\n'
' "http://www.w3.org/TR/REC-html40/loose.dtd">')
--- 3,37 ----
convert PEP's to (X)HTML - courtesy of /F
! Usage: %(PROGRAM)s [options] [sf_username]
! Options:
! -i/--install
! After generating the HTML, install it SourceForge. In that case the
! user's name is used in the scp and ssh commands, unless sf_username is
! given (in which case, it is used instead). Without -i, sf_username is
! ignored.
+ -h/--help
+ Print this help message and exit.
"""
! import sys
! import os
! import re
! import cgi
! import glob
! import getopt
!
! PROGRAM = sys.argv[0]
!
! HOST = "shell.sourceforge.net" # host for update
! HDIR = "/home/groups/python/htdocs/peps" # target host directory
LOCALVARS = "Local Variables:"
+ # The generated HTML doesn't validate -- you cannot use <hr> and <h3> inside
+ # <pre> tags. But if I change that, the result doesn't look very nice...
DTD = ('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"\n'
' "http://www.w3.org/TR/REC-html40/loose.dtd">')
***************
*** 27,30 ****
--- 39,55 ----
fixpat = re.compile("((http|ftp):[-_a-zA-Z0-9/.+~:?#$=&]+)|(pep-\d+(.txt)?)|.")
+
+
+ def usage(code, msg=''):
+ sys.stderr.write(__doc__ % globals() + '\n')
+ if msg:
+ msg = str(msg)
+ if msg[-1] <> '\n':
+ msg = msg + '\n'
+ sys.stderr.write(msg)
+ sys.exit(code)
+
+
+
def fixanchor(current, match):
text = match.group(0)
***************
*** 38,41 ****
--- 63,68 ----
return cgi.escape(match.group(0)) # really slow, but it works...
+
+
def fixfile(infile, outfile):
# convert plain text pep to minimal XHTML markup
***************
*** 107,112 ****
def main():
! update = 1
for file in glob.glob("pep-*.txt"):
newfile = os.path.splitext(file)[0] + ".html"
--- 134,160 ----
+
def main():
! # defaults
! update = 0
! username = ''
!
! try:
! opts, args = getopt.getopt(sys.argv[1:], 'ih', ['install', 'help'])
! except getopt.error, msg:
! usage(1, msg)
!
! if args:
! username = args[0] + '@'
! del args[0]
! if args:
! usage(1, 'unexpected arguments')
!
! for opt, arg in opts:
! if opt in ('-h', '--help'):
! usage(0)
! elif opt in ('-i', '--install'):
! update = 1
!
for file in glob.glob("pep-*.txt"):
newfile = os.path.splitext(file)[0] + ".html"
***************
*** 114,128 ****
fixfile(file, newfile)
- if len(sys.argv) > 1 and sys.argv[1] == "-n":
- update = 0
- del sys.argv[1]
-
- if len(sys.argv) == 1:
- username = ""
- elif len(sys.argv) == 2:
- username = sys.argv[1]+"@"
- else:
- raise "Syntax: "+sys.argv[0]+" [-n] [sf_username]"
-
if update:
os.system("scp pep-*.html style.css " + username + HOST + ":" + HDIR)
--- 162,165 ----
***************
*** 130,133 ****
--- 167,171 ----
+
if __name__ == "__main__":
main()