| 1 |
#!/usr/bin/python
|
| 2 |
# -*- coding: utf8 -*-
|
| 3 |
|
| 4 |
# Make sure tabs expand to 8 spaces in vim
|
| 5 |
# vim: expandtab
|
| 6 |
|
| 7 |
# Copyright 2002 Raphaƫl Hertzog
|
| 8 |
# Copyright 2006 Jeroen van Wolffelaar
|
| 9 |
# This file is distributed under the terms of the General Public License
|
| 10 |
# version 2 or (at your option) any later version.
|
| 11 |
|
| 12 |
import os, rfc822, sys, string, re, email, common
|
| 13 |
from xml.dom import implementation, ext
|
| 14 |
|
| 15 |
from config import dir, odir, root
|
| 16 |
|
| 17 |
os.environ["PATH"] = "/bin:/sbin:/usr/bin:/usr/sbin"
|
| 18 |
|
| 19 |
def read_msg(file):
|
| 20 |
f = open(file, "r")
|
| 21 |
msg = email.message_from_file(f)
|
| 22 |
f.close()
|
| 23 |
return msg
|
| 24 |
|
| 25 |
def create_html_file(pkg, source, htmlfile):
|
| 26 |
# Fixme: old code had some mechanism to clean attachments, apparantly
|
| 27 |
# produced by mhonarc
|
| 28 |
dir = os.path.dirname(htmlfile)
|
| 29 |
if not os.path.exists(dir): os.makedirs(dir)
|
| 30 |
|
| 31 |
(stdin, stdout, stderr) = os.popen3("""cd %s; \
|
| 32 |
mhonarc -rcfile /dev/stdin \
|
| 33 |
-rcfile %s/etc/mhonarc.rc \
|
| 34 |
-single %s 2> /dev/null""" % (dir, root, source))
|
| 35 |
stdin.write("""
|
| 36 |
<MSGHEAD>
|
| 37 |
<h3><a href="../../%s.html">Back to %s PTS page</a></h3>
|
| 38 |
</MSGHEAD>
|
| 39 |
""" % (pkg, pkg))
|
| 40 |
stdin.close()
|
| 41 |
html = open(htmlfile+".new", "w")
|
| 42 |
html.writelines(stdout.readlines())
|
| 43 |
for f in html, stdout, stderr: f.close()
|
| 44 |
os.chmod(htmlfile+".new", 0664)
|
| 45 |
os.rename(htmlfile+".new", htmlfile)
|
| 46 |
|
| 47 |
def add_resume_for_msg(pkg, file, elt, doc, kind):
|
| 48 |
if not os.path.isfile(file):
|
| 49 |
pass
|
| 50 |
|
| 51 |
msg = read_msg(file)
|
| 52 |
info = common.extract_info(msg)
|
| 53 |
sub_elt = doc.createElement("item")
|
| 54 |
sub_elt.appendChild(doc.createTextNode(info["subject"]))
|
| 55 |
if info.has_key("url"):
|
| 56 |
sub_elt.setAttribute("url", info["url"])
|
| 57 |
else:
|
| 58 |
htmlfile = pkg+"/"+kind+"/"+info["timestamp"]+".html"
|
| 59 |
hash = pkg[0]
|
| 60 |
if pkg[0:3] == "lib":
|
| 61 |
hash = pkg[0:4]
|
| 62 |
htmlpath = "%s/web/%s/%s" % (root, hash, htmlfile)
|
| 63 |
if not os.path.exists(htmlpath):
|
| 64 |
create_html_file(pkg, file, htmlpath)
|
| 65 |
sub_elt.setAttribute("url", htmlfile)
|
| 66 |
if info.has_key("date"):
|
| 67 |
sub_elt.setAttribute("date", info["date"])
|
| 68 |
if info.has_key("from_name"):
|
| 69 |
sub_elt.setAttribute("from", info["from_name"])
|
| 70 |
elt.appendChild(sub_elt)
|
| 71 |
|
| 72 |
# Create the XML documents
|
| 73 |
while 1:
|
| 74 |
line = sys.stdin.readline()
|
| 75 |
if not line: break #eof
|
| 76 |
pkg = line.strip()
|
| 77 |
|
| 78 |
doc = implementation.createDocument(None, "news", None)
|
| 79 |
root_elt = doc.documentElement
|
| 80 |
|
| 81 |
hash = pkg[0]
|
| 82 |
if pkg[0:3] == "lib":
|
| 83 |
hash = pkg[0:4]
|
| 84 |
|
| 85 |
# Get news information : static/news/auto
|
| 86 |
for type, number in [("static", 5), ("news", 30)]:
|
| 87 |
elt = doc.createElement(type)
|
| 88 |
dir = "%s/base/%s/%s/%s" % (root, hash, pkg, type)
|
| 89 |
if not os.path.exists(dir): os.makedirs(dir)
|
| 90 |
entries = os.listdir(dir)
|
| 91 |
entries.sort()
|
| 92 |
for entry in entries[:number]:
|
| 93 |
add_resume_for_msg(pkg, dir+"/"+entry, elt, doc, type)
|
| 94 |
root_elt.appendChild(elt)
|
| 95 |
|
| 96 |
# Output the data to the XML file
|
| 97 |
f = open("%s/%s/%s/news.xml" % (odir, hash, pkg), "w")
|
| 98 |
ext.PrettyPrint(doc, f, 'utf8')
|
| 99 |
f.close()
|
| 100 |
|