[Python-checkins] CVS: python/nondist/peps pep2html.py,1.2,1.3
Fred L. Drake
python-dev@python.org
2000年7月24日 20:51:46 -0700
Update of /cvsroot/python/python/nondist/peps
In directory slayer.i.sourceforge.net:/tmp/cvs-serv26749
Modified Files:
pep2html.py
Log Message:
Revise the generated HTML to be a little nicer, but still pretty simple.
Also add a -n option to suppress installing the generated HTML at
SourceForge to allow local use.
Index: pep2html.py
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep2html.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** pep2html.py 2000年07月20日 22:44:36 1.2
--- pep2html.py 2000年07月25日 03:51:44 1.3
***************
*** 3,10 ****
convert PEP's to (X)HTML - courtesy of /F
! Syntax: pep2html [sf_username]
The user name 'sf_username' is used to upload the converted files
to the web pages at source forge.
"""
--- 3,14 ----
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.
+
"""
***************
*** 14,31 ****
# tags. but if I change that, the result doesn't look very nice...
! DTD = ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" '
! '"http://www.w3.org/TR/REC-html40/loose.dtd">')
fixpat = re.compile("((http|ftp):[-_a-zA-Z0-9/.+~:?#$=&]+)|(pep-\d+(.txt)?)|.")
! def fixanchor(match):
text = match.group(0)
link = None
if text[:5] == "http:" or text[:4] == "ftp:":
link = text
! elif text[:3] == "pep":
link = os.path.splitext(text)[0] + ".html"
if link:
! return "<a href='%s'>%s</a>" % (link, cgi.escape(link))
return cgi.escape(match.group(0)) # really slow, but it works...
--- 18,35 ----
# 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">')
fixpat = re.compile("((http|ftp):[-_a-zA-Z0-9/.+~:?#$=&]+)|(pep-\d+(.txt)?)|.")
! def fixanchor(current, match):
text = match.group(0)
link = None
if text[:5] == "http:" or text[:4] == "ftp:":
link = text
! elif text[:4] == "pep-" and text != current:
link = os.path.splitext(text)[0] + ".html"
if link:
! return "<a href='%s'>%s</a>" % (link, cgi.escape(text))
return cgi.escape(match.group(0)) # really slow, but it works...
***************
*** 34,41 ****
fi = open(infile)
fo = open(outfile, "w")
! fo.write("%s\n<html>\n" % DTD)
# head
header = []
- fo.write("<head>\n")
pep = ""
title = ""
--- 38,44 ----
fi = open(infile)
fo = open(outfile, "w")
! fo.write(DTD + "\n<html>\n<head>\n")
# head
header = []
pep = ""
title = ""
***************
*** 58,70 ****
# body
fo.write("<body bgcolor='white'>\n")
! fo.write("<pre>\n")
! fo.write("[<a href='..'>home</a>]")
! if os.path.basename(file) != "pep-0000.txt":
! fo.write(" [<a href='.'>index</a>]")
! fo.write("\n<hr />\n")
! # fo.write("\n</pre><hr /><pre>\n")
for k, v in header:
! fo.write("<b>%s:</b> %s\n" % (cgi.escape(k), cgi.escape(v)))
title = 0
while 1:
line = fi.readline()
--- 61,73 ----
# body
fo.write("<body bgcolor='white'>\n")
! fo.write("[<a href='../'>home</a>]\n")
! if os.path.basename(infile) != "pep-0000.txt":
! fo.write("[<a href='.'>index</a>]\n")
! fo.write("<hr />\n<table border='0'>\n")
for k, v in header:
! fo.write(" <tr><th align='right'>%s:</th><td>%s</td></tr>\n"
! % (cgi.escape(k), cgi.escape(v)))
title = 0
+ fo.write("</table>\n<pre>")
while 1:
line = fi.readline()
***************
*** 72,87 ****
break
if line[:1] == "\f":
! fo.write("\n<hr />\n")
# fo.write("\n</pre><hr /><pre>\n")
title = 1
! elif title >= 0:
! line = fixpat.sub(fixanchor, line)
if title:
if line.strip() == "Local Variables:":
! title = -1
! else:
! fo.write("<h3><tt>%s</tt></h3>\n" % line)
! # fo.write("</pre><h3><tt>%s</tt></h3><pre>\n" % line)
! title = 0
else:
fo.write(line)
--- 75,89 ----
break
if line[:1] == "\f":
! fo.write("<hr />")
# fo.write("\n</pre><hr /><pre>\n")
title = 1
! else:
! line = fixpat.sub(lambda x, c=infile: fixanchor(c, x), line)
if title:
if line.strip() == "Local Variables:":
! break
! fo.write("</pre>\n<h3>%s</h3>\n<pre>" % line.strip())
! # fo.write("</pre><h3><tt>%s</tt></h3><pre>\n" % line)
! title = 0
else:
fo.write(line)
***************
*** 89,103 ****
fo.write("</body>\n")
fo.write("</html>\n")
! for file in glob.glob("pep-*.txt"):
! print file, "..."
! fixfile(file, os.path.splitext(file)[0] + ".html")
!
! if len(sys.argv) == 1:
! username = ""
! elif len(sys.argv) == 2:
! username = sys.argv[1]+"@"
! else:
! raise "Syntax: "+sys.argv[0]+" [sf_username]"
!
! os.system("scp pep-*.html "+username+"shell.sourceforge.net:/home/groups/python/htdocs/peps")
--- 91,118 ----
fo.write("</body>\n")
fo.write("</html>\n")
+
+
+ def main():
+ update = 1
+ for file in glob.glob("pep-*.txt"):
+ print file, "..."
+ fixfile(file, os.path.splitext(file)[0] + ".html")
+
+ 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 " + username
+ + "shell.sourceforge.net:/home/groups/python/htdocs/peps")
+
! if __name__ == "__main__":
! main()