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

Contents of /udd/web/bugs.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1820 - (show annotations) (download)
Tue Oct 12 09:01:35 2010 UTC (2 years, 7 months ago) by lucas
File size: 12207 byte(s)
some new filters, better handling of SQL errors, correct link to source code
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 ['notmain', 'packages not in main', 'id not in (select id from bugs_packages, sources where bugs_packages.source = sources.source and component=\'main\')'],
25 ['notsqueeze', 'packages not in squeeze', 'id not in (select id from bugs_packages, sources where bugs_packages.source = sources.source and release=\'squeeze\')'],
26 ['merged', 'merged bugs', 'id in (select id from bugs_merged_with where id > merged_with)'],
27 ['done', 'marked as done', 'status = \'done\''],
28 ['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)"],
29 ['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)"],
30 ['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)"],
31 ['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='maverick' and s1.version < s2.version)"],
32 ]
33
34 TYPES = [
35 ['rc', 'release-critical bugs', 'severity >= \'serious\'', true ],
36 ['ipv6', 'release goal: IPv6 support', 'id in (select id from bugs_tags where tag=\'ipv6\')', false ],
37 ['lfs', 'release goal: Large File Support', 'id in (select id from bugs_tags where tag=\'lfs\')', false ],
38 ['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],
39 ['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],
40 ['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'"],
41 ]
42
43 SORTS = [
44 ['id', 'bug#'],
45 ['source', 'source package'],
46 ['package', 'binary package'],
47 ['last_modified', 'last modified'],
48 ['severity', 'severity'],
49 ['popcon', 'popularity contest'],
50 ]
51
52 COLUMNS = [
53 ['cpopcon', 'popularity contest'],
54 ['chints', 'release team hints'],
55 ['cseverity', 'severity'],
56 ]
57
58 cgi = CGI::new
59 # releases
60 if RELEASE_RESTRICT.map { |r| r[0] }.include?(cgi.params['release'][0])
61 release = cgi.params['release'][0]
62 else
63 release = 'squeeze'
64 end
65 # columns
66 cols = {}
67 COLUMNS.map { |r| r[0] }.each do |r|
68 if cgi.params[r][0]
69 cols[r] = true
70 else
71 cols[r] = false
72 end
73 end
74 # sorts
75 if SORTS.map { |r| r[0] }.include?(cgi.params['sortby'][0])
76 sortby = cgi.params['sortby'][0]
77 else
78 sortby = 'id'
79 end
80 if ['asc', 'desc'].include?(cgi.params['sorto'][0])
81 sorto = cgi.params['sorto'][0]
82 else
83 sorto = 'asc'
84 end
85 # hack to enable popcon column if sortby = popcon
86 cols['cpopcon'] = true if sortby == 'popcon'
87 cols['cseverity'] = true if sortby == 'severity'
88 # filters
89 filters = {}
90 FILTERS.map { |r| r[0] }.each do |e|
91 if ['', 'only', 'ign'].include?(cgi.params[e][0])
92 filters[e] = cgi.params[e][0]
93 else
94 filters[e] = (e == 'merged' ? 'ign' : '')
95 end
96 end
97 # filter: newer than X days
98 if ['', 'only', 'ign'].include?(cgi.params['fnewer'][0])
99 fnewer = cgi.params['fnewer'][0]
100 else
101 fnewer = ''
102 end
103 if cgi.params['fnewerval'][0] =~ /^[0-9]+$/
104 fnewerval = cgi.params['fnewerval'][0].to_i
105 else
106 fnewerval = 7
107 end
108 # types
109 types = {}
110 TYPES.each do |t|
111 if cgi.params == {}
112 types[t[0]] = t[3]
113 else
114 if cgi.params[t[0]][0] == '1'
115 types[t[0]] = true
116 else
117 types[t[0]] = false
118 end
119 end
120 end
121
122 puts <<-EOF
123 <html>
124 <head>
125 <style type="text/css">
126
127 body {
128 font-family : "DejaVu Sans", "Bitstream Vera Sans", sans-serif;"
129 }
130
131 table.buglist td, table.buglist th {
132 border: 1px solid gray;
133 padding-left: 3px;
134 padding-right: 3px;
135 }
136 table.buglist tr:hover {
137 background-color: #ccc;
138 }
139 table {
140 border-collapse: collapse;
141 }
142
143 div#body {
144 border-top: 2px solid #d70751;
145 }
146
147 div.footer {
148 padding: 0.3em 0;
149 background-color: #fff;
150 text-align: center;
151 border-top: 2px solid #d70751;
152 margin: 0 0 0 0;
153 border-bottom: 0;
154 font-size: 85%;
155 }
156 </style>
157 <title>Debian Bugs Search @ UDD</title>
158 </head>
159 <body>
160 <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>
161 <div id="body">
162
163 <form action="bugs.cgi" method="get">
164 <p><b>Bugs affecting:</b>
165 EOF
166
167 RELEASE_RESTRICT.each do |r|
168 checked = (release == r[0] ? 'CHECKED=\'1\'':'')
169 puts "<input type='radio' name='release' value='#{r[0]}' #{checked}/>#{r[1]}&nbsp;&nbsp;"
170 end
171 puts <<-EOF
172 <br/>(also uses release tags and xxx-ignore information)</p>
173 <table class="invisible"><tr><td>
174 <table class="buglist">
175 <tr><th colspan='4'>FILTERS</th></tr>
176 <tr><th>not considered</th><th>only</th><th>ignore</th><th>type</th></tr>
177 EOF
178 FILTERS.each do |r|
179 puts <<-EOF
180 <tr>
181 <td style='text-align: center;'><input type='radio' name='#{r[0]}' value='' #{filters[r[0]]==''?'CHECKED=\'1\'':''}/></td>
182 <td style='text-align: center;'><input type='radio' name='#{r[0]}' value='only' #{filters[r[0]]=='only'?'CHECKED=\'1\'':''}/></td>
183 <td style='text-align: center;'><input type='radio' name='#{r[0]}' value='ign' #{filters[r[0]]=='ign'?'CHECKED=\'1\'':''}/></td>
184 <td>#{r[1]}</td>
185 </tr>
186 EOF
187 end
188 # newer than
189 puts <<-EOF
190 <tr>
191 <td style='text-align: center;'><input type='radio' name='fnewer' value='' #{fnewer==''?'CHECKED=\'1\'':''}/></td>
192 <td style='text-align: center;'><input type='radio' name='fnewer' value='only' #{fnewer=='only'?'CHECKED=\'1\'':''}/></td>
193 <td style='text-align: center;'><input type='radio' name='fnewer' value='ign' #{fnewer=='ign'?'CHECKED=\'1\'':''}/></td>
194 <td>newer than <input type='text' size='3' name='fnewerval' value='#{fnewerval}'/> days</td>
195 </tr>
196 EOF
197 puts "</table></td><td style='padding-left: 20px'><table class='buglist'>"
198 puts "<tr><th colspan='2'>Bug types</th></tr>"
199 TYPES.each do |t|
200 checked = types[t[0]]?" checked='1'":""
201 puts "<tr><td><input type='checkbox' name='#{t[0]}' value='1'#{checked}/></td><td>#{t[1]}</td></tr>"
202 end
203 puts "</table></td></tr></table>"
204 puts "<p><b>Sort by:</b> "
205 SORTS.each do |r|
206 checked = (sortby == r[0] ? 'CHECKED=\'1\'':'')
207 puts "<input type='radio' name='sortby' value='#{r[0]}' #{checked}/>#{r[1]}&nbsp;&nbsp;"
208 end
209 puts "<b> -- </b>"
210 [['asc', 'increasing'],[ 'desc', 'decreasing']].each do |r|
211 checked = (sorto == r[0] ? 'CHECKED=\'1\'':'')
212 puts "<input type='radio' name='sorto' value='#{r[0]}' #{checked}/>#{r[1]}&nbsp;&nbsp;"
213 end
214 puts "<br/>\n<b>Additional columns:</b> "
215 COLUMNS.each do |r|
216 checked = cols[r[0]] ? 'checked':''
217 puts "<input type='checkbox' name='#{r[0]}' value='1' #{checked}/>#{r[1]}&nbsp;&nbsp;"
218 end
219 puts <<-EOF
220 <br/>\n<input type='submit' value='Search'/></p>
221 </form>
222 EOF
223 if cgi.params != {}
224
225 # Generate and execute query
226 tstart = Time::now
227 dbh = DBI::connect('DBI:Pg:dbname=udd;port=5441;host=localhost', 'guest')
228 if cols['cpopcon']
229 q = "select id, bugs.package, bugs.source, severity, title, last_modified, coalesce(popcon_src.insts, 0) as popcon\nfrom bugs left join popcon_src on (bugs.source = popcon_src.source) \n"
230 else
231 q = "select id, bugs.package, bugs.source, severity, title, last_modified from bugs \n"
232 end
233 q += "where #{RELEASE_RESTRICT.select { |r| r[0] == release }[0][2]} \n"
234 FILTERS.each do |f|
235 if filters[f[0]] == 'only'
236 q += "and #{f[2]} \n"
237 elsif filters[f[0]] == 'ign'
238 q += "and not (#{f[2]}) \n"
239 end
240 end
241 if fnewer == 'only'
242 q += "and (current_timestamp - interval '#{fnewerval} days' <= arrival) \n"
243 elsif fnewer == 'ign'
244 q += "and (current_timestamp - interval '#{fnewerval} days' > arrival) \n"
245 end
246 q2 = TYPES.select { |t| types[t[0]] }.map { |t| t[2] }.join("\n OR ")
247 if q2 != ""
248 q += "AND (#{q2})\n"
249 else
250 puts "<p><b>Must select at least one bug type!</b></p>"
251 q += "AND FALSE\n"
252 end
253 q += "order by #{sortby} #{sorto}"
254 begin
255 sth = dbh.prepare(q)
256 sth.execute
257 rows = sth.fetch_all
258 rescue DBI::ProgrammingError => e
259 puts "<p>The query generated an error, please report it to lucas@debian.org: #{e.message}</p>"
260 puts "<pre>#{q}</pre>"
261 exit(0)
262 end
263
264 if cols['chints']
265 sthh = dbh.prepare("select distinct source, type, argument, version, file, comment from relevant_hints order by type")
266 sthh.execute
267 rowsh = sthh.fetch_all
268 hints = {}
269 rowsh.each do |r|
270 hints[r['source']] ||= []
271 hints[r['source']] << r
272 end
273 end
274
275 puts "<p><b>#{rows.length} bugs found.</b></p>"
276 puts '<table class="buglist">'
277 puts '<tr><th>bug#</th><th>package</th><th>title</th>'
278 puts '<th>popcon</th>' if cols['cpopcon']
279 puts '<th>severity</th>' if cols['cseverity']
280 if cols['chints']
281 puts '<th>hints</th>'
282 end
283 puts '<th>last&nbsp;modified</th></tr>'
284
285 def genhints(source, hints)
286 return '' if hints.nil?
287 s = ''
288 hints.each do |h|
289 v = h['version'] ? h['version'] + ' ' : ''
290 t = h['type'] == 'age-days' ? "age/#{h['argument']}" : h['type']
291 s += "<a href=\"http://release.debian.org/britney/hints/#{h['file']}\" title=\"#{v}#{h['file']} #{h['comment']}\">#{t}</a> "
292 end
293 s
294 end
295
296 rows.each do |r|
297 puts "<tr><td style='text-align: center;'><a href=\"http://bugs.debian.org/#{r['id']}\">##{r['id']}</a></td>"
298 puts "<td style='text-align: center;'>"
299 srcs = r['source'].split(/,\s*/)
300 bins = r['package'].split(/,\s*/)
301 puts (0...bins.length).map { |i| "<a href=\"http://packages.qa.debian.org/#{srcs[i]}\">#{bins[i]}</a>" }.join(', ')
302 puts "</td>"
303 puts "<td>#{CGI::escapeHTML(r['title'])}</td>"
304 puts "<td>#{r['popcon']}</td>" if cols['cpopcon']
305 puts "<td>#{r['severity']}</td>" if cols['cseverity']
306 puts "<td>#{genhints(r['source'], hints[r['source']])}</td>" if cols['chints']
307 puts "<td style='text-align: center;'>#{r['last_modified'].to_date}</td></tr>"
308 end
309
310 puts "</table>"
311 sth2 = dbh.prepare("select max(start_time) from timestamps where source = 'bugs' and command = 'run'")
312 sth2.execute ; r2 = sth2.fetch_all
313 puts "<p><b>Generated in #{Time::now - tstart} seconds. Last data update: #{r2[0][0]}"
314 puts " (%.1f hours ago)</b></p>" % ((Time::now - r2[0][0].to_time) / 3600)
315 puts "<pre>#{q}</pre>"
316 end # if cgi.params != {}
317 puts <<-EOF
318 </div>
319 <div class="footer">
320 <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>
321 </div>
322 </body>
323 </html>
324 EOF

Properties

Name Value
svn:executable *
svn:mergeinfo

  ViewVC Help
Powered by ViewVC 1.1.5