| 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 2005 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.path, rfc822, sys, string, re, email, common, cPickle
|
| 13 |
from xml.dom import implementation, ext
|
| 14 |
|
| 15 |
from config import dir, odir, root
|
| 16 |
|
| 17 |
# Create the source -> binaries correspondance
|
| 18 |
sources = {}
|
| 19 |
f = open(dir + "/sources.map", "r")
|
| 20 |
while 1:
|
| 21 |
line = f.readline();
|
| 22 |
if not line: break #eof
|
| 23 |
line = line.strip()
|
| 24 |
(binary, source) = line.split(None, 1)
|
| 25 |
if not sources.has_key(source):
|
| 26 |
sources[source] = []
|
| 27 |
sources[source].append(binary)
|
| 28 |
f.close()
|
| 29 |
|
| 30 |
# Read all the bugs stats
|
| 31 |
bugs = {}
|
| 32 |
f = open(dir + "/bugs.txt")
|
| 33 |
while 1:
|
| 34 |
line = f.readline()
|
| 35 |
if not line: break #eof
|
| 36 |
line = line.strip()
|
| 37 |
(binary, stats) = line.split(None, 1)
|
| 38 |
bugs[binary] = stats.split()
|
| 39 |
f.close()
|
| 40 |
|
| 41 |
# Read all the PTS stats
|
| 42 |
pts = {}
|
| 43 |
f = open(dir + "/count.txt")
|
| 44 |
while 1:
|
| 45 |
line = f.readline()
|
| 46 |
if not line: break #eof
|
| 47 |
line = line.strip()
|
| 48 |
(binary, stats) = line.split(None, 1)
|
| 49 |
pts[binary] = stats
|
| 50 |
f.close()
|
| 51 |
|
| 52 |
# Read the lisf of packages with debcheck problems
|
| 53 |
debcheck = {}
|
| 54 |
for dist in ("stable", "testing", "unstable"):
|
| 55 |
debcheck[dist] = {}
|
| 56 |
f = open(dir + "/debcheck-" + dist)
|
| 57 |
while 1:
|
| 58 |
line = f.readline()
|
| 59 |
if not line: break #eof
|
| 60 |
debcheck[dist][line.strip()] = 1
|
| 61 |
f.close()
|
| 62 |
|
| 63 |
# Read the list of packages with override disparities
|
| 64 |
override = {}
|
| 65 |
for dist in ("unstable", "experimental"):
|
| 66 |
override[dist] = {}
|
| 67 |
f = open(dir + "/override-disparities." + dist)
|
| 68 |
for line in f:
|
| 69 |
if line[0] != '-':
|
| 70 |
source = line.strip()[:-1]
|
| 71 |
override[dist][source] = []
|
| 72 |
else:
|
| 73 |
override[dist][source].append(line.strip()[2:])
|
| 74 |
f.close()
|
| 75 |
|
| 76 |
# Read the list of source packages with debconf templates
|
| 77 |
debconf = {}
|
| 78 |
# DISABLED until ddtp.debian.org is setup again
|
| 79 |
#f = open(dir + "/debconf-list")
|
| 80 |
#while 1:
|
| 81 |
# line = f.readline()
|
| 82 |
# if not line: break #eof
|
| 83 |
# line = line.strip()
|
| 84 |
# debconf[line] = 1;
|
| 85 |
#f.close()
|
| 86 |
|
| 87 |
# Read the current signature of other.xml files
|
| 88 |
sigs = {}
|
| 89 |
if os.path.exists(odir + "/other.sigs"):
|
| 90 |
f = open(odir + "/other.sigs", "r")
|
| 91 |
sigs = cPickle.load(f)
|
| 92 |
f.close()
|
| 93 |
|
| 94 |
# Read the wnpp information. [PvR]
|
| 95 |
wnpp = {}
|
| 96 |
if os.path.exists(dir + "/wnpp_rm"):
|
| 97 |
f = open(dir + "/wnpp_rm")
|
| 98 |
while 1:
|
| 99 |
line = f.readline()
|
| 100 |
if not line: break # eof
|
| 101 |
(package, type, number) = line.split("|")[0].split()
|
| 102 |
wnpp[package[:-1]] = (type, number)
|
| 103 |
f.close()
|
| 104 |
|
| 105 |
# Read watch information [FG]
|
| 106 |
watch = {}
|
| 107 |
if os.path.exists(odir + "/watch_done"):
|
| 108 |
f = open(odir + "/watch_done")
|
| 109 |
watch = cPickle.load(f)
|
| 110 |
f.close()
|
| 111 |
|
| 112 |
# Read patches information [FG]
|
| 113 |
patches = {}
|
| 114 |
# this can be easily inserted into a new update_patches.py if it becomes too
|
| 115 |
# heavy to parse the file
|
| 116 |
if os.path.exists(dir + "/patches.ubuntu"):
|
| 117 |
f = open(dir + "/patches.ubuntu")
|
| 118 |
for line in f.readlines():
|
| 119 |
(package, rel_url) = line.split(' ', 2)
|
| 120 |
rel_url = rel_url.strip()
|
| 121 |
r = re.search("_(\S+).patch", line)
|
| 122 |
if not r:
|
| 123 |
continue
|
| 124 |
version = r.group(1)
|
| 125 |
patches[package] = {}
|
| 126 |
patches[package]['ubuntu'] = (version, "http://patches.ubuntu.com/" + rel_url)
|
| 127 |
|
| 128 |
# Create the XML documents
|
| 129 |
while 1:
|
| 130 |
line = sys.stdin.readline()
|
| 131 |
if not line: break #eof
|
| 132 |
pkg = line.strip()
|
| 133 |
|
| 134 |
doc = implementation.createDocument(None, "other", None)
|
| 135 |
root_elt = doc.documentElement
|
| 136 |
|
| 137 |
hash = pkg[0]
|
| 138 |
if pkg[0:3] == "lib":
|
| 139 |
hash = pkg[0:4]
|
| 140 |
|
| 141 |
# Add debcheck availability info
|
| 142 |
dc_sig = ""
|
| 143 |
elt = doc.createElement("debcheck")
|
| 144 |
for dist in ("stable", "testing", "unstable"):
|
| 145 |
if debcheck[dist].has_key(pkg):
|
| 146 |
elt.setAttribute(dist, "yes")
|
| 147 |
dc_sig += "y"
|
| 148 |
else:
|
| 149 |
elt.setAttribute(dist, "no")
|
| 150 |
dc_sig += "n"
|
| 151 |
root_elt.appendChild(elt)
|
| 152 |
|
| 153 |
# Add debconf templates availibilty info
|
| 154 |
if debconf.has_key(pkg):
|
| 155 |
root_elt.setAttribute("debconf", "yes")
|
| 156 |
dc_sig += "y"
|
| 157 |
else:
|
| 158 |
root_elt.setAttribute("debconf", "no")
|
| 159 |
dc_sig += "n"
|
| 160 |
|
| 161 |
# Get PTS stats
|
| 162 |
elt = doc.createElement("pts")
|
| 163 |
elt.setAttribute("count", pts.get(pkg, "0"))
|
| 164 |
root_elt.appendChild(elt)
|
| 165 |
|
| 166 |
# Get BTS stats
|
| 167 |
elt = doc.createElement("bugs")
|
| 168 |
(s_rc, s_normal, s_wishlist, s_fixed, s_patch) = (0,0,0,0,0)
|
| 169 |
binlist = sources.get(pkg, [])
|
| 170 |
binlist.sort()
|
| 171 |
subsig = ""
|
| 172 |
for binary in binlist:
|
| 173 |
sub_elt = doc.createElement("item")
|
| 174 |
sub_elt.setAttribute("name", binary)
|
| 175 |
(rc, normal, wishlist, fixed, patch) = bugs.get(binary, ["0","0","0","0","0"])
|
| 176 |
sub_elt.setAttribute("rc", rc)
|
| 177 |
sub_elt.setAttribute("normal", normal)
|
| 178 |
sub_elt.setAttribute("wishlist", wishlist)
|
| 179 |
sub_elt.setAttribute("fixed", fixed)
|
| 180 |
sub_elt.setAttribute("patch", patch)
|
| 181 |
rc = string.atoi(rc)
|
| 182 |
normal = string.atoi(normal)
|
| 183 |
wishlist = string.atoi(wishlist)
|
| 184 |
fixed = string.atoi(fixed)
|
| 185 |
patch = string.atoi(patch)
|
| 186 |
all = rc + normal + wishlist + fixed
|
| 187 |
sub_elt.setAttribute("all", "%d" % all)
|
| 188 |
elt.appendChild(sub_elt)
|
| 189 |
if len(subsig):
|
| 190 |
subsig = "%s|%d|%d" % (subsig, all, patch)
|
| 191 |
else:
|
| 192 |
subsig = "%d|%d" % (all, patch)
|
| 193 |
s_rc += rc
|
| 194 |
s_normal += normal
|
| 195 |
s_wishlist += wishlist
|
| 196 |
s_fixed += fixed
|
| 197 |
s_patch += patch
|
| 198 |
if (pkg not in binlist): # Source package needs to be counted too
|
| 199 |
(rc, normal, wishlist, fixed, patch) = bugs.get(pkg, ["0","0","0","0","0"])
|
| 200 |
s_rc += string.atoi(rc)
|
| 201 |
s_normal += string.atoi(normal)
|
| 202 |
s_wishlist += string.atoi(wishlist)
|
| 203 |
s_fixed += string.atoi(fixed)
|
| 204 |
s_patch += string.atoi(patch)
|
| 205 |
|
| 206 |
elt.setAttribute("rc", "%d" % s_rc)
|
| 207 |
elt.setAttribute("normal", "%d" % s_normal)
|
| 208 |
elt.setAttribute("wishlist", "%d" % s_wishlist)
|
| 209 |
elt.setAttribute("fixed", "%d" % s_fixed)
|
| 210 |
elt.setAttribute("patch", "%d" % s_patch)
|
| 211 |
elt.setAttribute("all", "%d" % (s_fixed + s_wishlist + s_normal + s_rc))
|
| 212 |
root_elt.appendChild(elt)
|
| 213 |
|
| 214 |
# Get WNPP information. [PvR]
|
| 215 |
if wnpp.has_key(pkg):
|
| 216 |
(type, number) = wnpp[pkg]
|
| 217 |
elt = doc.createElement("wnpp")
|
| 218 |
elt.setAttribute("type", type)
|
| 219 |
elt.setAttribute("bugnumber", number)
|
| 220 |
root_elt.appendChild(elt)
|
| 221 |
root_elt.setAttribute("wnpp", "yes")
|
| 222 |
wnpp_sig = "%s%s" % (type,number)
|
| 223 |
else:
|
| 224 |
root_elt.setAttribute("wnpp", "no")
|
| 225 |
wnpp_sig = "n"
|
| 226 |
|
| 227 |
# Get override info [JvW]
|
| 228 |
override_elt = None
|
| 229 |
override_sig = []
|
| 230 |
for dist in [ 'unstable', 'experimental' ]:
|
| 231 |
if override[dist].has_key(pkg):
|
| 232 |
if not override_elt: override_elt = doc.createElement("override")
|
| 233 |
disparities = override[dist][pkg]
|
| 234 |
override_sig.append(disparities)
|
| 235 |
elt_g = doc.createElement("group")
|
| 236 |
elt_g.setAttribute("suite", dist)
|
| 237 |
for disp in disparities:
|
| 238 |
elt = doc.createTextNode(disp)
|
| 239 |
elt_disp = doc.createElement("disparity")
|
| 240 |
elt_disp.appendChild(elt)
|
| 241 |
elt_g.appendChild(elt_disp)
|
| 242 |
override_elt.appendChild(elt_g)
|
| 243 |
|
| 244 |
if override_elt:
|
| 245 |
root_elt.appendChild(override_elt)
|
| 246 |
root_elt.setAttribute("override", "yes")
|
| 247 |
else:
|
| 248 |
root_elt.setAttribute("override", "no")
|
| 249 |
|
| 250 |
# Get watch information [FG]
|
| 251 |
if watch.has_key(pkg):
|
| 252 |
new = str(watch[pkg]['new'])
|
| 253 |
warn = watch[pkg]['warning']
|
| 254 |
url = watch[pkg]['url']
|
| 255 |
elt = doc.createElement("watch")
|
| 256 |
elt.setAttribute("new", unicode(new,'UTF8','replace'))
|
| 257 |
elt.setAttribute("warning", unicode(warn,'UTF8','replace'))
|
| 258 |
elt.setAttribute("url", unicode(url,'UTF8','replace'))
|
| 259 |
root_elt.appendChild(elt)
|
| 260 |
root_elt.setAttribute("watch", "yes")
|
| 261 |
watch_sig = new
|
| 262 |
if warn != '':
|
| 263 |
watch_sig = watch_sig + ("/W%d" % len(warn))
|
| 264 |
if url != '':
|
| 265 |
watch_sig = watch_sig + ("/U%d" % len(url))
|
| 266 |
else:
|
| 267 |
root_elt.setAttribute("watch", "no")
|
| 268 |
watch_sig = "n"
|
| 269 |
|
| 270 |
# Add patches informations [FG]
|
| 271 |
if patches.has_key(pkg):
|
| 272 |
elt = doc.createElement("patches")
|
| 273 |
patch_sig = ""
|
| 274 |
distros = patches[pkg].keys()
|
| 275 |
distros.sort()
|
| 276 |
for distro in distros:
|
| 277 |
child = doc.createElement("item")
|
| 278 |
(version, url) = patches[pkg][distro]
|
| 279 |
child.setAttribute("distro", unicode(distro, 'UTF8', 'replace'))
|
| 280 |
child.setAttribute("version", unicode(version, 'UTF8', 'replace'))
|
| 281 |
child.setAttribute("url", unicode(url, 'UTF8', 'replace'))
|
| 282 |
elt.appendChild(child)
|
| 283 |
patch_sig += "%s/%s " % (distro, version)
|
| 284 |
root_elt.appendChild(elt)
|
| 285 |
root_elt.setAttribute("patches", "yes")
|
| 286 |
else:
|
| 287 |
root_elt.setAttribute("patches", "no")
|
| 288 |
patch_sig = "n"
|
| 289 |
|
| 290 |
# TODO: try to do that signature checking before the creation of XML DOM
|
| 291 |
# Build the sig and check if anything changed
|
| 292 |
sig = (pts.get(pkg, "0"), dc_sig, wnpp_sig, override_sig, watch_sig, patch_sig, s_rc, s_normal, s_wishlist, s_fixed, subsig)
|
| 293 |
if sigs.has_key(pkg) and sig == sigs[pkg] and \
|
| 294 |
os.path.isfile("%s/%s/%s/other.xml" % (odir, hash, pkg)):
|
| 295 |
continue
|
| 296 |
sigs[pkg] = sig
|
| 297 |
|
| 298 |
# Output the data to the XML file
|
| 299 |
try:
|
| 300 |
f = open("%s/%s/%s/other.xml" % (odir, hash, pkg), "w")
|
| 301 |
ext.PrettyPrint(doc, f, "iso-8859-1")
|
| 302 |
f.close()
|
| 303 |
except:
|
| 304 |
sys.stderr.write("Output problem for " + pkg + "/other.xml\n");
|
| 305 |
|
| 306 |
# Store the signatures
|
| 307 |
f = open(odir + "/other.sigs", "w")
|
| 308 |
cPickle.dump(sigs, f, 0)
|
| 309 |
f.close()
|
| 310 |
|