makehtml.py
上传用户:gyjinxi
上传日期:2007-01-04
资源大小:159k
文件大小:4k
- # makehtml:
- # This script generates the BoboMail Homepage
- # from the text files in the docs directory
- from bobomailrc import app_dir, pjoin, __version__
- import string, re
- from cgi import escape
- doc_dir = pjoin(app_dir, "docs")
- urlpat = re.compile(r'(w+://[^>)s]+)')
- emailpat = re.compile(r'([-+,.w]+@[-+.w]+)')
- def formatHTML(data):
- inList = 0
- html = ""
- data = string.replace(data, "nnn", "n n")
- paragraphs = string.split(data, "nn")
- if paragraphs:
- if "n" not in paragraphs[0]:
- html = html + "<h2>%s</h2>nn" % paragraphs[0]
- del paragraphs[0]
- for p in paragraphs:
- if len(p) and string.strip(p)[0] == "*":
- if not inList:
- html = html + "<ul>n"
- inList = 1
- html = html + "t<li>%sn" % makelinks(string.strip(p)[1:])
- else:
- if inList:
- html = html + "</ul>nn"
- inList = 0
- if len(p) and p[0] == " ": html = html + "<pre>%s</pre>" % makelinks(p)
- elif p == " ": html = html + "n<br>n"
- else: html = html + "<p>nt%sn</p>nn" % makelinks(p)
- if inList: html = html + "</ul>n"
- return html
- def makelinks(data):
- start, links = 0, {}
- data = escape(data)
- while 1:
- found = emailpat.search(data[start:])
- if found:
- url = found.group(1)
- links[url] = '<a href="mailto:%s">%s</a>' % (url, escape(url))
- else:
- found = urlpat.search(data[start:])
- if found:
- url = found.group(1)
- links[url] = '<a href="%s">%s</a>' % (url, escape(url))
- else: break
- start = start + found.end()
- for old, new in links.items():
- data = string.replace(data, old, new)
- return data
- header = """
- <html>
- <head>
- <title>BoboMail</title>
- <link rel="stylesheet" href="images/bobomail.css">
- </head>
- <body background="images/backgr.gif" bgcolor="white" marginheight="0" marginwidth="0">
- <table border="0" width="100%">
- <tr valign="top">
- <td><img src="images/logo.gif" alt="BoboMail" border="1"><br><p>
- <a href="http://sourceforge.net/project/?group_id=4938"><font color="white" face="Arial, Helvetica, Sans Serif">Project-Page</font></a><br>
- <a href="http://sourceforge.net/bugs/?group_id=4938"><font color="white" face="Arial, Helvetica, Sans Serif">Bug tracking</font></a><br>
- <a href="http://sourceforge.net/patch/?group_id=4938"><font color="white" face="Arial, Helvetica, Sans Serif">Patch manager</font></a><br>
- <a href="http://sourceforge.net/mail/?group_id=4938"><font color="white" face="Arial, Helvetica, Sans Serif">Mailing list</font></a><br>
- <br><br><br>
- <a href="images/shot1.gif"><font color="white" face="Arial, Helvetica, Sans Serif">Screenshot 1</font></a><br>
- <a href="images/shot2.gif"><font color="white" face="Arial, Helvetica, Sans Serif">Screenshot 2</font></a><br><br>
- <a href="http://bobomail.sourceforge.net/cgi-bin/bobomail.cgi"><font color="white" face="Arial, Helvetica, Sans Serif"><i><b>Test DEMO!</b></i></font></a><br><br>
- <b><a href="http://sourceforge.net/project/filelist.php?group_id=4938"><font color="white" face="Arial, Helvetica, Sans Serif">Download</font></a></b><br>
- </p></td>
- <td>"""
- footer = """
- </td>
- </tr>
- <tr>
- <td><tt>Special thanks to</tt> <br><a href="http://sourceforge.net">
- <img alt="SourceForge" border="0" src="http://sourceforge.net/sflogo.php?group_id=4938&type=1" alt="Sourceforge"></a></td>
- <td><hr noshade><i>Page automatically created from text-sources (see docs directory)</i></td>
- </tr>
- </table>
- </body>
- </html>
- """
- files = ["README", "INSTALL", "PROBLEMS", "TODO", "ChangeLog", "CREDITS"]
- page = '<h1>BoboMail %s<br><img alt="BoboMail" src="images/bobomail.jpg"></h1>nn' % __version__
- navbar = "nt<h4>"
- for filename in files:
- navbar = navbar + '<a href="#%s">%s</a> | ' % (filename, filename)
- fn = pjoin(doc_dir, filename)
- page = page + '<a name="%s"></a>' % filename
- page = page + formatHTML(open(fn).read())
- page = page + "<br>"
- navbar = navbar[:-2] + "<hr noshade></h4>n"
- page = navbar + page
- html = header + page + footer
- print html