#!/usr/bin/python2.2 # Make sure tabs expand to 8 spaces in vim # vim: expandtab # Copyright 2002 Raphaël Hertzog # This file is distributed under the terms of the General Public License # version 2 or (at your option) any later version. import os.path, rfc822, sys, string, re, email, common, cPickle from xml.dom import implementation, ext from config import dir, odir, root # Create the source -> binaries correspondance sources = {} f = open(dir + "/sources", "r") while 1: line = f.readline(); if not line: break #eof line = line.strip() (binary, source) = line.split(None, 1) if not sources.has_key(source): sources[source] = [] sources[source].append(binary) f.close() # Read all the bugs stats bugs = {} f = open(dir + "/bugs.txt") while 1: line = f.readline() if not line: break #eof line = line.strip() (binary, stats) = line.split(None, 1) bugs[binary] = stats.split() f.close() # Read all the PTS stats pts = {} f = open(dir + "/count.txt") while 1: line = f.readline() if not line: break #eof line = line.strip() (binary, stats) = line.split(None, 1) pts[binary] = stats f.close() # Read the lisf of packages with debcheck problems debcheck = {} for dist in ("stable", "testing", "unstable"): debcheck[dist] = {} f = open(dir + "/debcheck-" + dist) while 1: line = f.readline() if not line: break #eof debcheck[dist][line.strip()] = 1 f.close() # Read the list of source packages with debconf templates debconf = {} f = open(dir + "/debconf-list") while 1: line = f.readline() if not line: break #eof line = line.strip() debconf[line] = 1; f.close() # Read the current signature of other.xml files sigs = {} if os.path.exists(odir + "/other.sigs"): f = open(odir + "/other.sigs", "r") sigs = cPickle.load(f) f.close() # Read the wnpp information. [PvR] wnpp = {} if os.path.exists(dir + "/wnpp.txt"): f = open(dir + "/wnpp.txt") while 1: line = f.readline() if not line: break # eof line = line.strip() try: (package, type, number, age) = line.split(None,3) wnpp[package] = (type, number) except ValueError: # erroneous entry in wnpp.txt, ignore it line = line # no-op f.close() # Read watch information [FG] watch = {} if os.path.exists(odir + "/watch_done"): f = open(odir + "/watch_done") watch = cPickle.load(f) f.close() # Create the XML documents while 1: line = sys.stdin.readline() if not line: break #eof pkg = line.strip() doc = implementation.createDocument(None, "other", None) root_elt = doc.documentElement hash = pkg[0] if pkg[0:3] == "lib": hash = pkg[0:4] # Add debcheck availability info dc_sig = "" elt = doc.createElement("debcheck") for dist in ("stable", "testing", "unstable"): if debcheck[dist].has_key(pkg): elt.setAttribute(dist, "yes") dc_sig += "y" else: elt.setAttribute(dist, "no") dc_sig += "n" root_elt.appendChild(elt) # Add debconf templates availibilty info if debconf.has_key(pkg): root_elt.setAttribute("debconf", "yes") dc_sig += "y" else: root_elt.setAttribute("debconf", "no") dc_sig += "n" # Get PTS stats elt = doc.createElement("pts") elt.setAttribute("count", pts.get(pkg, "0")) root_elt.appendChild(elt) # Get BTS stats elt = doc.createElement("bugs") (s_rc, s_normal, s_wishlist, s_fixed) = (0,0,0,0) binlist = sources.get(pkg, []) binlist.sort() subsig = "" for binary in binlist: sub_elt = doc.createElement("item") sub_elt.setAttribute("name", binary) (rc, normal, wishlist, fixed) = bugs.get(binary, ["0","0","0","0"]) sub_elt.setAttribute("rc", rc) sub_elt.setAttribute("normal", normal) sub_elt.setAttribute("wishlist", wishlist) sub_elt.setAttribute("fixed", fixed) rc = string.atoi(rc) normal = string.atoi(normal) wishlist = string.atoi(wishlist) fixed = string.atoi(fixed) all = rc + normal + wishlist + fixed sub_elt.setAttribute("all", "%d" % all) elt.appendChild(sub_elt) if len(subsig): subsig = "%s|%d" % (subsig, all) else: subsig = "%d" % all s_rc += rc s_normal += normal s_wishlist += wishlist s_fixed += fixed if (pkg not in binlist): # Source package needs to be counted too (rc, normal, wishlist, fixed) = bugs.get(pkg, ["0","0","0","0"]) s_rc += string.atoi(rc) s_normal += string.atoi(normal) s_wishlist += string.atoi(wishlist) s_fixed += string.atoi(fixed) elt.setAttribute("rc", "%d" % s_rc) elt.setAttribute("normal", "%d" % s_normal) elt.setAttribute("wishlist", "%d" % s_wishlist) elt.setAttribute("fixed", "%d" % s_fixed) elt.setAttribute("all", "%d" % (s_fixed + s_wishlist + s_normal + s_rc)) root_elt.appendChild(elt) # Get WNPP information. [PvR] if wnpp.has_key(pkg): (type, number) = wnpp[pkg] elt = doc.createElement("wnpp") elt.setAttribute("type", type) elt.setAttribute("bugnumber", number) root_elt.appendChild(elt) root_elt.setAttribute("wnpp", "yes") wnpp_sig = "%s%s" % (type,number) else: root_elt.setAttribute("wnpp", "no") wnpp_sig = "n" # Get watch information [FG] if watch.has_key(pkg): new = str(watch[pkg]['new']) warn = watch[pkg]['warning'] url = watch[pkg]['url'] elt = doc.createElement("watch") elt.setAttribute("new", new) elt.setAttribute("warning", warn) elt.setAttribute("url", url) root_elt.appendChild(elt) root_elt.setAttribute("watch", "yes") watch_sig = new else: root_elt.setAttribute("watch", "no") watch_sig = "n" # TODO: try to do that signature checking before the creation of XML DOM # Build the sig and check if anything changed sig = "%s %s %s %s %d/%d/%d/%d %s" % (pts.get(pkg, "0"), dc_sig, wnpp_sig, watch_sig, s_rc, s_normal, s_wishlist, s_fixed, subsig) if sigs.has_key(pkg) and sig == sigs[pkg]: continue sigs[pkg] = sig # Output the data to the XML file f = open("%s/%s/%s/other.xml" % (odir, hash, pkg), "w") ext.PrettyPrint(doc, f, "iso-8859-1") f.close() # Store the signatures f = open(odir + "/other.sigs", "w") cPickle.dump(sigs, f, 0) f.close()