/[collab-qa]/udd/web/bugs.cgi
ViewVC logotype

Contents of /udd/web/bugs.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1868 - (show annotations) (download)
Mon Dec 13 12:46:45 2010 UTC (2 years, 5 months ago) by lucas
File size: 17195 byte(s)
check for system load before processing
1 #!/usr/bin/ruby -w
2
3 require 'dbi'
4 require 'pp'
5 require 'cgi'
6
7 puts "Content-type: text/html\n\n"
8
9 RELEASE_RESTRICT = [
10 ['squeeze', 'squeeze', 'id in (select id from bugs_rt_affects_testing)'],
11 ['sid', 'sid', 'id in (select id from bugs_rt_affects_unstable)'],
12 ['squeeze_and_sid', 'squeeze and sid', 'id in (select id from bugs_rt_affects_testing) and id in (select id from bugs_rt_affects_unstable)'],
13 ['squeeze_or_sid', 'squeeze or sid', 'id in (select id from bugs_rt_affects_testing union select id from bugs_rt_affects_unstable)'],
14 ['squeeze_not_sid', 'squeeze, not sid', 'id in (select id from bugs_rt_affects_testing) and id not in (select id from bugs_rt_affects_unstable)'],
15 ['sid_not_squeeze', 'sid, not squeeze', 'id in (select id from bugs_rt_affects_unstable) and id not in (select id from bugs_rt_affects_testing)'],
16 ['lenny', 'lenny', 'id in (select id from bugs_rt_affects_stable)'],
17 ['any', 'any', 'id in (select id from bugs where status!=\'done\')'],
18 ]
19
20 FILTERS = [
21 ['patch', 'tagged patch', 'id in (select id from bugs_tags where tag=\'patch\')'],
22 ['pending', 'tagged pending', 'id in (select id from bugs_tags where tag=\'pending\')'],
23 ['security', 'tagged security', 'id in (select id from bugs_tags where tag=\'security\')'],
24 ['wontfix', 'tagged wontfix', 'id in (select id from bugs_tags where tag=\'wontfix\')'],
25 ['upstream', 'tagged upstream', 'id in (select id from bugs_tags where tag=\'upstream\')'],
26 ['unreproducible', 'tagged unreproducible', 'id in (select id from bugs_tags where tag=\'unreproducible\')'],
27 ['forwarded', 'forwarded upstream', 'forwarded != \'\''],
28 ['claimed', 'claimed bugs', "id in (select id from bugs_usertags where email='bugsquash@qa.debian.org')"],
29 ['deferred', 'fixed in deferred/delayed', "id in (select id from deferred_closes)"],
30 ['notmain', 'packages not in main', 'id not in (select id from bugs_packages, sources where bugs_packages.source = sources.source and component=\'main\')'],
31 ['notsqueeze', 'packages not in squeeze', 'id not in (select id from bugs_packages, sources where bugs_packages.source = sources.source and release=\'squeeze\')'],
32 ['base', 'packages in base system', 'bugs.source in (select source from sources where priority=\'required\' or priority=\'important\')'],
33 ['standard', 'packages in standard installation', 'bugs.source in (select source from sources where priority=\'standard\')'],
34 ['orphaned', 'orphaned packages', 'bugs.source in (select source from orphaned_packages where type in (\'ITA\', \'O\'))'],
35 ['merged', 'merged bugs', 'id in (select id from bugs_merged_with where id > merged_with)'],
36 ['done', 'marked as done', 'status = \'done\''],
37 ['outdatedsqueeze', 'outdated binaries in squeeze', "bugs.source in (select distinct p1.source from packages_summary p1, packages_summary p2 where p1.source = p2.source and p1.release='squeeze' and p2.release='squeeze' and p1.source_version != p2.source_version)"],
38 ['outdatedsid', 'outdated binaries in sid', "bugs.source in (select distinct p1.source from packages_summary p1, packages_summary p2 where p1.source = p2.source and p1.release='sid' and p2.release='sid' and p1.source_version != p2.source_version)"],
39 ['needmig', 'different versions in squeeze and sid', "bugs.source in (select s1.source from sources s1, sources s2 where s1.source = s2.source and s1.release = 'squeeze' and s2.release='sid' and s1.version != s2.version)"],
40 ['newerubuntu', 'newer in Ubuntu than in sid', "bugs.source in (select s1.source from sources_uniq s1, ubuntu_sources s2 where s1.source = s2.source and s1.release = 'sid' and s2.release='natty' and s1.version < s2.version)"],
41 ]
42
43 TYPES = [
44 ['rc', 'release-critical bugs', 'severity >= \'serious\'', true ],
45 ['ipv6', 'release goal: IPv6 support', 'id in (select id from bugs_tags where tag=\'ipv6\')', false ],
46 ['lfs', 'release goal: Large File Support', 'id in (select id from bugs_tags where tag=\'lfs\')', false ],
47 ['boot', 'release goal: boot performance (init.d dependencies)', 'id in (select id from bugs_usertags where email = \'initscripts-ng-devel@lists.alioth.debian.org\')', false],
48 ['oldgnome', 'release goal: remove obsolete GNOME libraries', 'id in (select id from bugs_usertags where email = \'pkg-gnome-maintainers@lists.alioth.debian.org\' and tag=\'oldlibs\')', false],
49 ['ruby', 'Ruby bugs', "bugs.source in (select source from sources where maintainer ~ 'ruby' or uploaders ~ 'ruby')\nOR bugs.package in (select source from packages where (package ~ 'ruby' or depends ~ 'ruby') and source != 'subversion')\nOR title ~ 'ruby'"],
50 ['l10n', 'Localisation bugs', 'id in (select id from bugs_tags where tag=\'l10n\')', false],
51 ['xsf', 'X Strike Force bugs', "bugs.source in (select source from sources where maintainer ~ 'debian-x@lists.debian.org')\n"],
52 ['allbugs', 'All bugs', 'true', false],
53 ]
54
55 SORTS = [
56 ['id', 'bug#'],
57 ['source', 'source package'],
58 ['package', 'binary package'],
59 ['last_modified', 'last modified'],
60 ['severity', 'severity'],
61 ['popcon', 'popularity contest'],
62 ]
63
64 COLUMNS = [
65 ['cpopcon', 'popularity contest'],
66 ['chints', 'release team hints'],
67 ['cseverity', 'severity'],
68 ['ctags', 'tags'],
69 ['cclaimed', 'claimed by'],
70 ['cdeferred', 'deferred/delayed'],
71 ['caffected', 'affected releases'],
72 ]
73
74 cgi = CGI::new
75 # releases
76 if RELEASE_RESTRICT.map { |r| r[0] }.include?(cgi.params['release'][0])
77 release = cgi.params['release'][0]
78 else
79 release = 'squeeze'
80 end
81 # columns
82 cols = {}
83 COLUMNS.map { |r| r[0] }.each do |r|
84 if cgi.params[r][0]
85 cols[r] = true
86 else
87 cols[r] = false
88 end
89 end
90 # sorts
91 if SORTS.map { |r| r[0] }.include?(cgi.params['sortby'][0])
92 sortby = cgi.params['sortby'][0]
93 else
94 sortby = 'id'
95 end
96 if ['asc', 'desc'].include?(cgi.params['sorto'][0])
97 sorto = cgi.params['sorto'][0]
98 else
99 sorto = 'asc'
100 end
101 # hack to enable popcon column if sortby = popcon
102 cols['cpopcon'] = true if sortby == 'popcon'
103 cols['cseverity'] = true if sortby == 'severity'
104 # filters
105 filters = {}
106 FILTERS.map { |r| r[0] }.each do |e|
107 if ['', 'only', 'ign'].include?(cgi.params[e][0])
108 filters[e] = cgi.params[e][0]
109 else
110 filters[e] = (e == 'merged' ? 'ign' : '')
111 end
112 end
113 # filter: newer than X days
114 if ['', 'only', 'ign'].include?(cgi.params['fnewer'][0])
115 fnewer = cgi.params['fnewer'][0]
116 else
117 fnewer = ''
118 end
119 if cgi.params['fnewerval'][0] =~ /^[0-9]+$/
120 fnewerval = cgi.params['fnewerval'][0].to_i
121 else
122 fnewerval = 7
123 end
124 # types
125 types = {}
126 TYPES.each do |t|
127 if cgi.params == {}
128 types[t[0]] = t[3]
129 else
130 if cgi.params[t[0]][0] == '1'
131 types[t[0]] = true
132 else
133 types[t[0]] = false
134 end
135 end
136 end
137
138 puts <<-EOF
139 <html>
140 <head>
141 <style type="text/css">
142
143 body {
144 font-family : "DejaVu Sans", "Bitstream Vera Sans", sans-serif;"
145 }
146
147 table.buglist td, table.buglist th {
148 border: 1px solid gray;
149 padding-left: 3px;
150 padding-right: 3px;
151 }
152 table.buglist tr:hover {
153 background-color: #ccc;
154 color: #000;
155 }
156 table {
157 border-collapse: collapse;
158 }
159
160 div#body {
161 border-top: 2px solid #d70751;
162 }
163
164 div.footer {
165 padding: 0.3em 0;
166 background-color: #fff;
167 color: #000;
168 text-align: center;
169 border-top: 2px solid #d70751;
170 margin: 0 0 0 0;
171 border-bottom: 0;
172 font-size: 85%;
173 }
174 </style>
175 <title>Debian Bugs Search @ UDD</title>
176 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
177 <script type="text/javascript">
178 function removeBlankFields(form) {
179 var inputs = form.getElementsByTagName("input");
180 var removeList = new Array();
181 for (var i=0; i<inputs.length; i++) {
182 if (inputs[i].value == "") {
183 removeList.push(inputs[i]);
184 }
185 }
186 for (x in removeList) {
187 removeList[x].parentNode.removeChild(removeList[x]);
188 }
189 }
190 </script>
191 </head>
192 <body>
193 <h1 style="margin-bottom : 5px"><img src="http://qa.debian.org/debian.png" alt="Debian logo" width="188" height="52" style="vertical-align : -13px; ">Bugs Search <span style="color :#c70036">@</span> UDD</h1>
194 <div id="body">
195
196 <form action="bugs.cgi" method="get" onsubmit="removeBlankFields(this);">
197 <p><b>Bugs affecting:</b>
198 EOF
199
200 RELEASE_RESTRICT.each do |r|
201 checked = (release == r[0] ? 'CHECKED=\'1\'':'')
202 puts "<input type='radio' name='release' value='#{r[0]}' #{checked}/>#{r[1]}&nbsp;&nbsp;"
203 end
204 puts <<-EOF
205 <br/>(This already uses release tags ('sid', 'squeeze') and xxx-ignore ('squeeze-ignore') to include/exclude bugs)</p>
206 <table class="invisible"><tr><td>
207 <table class="buglist">
208 <tr><th colspan='4'>FILTERS</th></tr>
209 <tr><th>not considered</th><th>only</th><th>ignore</th><th>type</th></tr>
210 EOF
211 FILTERS.each do |r|
212 puts <<-EOF
213 <tr>
214 <td style='text-align: center;'><input type='radio' name='#{r[0]}' value='' #{filters[r[0]]==''?'CHECKED=\'1\'':''}/></td>
215 <td style='text-align: center;'><input type='radio' name='#{r[0]}' value='only' #{filters[r[0]]=='only'?'CHECKED=\'1\'':''}/></td>
216 <td style='text-align: center;'><input type='radio' name='#{r[0]}' value='ign' #{filters[r[0]]=='ign'?'CHECKED=\'1\'':''}/></td>
217 <td>#{r[1]}</td>
218 </tr>
219 EOF
220 end
221 # newer than
222 puts <<-EOF
223 <tr>
224 <td style='text-align: center;'><input type='radio' name='fnewer' value='' #{fnewer==''?'CHECKED=\'1\'':''}/></td>
225 <td style='text-align: center;'><input type='radio' name='fnewer' value='only' #{fnewer=='only'?'CHECKED=\'1\'':''}/></td>
226 <td style='text-align: center;'><input type='radio' name='fnewer' value='ign' #{fnewer=='ign'?'CHECKED=\'1\'':''}/></td>
227 <td>newer than <input type='text' size='3' name='fnewerval' value='#{fnewerval}'/> days</td>
228 </tr>
229 EOF
230 puts "</table></td><td style='padding-left: 20px'><table class='buglist'>"
231 puts "<tr><th colspan='2'>Bug types</th></tr>"
232 TYPES.each do |t|
233 checked = types[t[0]]?" checked='1'":""
234 puts "<tr><td><input type='checkbox' name='#{t[0]}' value='1'#{checked}/></td><td>#{t[1]}</td></tr>"
235 end
236 puts "</table></td></tr></table>"
237 puts "<p><b>Sort by:</b> "
238 SORTS.each do |r|
239 checked = (sortby == r[0] ? 'CHECKED=\'1\'':'')
240 puts "<input type='radio' name='sortby' value='#{r[0]}' #{checked}/>#{r[1]}&nbsp;&nbsp;"
241 end
242 puts "<b> -- </b>"
243 [['asc', 'increasing'],[ 'desc', 'decreasing']].each do |r|
244 checked = (sorto == r[0] ? 'CHECKED=\'1\'':'')
245 puts "<input type='radio' name='sorto' value='#{r[0]}' #{checked}/>#{r[1]}&nbsp;&nbsp;"
246 end
247 puts "<br/>\n<b>Additional information:</b> "
248 COLUMNS.each do |r|
249 checked = cols[r[0]] ? 'checked':''
250 puts "<input type='checkbox' name='#{r[0]}' value='1' #{checked}/>#{r[1]}&nbsp;&nbsp;"
251 end
252 puts <<-EOF
253 <br/>\n<input type='submit' value='Search'/></p>
254 </form>
255 EOF
256 if cgi.params != {}
257
258 # Generate and execute query
259 tstart = Time::now
260 dbh = DBI::connect('DBI:Pg:dbname=udd;port=5441;host=localhost', 'guest')
261 if cols['cpopcon']
262 q = "select id, bugs.package, bugs.source, severity, title, last_modified, affects_stable, affects_testing, affects_unstable, affects_experimental, coalesce(popcon_src.insts, 0) as popcon\nfrom bugs left join popcon_src on (bugs.source = popcon_src.source) \n"
263 else
264 q = "select id, bugs.package, bugs.source, severity, title, last_modified, affects_stable, affects_testing, affects_unstable, affects_experimental from bugs \n"
265 end
266 q += "where #{RELEASE_RESTRICT.select { |r| r[0] == release }[0][2]} \n"
267 FILTERS.each do |f|
268 if filters[f[0]] == 'only'
269 q += "and #{f[2]} \n"
270 elsif filters[f[0]] == 'ign'
271 q += "and not (#{f[2]}) \n"
272 end
273 end
274 if fnewer == 'only'
275 q += "and (current_timestamp - interval '#{fnewerval} days' <= arrival) \n"
276 elsif fnewer == 'ign'
277 q += "and (current_timestamp - interval '#{fnewerval} days' > arrival) \n"
278 end
279 q2 = TYPES.select { |t| types[t[0]] }.map { |t| t[2] }.join("\n OR ")
280 if q2 != ""
281 q += "AND (#{q2})\n"
282 else
283 puts "<p><b>Must select at least one bug type!</b></p>"
284 q += "AND FALSE\n"
285 end
286 q += "order by #{sortby} #{sorto}"
287
288 load = IO::read('/proc/loadavg').split[0].to_f
289 if load > 7
290 puts "<p><b>Current system load (#{load}) is too high. Please retry later!</b></p>"
291 exit(0)
292 end
293
294 begin
295 sth = dbh.prepare(q)
296 sth.execute
297 rows = sth.fetch_all
298 rescue DBI::ProgrammingError => e
299 puts "<p>The query generated an error, please report it to lucas@debian.org: #{e.message}</p>"
300 puts "<pre>#{q}</pre>"
301 exit(0)
302 end
303
304 if cols['chints']
305 sthh = dbh.prepare("select distinct source, type, argument, version, file, comment from relevant_hints order by type")
306 sthh.execute
307 rowsh = sthh.fetch_all
308 hints = {}
309 rowsh.each do |r|
310 hints[r['source']] ||= []
311 hints[r['source']] << r
312 end
313 end
314
315 if cols['ctags']
316 ids = rows.map { |r| r['id'] }.join(',')
317 stht = dbh.prepare("select id, tag from bugs_tags where id in (#{ids})")
318 stht.execute
319 rowst = stht.fetch_all
320 tags = {}
321 rowst.each do |r|
322 tags[r['id']] ||= []
323 tags[r['id']] << r['tag']
324 end
325 end
326
327 if cols['cclaimed']
328 ids = rows.map { |r| r['id'] }.join(',')
329 stht = dbh.prepare("select distinct id, tag from bugs_usertags where email='bugsquash@qa.debian.org' and id in (#{ids})")
330 stht.execute
331 rowst = stht.fetch_all
332 claimedbugs = {}
333 rowst.each do |r|
334 claimedbugs[r['id']] ||= []
335 claimedbugs[r['id']] << r['tag']
336 end
337 end
338
339 if cols['cdeferred']
340 ids = rows.map { |r| r['id'] }.join(',')
341 sthd = dbh.prepare("select id, deferred.source, deferred.version, extract (day from delay_remaining) as du from deferred, deferred_closes where deferred.source = deferred_closes.source and deferred.version = deferred_closes.version and deferred_closes.id in (#{ids})")
342 sthd.execute
343 rowsd = sthd.fetch_all
344 deferredbugs = {}
345 rowsd.each do |r|
346 d = r['du'].to_i
347 deferredbugs[r['id']] = "#{r['version']} (#{d}&nbsp;day#{d==1?'':'s'})"
348 end
349 end
350
351 puts "<p><b>#{rows.length} bugs found.</b></p>"
352 puts '<table class="buglist">'
353 puts '<tr><th>bug#</th><th>package</th><th>title</th>'
354 puts '<th>popcon</th>' if cols['cpopcon']
355 puts '<th>severity</th>' if cols['cseverity']
356 puts '<th>hints</th>' if cols['chints']
357 puts '<th>claimed by</th>' if cols['cclaimed']
358 puts '<th>deferred</th>' if cols['cdeferred']
359 puts '<th>last&nbsp;modified</th></tr>'
360
361 def genhints(source, hints)
362 return '' if hints.nil?
363 s = ''
364 hints.each do |h|
365 v = h['version'] ? h['version'] + ' ' : ''
366 t = h['type'] == 'age-days' ? "age/#{h['argument']}" : h['type']
367 s += "<a href=\"http://release.debian.org/britney/hints/#{h['file']}\" title=\"#{v}#{h['file']} #{h['comment']}\">#{t}</a> "
368 end
369 s
370 end
371
372 # copied from /org/bugs.debian.org/etc/config
373 $TagsSingleLetter = {
374 'patch' => '+',
375 'wontfix' => '☹',
376 'moreinfo' => 'M',
377 'unreproducible' => 'R',
378 'security' => 'S',
379 'pending' => 'P',
380 'fixed' => 'F',
381 'help' => 'H',
382 'fixed-upstream' => 'U',
383 'upstream' => 'u',
384 # Added tags
385 'confirmed' => 'C',
386 'etch-ignore' => 'etc-i',
387 'lenny-ignore' => 'len-i',
388 'sarge-ignore' => 'sar-i',
389 'squeeze-ignore' => 'squ-i',
390 'woody' => 'wod',
391 'sarge' => 'sar',
392 'etch' => 'etc',
393 'lenny' => 'len',
394 'squeeze' => 'squ',
395 'sid' => 'sid',
396 'experimental' => 'exp',
397 'l10n' => 'l10n',
398 'd-i' => 'd-i',
399 'ipv6' => 'ipv6',
400 'lfs' => 'lfs',
401 'fixed-in-experimental' => 'fie',
402 }
403
404 def gentags(tags)
405 return '' if tags.nil?
406 tags.sort!
407 texttags = tags.map do |tag|
408 puts "unknowntag: #{tag}" if $TagsSingleLetter[tag].nil?
409 "<abbr title='#{tag}'>#{$TagsSingleLetter[tag]}</abbr>"
410 end
411 return '&nbsp;[' + texttags.join('|') + ']'
412 end
413
414 def genaffected(r)
415 s = ""
416 s += "<abbr title='affects stable'>S</abbr>" if r['affects_stable']
417 s += "<abbr title='affects testing'>T</abbr>" if r['affects_testing']
418 s += "<abbr title='affects unstable'>U</abbr>" if r['affects_unstable']
419 s += "<abbr title='affects unstable'>E</abbr>" if r['affects_experimental']
420 return "" if s == ""
421 return "&nbsp;("+s+")"
422 end
423
424 rows.each do |r|
425 print "<tr><td style='text-align: left;'><a href=\"http://bugs.debian.org/#{r['id']}\">##{r['id']}</a>"
426 puts "#{gentags(tags[r['id']])}" if cols['ctags']
427 puts "#{genaffected(r)}" if cols['caffected']
428 puts "</td>"
429 puts "<td style='text-align: center;'>"
430 srcs = r['source'].split(/,\s*/)
431 bins = r['package'].split(/,\s*/)
432 puts (0...bins.length).map { |i| "<a href=\"http://packages.qa.debian.org/#{srcs[i]}\">#{bins[i]}</a>" }.join(', ')
433 puts "</td>"
434 puts "<td>#{CGI::escapeHTML(r['title'])}</td>"
435 puts "<td>#{r['popcon']}</td>" if cols['cpopcon']
436 puts "<td>#{r['severity']}</td>" if cols['cseverity']
437 puts "<td>#{genhints(r['source'], hints[r['source']])}</td>" if cols['chints']
438 puts "<td>#{claimedbugs[r['id']]}</td>" if cols['cclaimed']
439 puts "<td>#{deferredbugs[r['id']]}</td>" if cols['cdeferred']
440 puts "<td style='text-align: center;'>#{r['last_modified'].to_date}</td></tr>"
441 end
442
443 puts "</table>"
444 sth2 = dbh.prepare("select max(start_time) from timestamps where source = 'bugs' and command = 'run'")
445 sth2.execute ; r2 = sth2.fetch_all
446 puts "<p><b>Generated in #{Time::now - tstart} seconds. Last data update: #{r2[0][0]}"
447 puts " (%.1f hours ago)</b></p>" % ((Time::now - r2[0][0].to_time) / 3600)
448 puts "<pre>#{q}</pre>"
449 end # if cgi.params != {}
450 puts <<-EOF
451 </div>
452 <div class="footer">
453 <small>Suggestions / comments / patches to lucas@debian.org. <a href="http://svn.debian.org/wsvn/collab-qa/udd/web/bugs.cgi">source code</a>.</small>
454 </div>
455 </body>
456 </html>
457 EOF

Properties

Name Value
svn:executable *
svn:mergeinfo

  ViewVC Help
Powered by ViewVC 1.1.5