All pastes #147816 Raw Edit

Gloubi

public python v1 · immutable
#147816 ·published 2006-08-24 17:42 UTC
rendered paste body
#!/usr/bin/env pythonimport os, os.path, re, sys, gzipfrom time import gmtime, strftimedef list_packages(distro, branch):        pkg_file = "dists/" + distro + "/" + branch + "/binary-i386/Packages.gz"    f=gzip.GzipFile(pkg_file, 'r')    contents=f.read()    f.close()        pkg_re = re.compile(r"Package: (.*)")    ver_re = re.compile(r"Version: (.*)")    desc_re = re.compile(r"Description: (.*)")    arch_re = re.compile(r"Architecture: (.*)")    pkg_list = pkg_re.search(contents)    ver_list = ver_re.search(contents)    desc_list = desc_re.search(contents)    arch_list = arch_re.search(contents)        pkg_i = pkg_re.finditer(contents)    ver_i = ver_re.finditer(contents)    desc_i = desc_re.finditer(contents)    arch_i = arch_re.finditer(contents)    html_table = ""    try:        while 1:            pkg = pkg_i.next()            ver = ver_i.next()            desc = desc_i.next()            arch = arch_i.next()            html_table = html_table + """    <tr>      <td class=\"pkgLeft\"><a href=\"dists/""" + distro + "/" + \            branch + "/binary-i386/" + pkg.group(1) + "_" + \            ver.group(1) + "_" + arch.group(1) + ".deb\">" + \            pkg.group(1) + """</a></td>      <td class=\"pkgCenter\">""" + ver.group(1) + """</td>      <td class=\"pkgRight\">""" + desc.group(1) + """</td>    </tr>"""          except StopIteration: pass    html = """<h3>""" + distro +""" """ + branch + """:</h3><div class=\"pkglist\">  <table>    <tr><th>Package</th><th>Version</th><th>Description</th></tr>""" + html_table + """  </table></div>"""    f = open('tempfile', 'r')    contents = f.read() + html    f.close()    f = open('tempfile', 'w')    f.write(contents)    f.closetry:    arg = sys.argv[1]except:    arg=""if arg == "-b":    cmd = "cd dists && ./create_repo.sh && cd .."    os.system(cmd)f = open('tempfile', 'w')f.write("")f.close()list_packages("dapper", "contrib")f = open('tempfile', 'r')contents = f.read()f.closef = open('index.html', 'r')html_page = f.read()f.closehtml_re = re.compile(r"<!-- pkg list: begin -->(.*)<!-- pkg list: end -->", re.S)contents = """<!-- pkg list: begin -->""" + contents + """<!-- pkg list: end -->"""new_html = html_re.sub(contents, html_page)today = strftime("%a, %d %b %Y", gmtime())html_re = re.compile(r"<!-- Date: begin -->(.*)<!-- Date: end -->", re.S)new_date = """<!-- Date: begin --><p id="footer">Last modified: """ + today + """</p><!-- Date: end -->"""final_html = html_re.sub(new_date, new_html)f = open('index.html', 'w')f.write(final_html)f.close