3 """ Produces a report on NEW and BYHAND packages """
4 # Copyright (C) 2001, 2002, 2003, 2005, 2006 James Troup <james@nocrew.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ################################################################################
22 # <o-o> XP runs GCC, XFREE86, SSH etc etc,.,, I feel almost like linux....
23 # <o-o> I am very confident that I can replicate any Linux application on XP
24 # <willy> o-o: *boggle*
25 # <o-o> building from source.
26 # <o-o> Viiru: I already run GIMP under XP
27 # <willy> o-o: why do you capitalise the names of all pieces of software?
28 # <o-o> willy: because I want the EMPHASIZE them....
30 # <willy> o-o: it makes you look like ZIPPY the PINHEAD
31 # <o-o> willy: no idea what you are talking about.
32 # <willy> o-o: do some research
33 # <o-o> willy: for what reason?
35 ################################################################################
38 import glob, os, stat, sys, time
45 from daklib import utils
46 from daklib.dbconn import DBConn, DBSource, has_new_comment, PolicyQueue, \
47 get_uid_from_fingerprint
48 from daklib.policy import PolicyQueueUploadHandler
49 from daklib.textutils import fix_maintainer
50 from daklib.dak_exceptions import *
56 ################################################################################
58 def usage(exit_code=0):
59 print """Usage: dak queue-report
60 Prints a report of packages in queues (usually new and byhand).
62 -h, --help show this help and exit.
63 -8, --822 writes 822 formated output to the location set in dak.conf
64 -n, --new produce html-output
65 -s, --sort=key sort output according to key, see below.
66 -a, --age=key if using sort by age, how should time be treated?
67 If not given a default of hours will be used.
68 -r, --rrd=key Directory where rrd files to be updated are stored
69 -d, --directories=key A comma seperated list of queues to be scanned
71 Sorting Keys: ao=age, oldest first. an=age, newest first.
72 na=name, ascending nd=name, descending
73 nf=notes, first nl=notes, last
75 Age Keys: m=minutes, h=hours, d=days, w=weeks, o=months, y=years
80 ################################################################################
88 ################################################################################
112 return "%s %s%s" % (x, unit, plural(x))
114 ################################################################################
116 def sg_compare (a, b):
119 """Sort by have note, time of oldest upload."""
121 a_note_state = a["note_state"]
122 b_note_state = b["note_state"]
123 if a_note_state < b_note_state:
125 elif a_note_state > b_note_state:
128 # Sort by time of oldest upload
129 return cmp(a["oldest"], b["oldest"])
131 ############################################################
134 for sorting in direction:
135 (sortkey, way, time) = sorting
141 x=int(a[sortkey]/3600)
142 y=int(b[sortkey]/3600)
144 x=int(a[sortkey]/86400)
145 y=int(b[sortkey]/86400)
147 x=int(a[sortkey]/604800)
148 y=int(b[sortkey]/604800)
150 x=int(a[sortkey]/2419200)
151 y=int(b[sortkey]/2419200)
153 x=int(a[sortkey]/29030400)
154 y=int(b[sortkey]/29030400)
168 ############################################################
171 print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
172 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
173 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
175 <meta http-equiv="content-type" content="text/xhtml+xml; charset=utf-8" />
176 <link type="text/css" rel="stylesheet" href="style.css" />
177 <link rel="shortcut icon" href="http://www.debian.org/favicon.ico" />
179 Debian NEW and BYHAND Packages
181 <script type="text/javascript">
183 function togglePkg() {
184 var children = document.getElementsByTagName("*");
185 for (var i = 0; i < children.length; i++) {
186 if(!children[i].hasAttribute("class"))
188 c = children[i].getAttribute("class").split(" ");
189 for(var j = 0; j < c.length; j++) {
190 if(c[j] == "sourceNEW") {
191 if (children[i].style.display == '')
192 children[i].style.display = 'none';
193 else children[i].style.display = '';
203 <a href="http://www.debian.org/">
204 <img src="http://www.debian.org/logos/openlogo-nd-50.png"
205 alt="debian logo" /></a>
206 <a href="http://www.debian.org/">
207 <img src="http://www.debian.org/Pics/debian.png"
208 alt="Debian Project" /></a>
210 <div id="titleblock">
212 <img src="http://www.debian.org/Pics/red-upperleft.png"
213 id="red-upperleft" alt="corner image"/>
214 <img src="http://www.debian.org/Pics/red-lowerleft.png"
215 id="red-lowerleft" alt="corner image"/>
216 <img src="http://www.debian.org/Pics/red-upperright.png"
217 id="red-upperright" alt="corner image"/>
218 <img src="http://www.debian.org/Pics/red-lowerright.png"
219 id="red-lowerright" alt="corner image"/>
221 Debian NEW and BYHAND Packages
227 print "<p class=\"timestamp\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
228 print "<p class=\"timestamp\">There are <a href=\"/stat.html\">graphs about the queues</a> available.</p>"
232 <p>Hint: Age is the youngest upload of the package, if there is more than
234 You may want to look at <a href="http://ftp-master.debian.org/REJECT-FAQ.html">the REJECT-FAQ</a>
235 for possible reasons why one of the above packages may get rejected.</p>
237 <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10"
238 alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
239 <a href="http://jigsaw.w3.org/css-validator/">
240 <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss"
244 </div> </body> </html>
247 def table_header(type, source_count, total_count):
248 print "<h1 class='sourceNEW'>Summary for: %s</h1>" % (type)
249 print "<h1 class='sourceNEW' style='display: none'>Summary for: binary-%s only</h1>" % (type)
251 <p class="togglepkg" onclick="togglePkg()">Click to toggle all/binary-NEW packages</p>
253 <caption class="sourceNEW">
255 print "Package count in <strong>%s</strong>: <em>%s</em> | Total Package count: <em>%s</em>" % (type, source_count, total_count)
263 <th>Distribution</th>
272 def table_footer(type):
273 print "</tbody></table>"
276 def table_row(source, version, arch, last_mod, maint, distribution, closes, fingerprint, sponsor, changedby):
281 session = DBConn().session()
282 for dist in distribution:
283 if dist == "experimental":
286 query = '''SELECT source
288 WHERE source = :source
289 AND suite_name IN ('unstable', 'experimental')'''
290 if not session.execute(query, {'source': source}).rowcount:
291 trclass += " sourceNEW"
294 if row_number % 2 != 0:
295 print "<tr class=\"%s even\">" % (trclass)
297 print "<tr class=\"%s odd\">" % (trclass)
299 if "sourceNEW" in trclass:
300 print "<td class=\"package\">%s</td>" % (source)
302 print "<td class=\"package\"><a href=\"http://packages.qa.debian.org/%(source)s\">%(source)s</a></td>" % {'source': source}
303 print "<td class=\"version\">"
304 for vers in version.split():
305 print "<a href=\"new/%s_%s.html\">%s</a><br/>" % (source, utils.html_escape(vers), utils.html_escape(vers))
307 print "<td class=\"arch\">%s</td>" % (arch)
308 print "<td class=\"distribution\">"
309 for dist in distribution:
310 print "%s<br/>" % (dist)
312 print "<td class=\"age\">%s</td>" % (last_mod)
313 (name, mail) = maint.split(":", 1)
315 print "<td class=\"upload-data\">"
316 print "<span class=\"maintainer\">Maintainer: <a href=\"http://qa.debian.org/developer.php?login=%s\">%s</a></span><br/>" % (utils.html_escape(mail), utils.html_escape(name))
317 (name, mail) = changedby.split(":", 1)
318 print "<span class=\"changed-by\">Changed-By: <a href=\"http://qa.debian.org/developer.php?login=%s\">%s</a></span><br/>" % (utils.html_escape(mail), utils.html_escape(name))
322 (login, domain) = sponsor.split("@", 1)
323 print "<span class=\"sponsor\">Sponsor: <a href=\"http://qa.debian.org/developer.php?login=%s\">%s</a>@debian.org</span><br/>" % (utils.html_escape(login), utils.html_escape(login))
324 except Exception as e:
327 print "<span class=\"signature\">Fingerprint: %s</span>" % (fingerprint)
330 print "<td class=\"closes\">"
332 print "<a href=\"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s\">#%s</a><br/>" % (utils.html_escape(close), utils.html_escape(close))
336 ############################################################
338 def update_graph_database(rrd_dir, type, n_source, n_binary):
342 rrd_file = os.path.join(rrd_dir, type.lower()+'.rrd')
343 update = [rrd_file, "N:%s:%s" % (n_source, n_binary)]
346 rrdtool.update(*update)
347 except rrdtool.error:
348 create = [rrd_file]+"""
353 DS:ds0:GAUGE:7200:0:1000
354 DS:ds1:GAUGE:7200:0:1000
355 RRA:AVERAGE:0.5:1:599
356 RRA:AVERAGE:0.5:6:700
357 RRA:AVERAGE:0.5:24:775
358 RRA:AVERAGE:0.5:288:795
363 """.strip().split("\n")
365 rc = rrdtool.create(*create)
366 ru = rrdtool.update(*update)
367 except rrdtool.error as e:
368 print('warning: queue_report: rrdtool error, skipping %s.rrd: %s' % (type, e))
372 ############################################################
374 def process_queue(queue, log, rrd_dir):
376 type = queue.queue_name
377 session = DBConn().session()
379 # Divide the .changes into per-source groups
381 for upload in queue.uploads:
382 source = upload.changes.source
383 if source not in per_source:
384 per_source[source] = {}
385 per_source[source]["list"] = []
386 per_source[source]["processed"] = ""
387 handler = PolicyQueueUploadHandler(upload, session)
388 if handler.get_action():
389 per_source[source]["processed"] = " | PENDING %s" % handler.get_action()
390 per_source[source]["list"].append(upload)
391 # Determine oldest time and have note status for each source group
392 for source in per_source.keys():
393 source_list = per_source[source]["list"]
394 first = source_list[0]
395 oldest = time.mktime(first.changes.created.timetuple())
397 for d in per_source[source]["list"]:
398 mtime = time.mktime(d.changes.created.timetuple())
399 if Cnf.has_key("Queue-Report::Options::New"):
405 have_note += has_new_comment(d.changes.source, d.changes.version)
406 per_source[source]["oldest"] = oldest
408 per_source[source]["note_state"] = 0; # none
409 elif have_note < len(source_list):
410 per_source[source]["note_state"] = 1; # some
412 per_source[source]["note_state"] = 2; # all
413 per_source_items = per_source.items()
414 per_source_items.sort(sg_compare)
416 update_graph_database(rrd_dir, type, len(per_source_items), len(queue.uploads))
422 for i in per_source_items:
431 filename=i[1]["list"][0].changes.changesname
432 last_modified = time.time()-i[1]["oldest"]
433 source = i[1]["list"][0].changes.source
434 if len(source) > max_source_len:
435 max_source_len = len(source)
436 binary_list = i[1]["list"][0].binaries
437 binary = ', '.join([ b.package for b in binary_list ])
440 for j in i[1]["list"]:
442 changesbase = dbc.changesname
444 if Cnf.has_key("Queue-Report::Options::New") or Cnf.has_key("Queue-Report::Options::822"):
446 (maintainer["maintainer822"], maintainer["maintainer2047"],
447 maintainer["maintainername"], maintainer["maintaineremail"]) = \
448 fix_maintainer (dbc.maintainer)
449 except ParseMaintError as msg:
450 print "Problems while parsing maintainer address\n"
451 maintainer["maintainername"] = "Unknown"
452 maintainer["maintaineremail"] = "Unknown"
453 maint="%s:%s" % (maintainer["maintainername"], maintainer["maintaineremail"])
454 # ...likewise for the Changed-By: field if it exists.
456 (changeby["changedby822"], changeby["changedby2047"],
457 changeby["changedbyname"], changeby["changedbyemail"]) = \
458 fix_maintainer (dbc.changedby)
459 except ParseMaintError as msg:
460 (changeby["changedby822"], changeby["changedby2047"],
461 changeby["changedbyname"], changeby["changedbyemail"]) = \
463 changedby="%s:%s" % (changeby["changedbyname"], changeby["changedbyemail"])
465 distribution=dbc.distribution.split()
468 fingerprint = dbc.fingerprint
469 sponsor_name = get_uid_from_fingerprint(fingerprint).name
470 sponsor_email = get_uid_from_fingerprint(fingerprint).uid + "@debian.org"
471 if sponsor_name != maintainer["maintainername"] and sponsor_name != changeby["changedbyname"] and \
472 sponsor_email != maintainer["maintaineremail"] and sponsor_name != changeby["changedbyemail"]:
473 sponsor = sponsor_email
475 for arch in dbc.architecture.split():
477 versions.add(dbc.version)
478 arches_list = list(arches)
479 arches_list.sort(utils.arch_compare_sw)
480 arch_list = " ".join(arches_list)
481 version_list = " ".join(versions)
482 if len(version_list) > max_version_len:
483 max_version_len = len(version_list)
484 if len(arch_list) > max_arch_len:
485 max_arch_len = len(arch_list)
486 if i[1]["note_state"]:
490 entries.append([source, binary, version_list, arch_list, per_source[source]["processed"], note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, filename])
492 # direction entry consists of "Which field, which direction, time-consider" where
493 # time-consider says how we should treat last_modified. Thats all.
495 # Look for the options for sort and then do the sort.
497 if Cnf.has_key("Queue-Report::Options::Age"):
498 age = Cnf["Queue-Report::Options::Age"]
499 if Cnf.has_key("Queue-Report::Options::New"):
500 # If we produce html we always have oldest first.
501 direction.append([5,-1,"ao"])
503 if Cnf.has_key("Queue-Report::Options::Sort"):
504 for i in Cnf["Queue-Report::Options::Sort"].split(","):
507 direction.append([5,-1,age])
510 direction.append([5,1,age])
513 direction.append([0,1,0])
516 direction.append([0,-1,0])
519 direction.append([4,1,0])
522 direction.append([4,-1,0])
523 entries.sort(lambda x, y: sortfunc(x, y))
524 # Yes, in theory you can add several sort options at the commandline with. But my mind is to small
525 # at the moment to come up with a real good sorting function that considers all the sidesteps you
526 # have with it. (If you combine options it will simply take the last one at the moment).
527 # Will be enhanced in the future.
529 if Cnf.has_key("Queue-Report::Options::822"):
530 # print stuff out in 822 format
531 for entry in entries:
532 (source, binary, version_list, arch_list, processed, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, changes_file) = entry
534 # We'll always have Source, Version, Arch, Mantainer, and Dist
535 # For the rest, check to see if we have them, then print them out
536 log.write("Source: " + source + "\n")
537 log.write("Binary: " + binary + "\n")
538 log.write("Version: " + version_list + "\n")
539 log.write("Architectures: ")
540 log.write( (", ".join(arch_list.split(" "))) + "\n")
541 log.write("Age: " + time_pp(last_modified) + "\n")
542 log.write("Last-Modified: " + str(int(time.time()) - int(last_modified)) + "\n")
543 log.write("Queue: " + type + "\n")
545 (name, mail) = maint.split(":", 1)
546 log.write("Maintainer: " + name + " <"+mail+">" + "\n")
548 (name, mail) = changedby.split(":", 1)
549 log.write("Changed-By: " + name + " <"+mail+">" + "\n")
551 log.write("Sponsored-By: " + "@".join(sponsor.split("@")[:2]) + "\n")
552 log.write("Distribution:")
553 for dist in distribution:
554 log.write(" " + dist)
556 log.write("Fingerprint: " + fingerprint + "\n")
560 bug_string += "#"+bugs+", "
561 log.write("Closes: " + bug_string[:-2] + "\n")
562 log.write("Changes-File: " + os.path.basename(changes_file) + "\n")
565 total_count = len(queue.uploads)
566 source_count = len(per_source_items)
568 if Cnf.has_key("Queue-Report::Options::New"):
569 direction.append([5,1,"ao"])
570 entries.sort(lambda x, y: sortfunc(x, y))
571 # Output for a html file. First table header. then table_footer.
572 # Any line between them is then a <tr> printed from subroutine table_row.
574 table_header(type.upper(), source_count, total_count)
575 for entry in entries:
576 (source, binary, version_list, arch_list, processed, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, undef) = entry
577 table_row(source, version_list, arch_list, time_pp(last_modified), maint, distribution, closes, fingerprint, sponsor, changedby)
578 table_footer(type.upper())
579 elif not Cnf.has_key("Queue-Report::Options::822"):
580 # The "normal" output without any formatting.
581 format="%%-%ds | %%-%ds | %%-%ds%%s | %%s old%%s\n" % (max_source_len, max_version_len, max_arch_len)
584 for entry in entries:
585 (source, binary, version_list, arch_list, processed, note, last_modified, undef, undef, undef, undef, undef, undef, undef) = entry
586 msg += format % (source, version_list, arch_list, note, time_pp(last_modified), processed)
593 print "%s %s source package%s / %s %s package%s in total." % (source_count, type, plural(source_count), total_count, type, plural(total_count))
596 ################################################################################
601 Cnf = utils.get_conf()
602 Arguments = [('h',"help","Queue-Report::Options::Help"),
603 ('n',"new","Queue-Report::Options::New"),
604 ('8','822',"Queue-Report::Options::822"),
605 ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
606 ('a',"age","Queue-Report::Options::Age", "HasArg"),
607 ('r',"rrd","Queue-Report::Options::Rrd", "HasArg"),
608 ('d',"directories","Queue-Report::Options::Directories", "HasArg")]
610 if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
611 Cnf["Queue-Report::Options::%s" % (i)] = ""
613 apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
615 Options = Cnf.subtree("Queue-Report::Options")
619 if Cnf.has_key("Queue-Report::Options::New"):
624 if Cnf.has_key("Queue-Report::Options::Directories"):
625 for i in Cnf["Queue-Report::Options::Directories"].split(","):
626 queue_names.append(i)
627 elif Cnf.has_key("Queue-Report::Directories"):
628 queue_names = Cnf.value_list("Queue-Report::Directories")
630 queue_names = [ "byhand", "new" ]
632 if Cnf.has_key("Queue-Report::Options::Rrd"):
633 rrd_dir = Cnf["Queue-Report::Options::Rrd"]
634 elif Cnf.has_key("Dir::Rrd"):
635 rrd_dir = Cnf["Dir::Rrd"]
640 if Cnf.has_key("Queue-Report::Options::822"):
641 # Open the report file
642 f = open(Cnf["Queue-Report::ReportLocations::822Location"], "w")
644 session = DBConn().session()
646 for queue_name in queue_names:
647 queue = session.query(PolicyQueue).filter_by(queue_name=queue_name).first()
648 if queue is not None:
649 process_queue(queue, f, rrd_dir)
651 utils.warn("Cannot find queue %s" % queue_name)
653 if Cnf.has_key("Queue-Report::Options::822"):
656 if Cnf.has_key("Queue-Report::Options::New"):
659 ################################################################################
661 if __name__ == '__main__':