| 7 |
# This file is distributed under the terms of the General Public License |
# This file is distributed under the terms of the General Public License |
| 8 |
# version 2 or (at your option) any later version. |
# version 2 or (at your option) any later version. |
| 9 |
|
|
| 10 |
import os.path, rfc822, sys, string, re, email, common |
import os.path, rfc822, sys, string, re, email, common, cPickle |
| 11 |
from xml.dom import implementation, ext |
from xml.dom import implementation, ext |
| 12 |
|
|
| 13 |
from config import dir, odir, root |
from config import dir, odir, root |
| 14 |
|
|
|
def striphtml(input): |
|
|
cleared = input.strip() |
|
|
while cleared.find("<") != -1 and cleared.find(">") != -1: |
|
|
cleared = cleared[:cleared.find("<")] + cleared[cleared.find(">")+1:] |
|
|
return cleared |
|
|
|
|
|
def read_msg(file): |
|
|
f = open(file, "r") |
|
|
parser = email.Parser.Parser() |
|
|
msg = parser.parse(f) |
|
|
f.close() |
|
|
return msg |
|
|
|
|
|
def add_resume_for_msg(file, elt, doc, kind): |
|
|
global pkg, i |
|
|
if os.path.isfile(file): |
|
|
msg = read_msg(file) |
|
|
info = common.extract_info(msg) |
|
|
sub_elt = doc.createElement("item") |
|
|
sub_elt.appendChild(doc.createTextNode(info["subject"])) |
|
|
if info.has_key("url"): |
|
|
sub_elt.setAttribute("url", info["url"]) |
|
|
else: |
|
|
sub_elt.setAttribute("url", "%s/%s/%s.html" % (pkg, kind, i+1)) |
|
|
if info.has_key("date"): |
|
|
sub_elt.setAttribute("date", info["date"]) |
|
|
elt.appendChild(sub_elt) |
|
|
|
|
| 15 |
# Create the source -> binaries correspondance |
# Create the source -> binaries correspondance |
| 16 |
sources = {} |
sources = {} |
| 17 |
f = open(dir + "/sources", "r") |
f = open(dir + "/sources", "r") |
| 47 |
pts[binary] = stats |
pts[binary] = stats |
| 48 |
f.close() |
f.close() |
| 49 |
|
|
| 50 |
|
# Read the current signature of other.xml files |
| 51 |
|
sigs = {} |
| 52 |
|
if os.path.exists(odir + "/other.sigs"): |
| 53 |
|
f = open(odir + "/other.sigs", "r") |
| 54 |
|
sigs = cPickle.load(f) |
| 55 |
|
f.close() |
| 56 |
|
|
| 57 |
# Create the XML documents |
# Create the XML documents |
| 58 |
while 1: |
while 1: |
| 59 |
line = sys.stdin.readline() |
line = sys.stdin.readline() |
| 75 |
# Get BTS stats |
# Get BTS stats |
| 76 |
elt = doc.createElement("bugs") |
elt = doc.createElement("bugs") |
| 77 |
(s_rc, s_normal, s_wishlist, s_fixed) = (0,0,0,0) |
(s_rc, s_normal, s_wishlist, s_fixed) = (0,0,0,0) |
| 78 |
for binary in sources.get(pkg, []): |
binlist = sources.get(pkg, []) |
| 79 |
|
binlist.sort() |
| 80 |
|
subsig = "" |
| 81 |
|
for binary in binlist: |
| 82 |
sub_elt = doc.createElement("item") |
sub_elt = doc.createElement("item") |
| 83 |
sub_elt.setAttribute("name", binary) |
sub_elt.setAttribute("name", binary) |
| 84 |
(rc, normal, wishlist, fixed) = bugs.get(binary, ["0","0","0","0"]) |
(rc, normal, wishlist, fixed) = bugs.get(binary, ["0","0","0","0"]) |
| 93 |
all = rc + normal + wishlist + fixed |
all = rc + normal + wishlist + fixed |
| 94 |
sub_elt.setAttribute("all", "%d" % all) |
sub_elt.setAttribute("all", "%d" % all) |
| 95 |
elt.appendChild(sub_elt) |
elt.appendChild(sub_elt) |
| 96 |
|
if len(subsig): |
| 97 |
|
subsig = "%s|%d" % (subsig, all) |
| 98 |
|
else: |
| 99 |
|
subsig = "%d" % all |
| 100 |
s_rc += rc |
s_rc += rc |
| 101 |
s_normal += normal |
s_normal += normal |
| 102 |
s_wishlist += wishlist |
s_wishlist += wishlist |
| 108 |
elt.setAttribute("fixed", "%d" % s_fixed) |
elt.setAttribute("fixed", "%d" % s_fixed) |
| 109 |
elt.setAttribute("all", "%d" % (s_fixed + s_wishlist + s_normal + s_rc)) |
elt.setAttribute("all", "%d" % (s_fixed + s_wishlist + s_normal + s_rc)) |
| 110 |
root_elt.appendChild(elt) |
root_elt.appendChild(elt) |
|
|
|
|
# Get news information : static/news/auto |
|
|
elt = doc.createElement("static") |
|
|
for i in range(5): |
|
|
file = "%s/base/%s/%s/static/%d.txt" % (root, hash, pkg, i+1) |
|
|
add_resume_for_msg(file, elt, doc, "static") |
|
|
root_elt.appendChild(elt) |
|
|
elt = doc.createElement("news") |
|
|
for i in range(20): |
|
|
file = "%s/base/%s/%s/news/%d.txt" % (root, hash, pkg, i+1) |
|
|
add_resume_for_msg(file, elt, doc, "news") |
|
|
root_elt.appendChild(elt) |
|
|
elt = doc.createElement("auto") |
|
|
for i in range(10): |
|
|
file = "%s/base/%s/%s/auto/%d.txt" % (root, hash, pkg, i+1) |
|
|
add_resume_for_msg(file, elt, doc, "auto") |
|
|
root_elt.appendChild(elt) |
|
| 111 |
|
|
| 112 |
|
# TODO: try to do that signature checking before the creation of XML DOM |
| 113 |
|
# Build the sig and check if anything changed |
| 114 |
|
sig = "%s %d/%d/%d/%d %s" % (pts.get(pkg, "0"), s_rc, s_normal, s_wishlist, s_fixed, subsig) |
| 115 |
|
if sigs.has_key(pkg) and sig == sigs[pkg]: |
| 116 |
|
continue |
| 117 |
|
sigs[pkg] = sig |
| 118 |
|
|
| 119 |
# Output the data to the XML file |
# Output the data to the XML file |
| 120 |
f = open("%s/%s/%s/other.xml" % (odir, hash, pkg), "w") |
f = open("%s/%s/%s/other.xml" % (odir, hash, pkg), "w") |
| 121 |
ext.PrettyPrint(doc, f, "iso-8859-1") |
ext.PrettyPrint(doc, f, "iso-8859-1") |
| 122 |
f.close() |
f.close() |
| 123 |
|
|
| 124 |
|
# Store the signatures |
| 125 |
|
f = open(odir + "/other.sigs", "w") |
| 126 |
|
cPickle.dump(sigs, f, 0) |
| 127 |
|
f.close() |
| 128 |
|
|