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.textutils import fix_maintainer
49 from daklib.dak_exceptions import *
55 ################################################################################
57 def usage(exit_code=0):
58 print """Usage: dak queue-report
59 Prints a report of packages in queues (usually new and byhand).
61 -h, --help show this help and exit.
62 -8, --822 writes 822 formated output to the location set in dak.conf
63 -n, --new produce html-output
64 -s, --sort=key sort output according to key, see below.
65 -a, --age=key if using sort by age, how should time be treated?
66 If not given a default of hours will be used.
67 -r, --rrd=key Directory where rrd files to be updated are stored
68 -d, --directories=key A comma seperated list of queues to be scanned
70 Sorting Keys: ao=age, oldest first. an=age, newest first.
71 na=name, ascending nd=name, descending
72 nf=notes, first nl=notes, last
74 Age Keys: m=minutes, h=hours, d=days, w=weeks, o=months, y=years
79 ################################################################################
87 ################################################################################
111 return "%s %s%s" % (x, unit, plural(x))
113 ################################################################################
115 def sg_compare (a, b):
118 """Sort by have note, time of oldest upload."""
120 a_note_state = a["note_state"]
121 b_note_state = b["note_state"]
122 if a_note_state < b_note_state:
124 elif a_note_state > b_note_state:
127 # Sort by time of oldest upload
128 return cmp(a["oldest"], b["oldest"])
130 ############################################################
133 for sorting in direction:
134 (sortkey, way, time) = sorting
140 x=int(a[sortkey]/3600)
141 y=int(b[sortkey]/3600)
143 x=int(a[sortkey]/86400)
144 y=int(b[sortkey]/86400)
146 x=int(a[sortkey]/604800)
147 y=int(b[sortkey]/604800)
149 x=int(a[sortkey]/2419200)
150 y=int(b[sortkey]/2419200)
152 x=int(a[sortkey]/29030400)
153 y=int(b[sortkey]/29030400)
167 ############################################################
170 print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
171 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
172 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
174 <meta http-equiv="content-type" content="text/xhtml+xml; charset=utf-8" />
175 <link type="text/css" rel="stylesheet" href="style.css" />
176 <link rel="shortcut icon" href="http://www.debian.org/favicon.ico" />
178 Debian NEW and BYHAND Packages
180 <script type="text/javascript">
182 function togglePkg() {
183 var children = document.getElementsByTagName("*");
184 for (var i = 0; i < children.length; i++) {
185 if(!children[i].hasAttribute("class"))
187 c = children[i].getAttribute("class").split(" ");
188 for(var j = 0; j < c.length; j++) {
189 if(c[j] == "binNEW") {
190 if (children[i].style.display == '')
191 children[i].style.display = 'none';
192 else children[i].style.display = '';
202 <a href="http://www.debian.org/">
203 <img src="http://www.debian.org/logos/openlogo-nd-50.png"
204 alt="debian logo" /></a>
205 <a href="http://www.debian.org/">
206 <img src="http://www.debian.org/Pics/debian.png"
207 alt="Debian Project" /></a>
209 <div id="titleblock">
211 <img src="http://www.debian.org/Pics/red-upperleft.png"
212 id="red-upperleft" alt="corner image"/>
213 <img src="http://www.debian.org/Pics/red-lowerleft.png"
214 id="red-lowerleft" alt="corner image"/>
215 <img src="http://www.debian.org/Pics/red-upperright.png"
216 id="red-upperright" alt="corner image"/>
217 <img src="http://www.debian.org/Pics/red-lowerright.png"
218 id="red-lowerright" alt="corner image"/>
220 Debian NEW and BYHAND Packages
226 print "<p class=\"timestamp\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
227 print "<p class=\"timestamp\">There are <a href=\"/stat.html\">graphs about the queues</a> available.</p>"
231 <p>Hint: Age is the youngest upload of the package, if there is more than
233 You may want to look at <a href="http://ftp-master.debian.org/REJECT-FAQ.html">the REJECT-FAQ</a>
234 for possible reasons why one of the above packages may get rejected.</p>
236 <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10"
237 alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
238 <a href="http://jigsaw.w3.org/css-validator/">
239 <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss"
243 </div> </body> </html>
246 def table_header(type, source_count, total_count):
247 print "<h1 class='binNEW'>Summary for: %s</h1>" % (type)
248 print "<h1 class='binNEW' style='display: none'>Summary for: binary-%s only</h1>" % (type)
250 <p class="togglepkg" onclick="togglePkg()">Click to toggle all/binary-NEW packages</p>
252 <caption class="binNEW">
254 print "Package count in <strong>%s</strong>: <em>%s</em> | Total Package count: <em>%s</em>" % (type, source_count, total_count)
262 <th>Distribution</th>
271 def table_footer(type):
272 print "</tbody></table>"
275 def table_row(source, version, arch, last_mod, maint, distribution, closes, fingerprint, sponsor, changedby):
280 session = DBConn().session()
281 for dist in distribution:
282 if dist == "experimental":
285 if not len(session.query(DBSource).filter_by(source = source).all()):
289 if row_number % 2 != 0:
290 print "<tr class=\"%s even\">" % (trclass)
292 print "<tr class=\"%s odd\">" % (trclass)
294 if "binNEW" in trclass:
295 print "<td class=\"package\">%s</td>" % (source)
297 print "<td class=\"package\"><a href=\"http://packages.qa.debian.org/%(source)s\">%(source)s</a></td>" % {'source': source}
298 print "<td class=\"version\">"
299 for vers in version.split():
300 print "<a href=\"new/%s_%s.html\">%s</a><br/>" % (source, utils.html_escape(vers), utils.html_escape(vers))
302 print "<td class=\"arch\">%s</td>" % (arch)
303 print "<td class=\"distribution\">"
304 for dist in distribution:
305 print "%s<br/>" % (dist)
307 print "<td class=\"age\">%s</td>" % (last_mod)
308 (name, mail) = maint.split(":", 1)
310 print "<td class=\"upload-data\">"
311 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))
312 (name, mail) = changedby.split(":", 1)
313 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))
317 (login, domain) = sponsor.split("@", 1)
318 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))
319 except Exception as e:
322 print "<span class=\"signature\">Fingerprint: %s</span>" % (fingerprint)
325 print "<td class=\"closes\">"
327 print "<a href=\"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s\">#%s</a><br/>" % (utils.html_escape(close), utils.html_escape(close))
331 ############################################################
333 def update_graph_database(rrd_dir, type, n_source, n_binary):
337 rrd_file = os.path.join(rrd_dir, type.lower()+'.rrd')
338 update = [rrd_file, "N:%s:%s" % (n_source, n_binary)]
341 rrdtool.update(*update)
342 except rrdtool.error:
343 create = [rrd_file]+"""
348 DS:ds0:GAUGE:7200:0:1000
349 DS:ds1:GAUGE:7200:0:1000
350 RRA:AVERAGE:0.5:1:599
351 RRA:AVERAGE:0.5:6:700
352 RRA:AVERAGE:0.5:24:775
353 RRA:AVERAGE:0.5:288:795
358 """.strip().split("\n")
360 rc = rrdtool.create(*create)
361 ru = rrdtool.update(*update)
362 except rrdtool.error as e:
363 print('warning: queue_report: rrdtool error, skipping %s.rrd: %s' % (type, e))
367 ############################################################
369 def process_queue(queue, log, rrd_dir):
371 type = queue.queue_name
373 # Divide the .changes into per-source groups
375 for upload in queue.uploads:
376 source = upload.changes.source
377 if source not in per_source:
378 per_source[source] = {}
379 per_source[source]["list"] = []
380 per_source[source]["list"].append(upload)
381 # Determine oldest time and have note status for each source group
382 for source in per_source.keys():
383 source_list = per_source[source]["list"]
384 first = source_list[0]
385 oldest = time.mktime(first.changes.created.timetuple())
387 for d in per_source[source]["list"]:
388 mtime = time.mktime(d.changes.created.timetuple())
389 if Cnf.has_key("Queue-Report::Options::New"):
395 have_note += has_new_comment(d.changes.source, d.changes.version)
396 per_source[source]["oldest"] = oldest
398 per_source[source]["note_state"] = 0; # none
399 elif have_note < len(source_list):
400 per_source[source]["note_state"] = 1; # some
402 per_source[source]["note_state"] = 2; # all
403 per_source_items = per_source.items()
404 per_source_items.sort(sg_compare)
406 update_graph_database(rrd_dir, type, len(per_source_items), len(queue.uploads))
412 for i in per_source_items:
421 filename=i[1]["list"][0].changes.changesname
422 last_modified = time.time()-i[1]["oldest"]
423 source = i[1]["list"][0].changes.source
424 if len(source) > max_source_len:
425 max_source_len = len(source)
426 binary_list = i[1]["list"][0].binaries
427 binary = ', '.join([ b.package for b in binary_list ])
430 for j in i[1]["list"]:
432 changesbase = dbc.changesname
434 if Cnf.has_key("Queue-Report::Options::New") or Cnf.has_key("Queue-Report::Options::822"):
436 (maintainer["maintainer822"], maintainer["maintainer2047"],
437 maintainer["maintainername"], maintainer["maintaineremail"]) = \
438 fix_maintainer (dbc.maintainer)
439 except ParseMaintError as msg:
440 print "Problems while parsing maintainer address\n"
441 maintainer["maintainername"] = "Unknown"
442 maintainer["maintaineremail"] = "Unknown"
443 maint="%s:%s" % (maintainer["maintainername"], maintainer["maintaineremail"])
444 # ...likewise for the Changed-By: field if it exists.
446 (changeby["changedby822"], changeby["changedby2047"],
447 changeby["changedbyname"], changeby["changedbyemail"]) = \
448 fix_maintainer (dbc.changedby)
449 except ParseMaintError as msg:
450 (changeby["changedby822"], changeby["changedby2047"],
451 changeby["changedbyname"], changeby["changedbyemail"]) = \
453 changedby="%s:%s" % (changeby["changedbyname"], changeby["changedbyemail"])
455 distribution=dbc.distribution.split()
458 fingerprint = dbc.fingerprint
459 sponsor_name = get_uid_from_fingerprint(fingerprint).name
460 sponsor_email = get_uid_from_fingerprint(fingerprint).uid + "@debian.org"
461 if sponsor_name != maintainer["maintainername"] and sponsor_name != changeby["changedbyname"] and \
462 sponsor_email != maintainer["maintaineremail"] and sponsor_name != changeby["changedbyemail"]:
463 sponsor = sponsor_email
465 for arch in dbc.architecture.split():
467 versions.add(dbc.version)
468 arches_list = list(arches)
469 arches_list.sort(utils.arch_compare_sw)
470 arch_list = " ".join(arches_list)
471 version_list = " ".join(versions)
472 if len(version_list) > max_version_len:
473 max_version_len = len(version_list)
474 if len(arch_list) > max_arch_len:
475 max_arch_len = len(arch_list)
476 if i[1]["note_state"]:
480 entries.append([source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, filename])
482 # direction entry consists of "Which field, which direction, time-consider" where
483 # time-consider says how we should treat last_modified. Thats all.
485 # Look for the options for sort and then do the sort.
487 if Cnf.has_key("Queue-Report::Options::Age"):
488 age = Cnf["Queue-Report::Options::Age"]
489 if Cnf.has_key("Queue-Report::Options::New"):
490 # If we produce html we always have oldest first.
491 direction.append([5,-1,"ao"])
493 if Cnf.has_key("Queue-Report::Options::Sort"):
494 for i in Cnf["Queue-Report::Options::Sort"].split(","):
497 direction.append([5,-1,age])
500 direction.append([5,1,age])
503 direction.append([0,1,0])
506 direction.append([0,-1,0])
509 direction.append([4,1,0])
512 direction.append([4,-1,0])
513 entries.sort(lambda x, y: sortfunc(x, y))
514 # Yes, in theory you can add several sort options at the commandline with. But my mind is to small
515 # at the moment to come up with a real good sorting function that considers all the sidesteps you
516 # have with it. (If you combine options it will simply take the last one at the moment).
517 # Will be enhanced in the future.
519 if Cnf.has_key("Queue-Report::Options::822"):
520 # print stuff out in 822 format
521 for entry in entries:
522 (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, changes_file) = entry
524 # We'll always have Source, Version, Arch, Mantainer, and Dist
525 # For the rest, check to see if we have them, then print them out
526 log.write("Source: " + source + "\n")
527 log.write("Binary: " + binary + "\n")
528 log.write("Version: " + version_list + "\n")
529 log.write("Architectures: ")
530 log.write( (", ".join(arch_list.split(" "))) + "\n")
531 log.write("Age: " + time_pp(last_modified) + "\n")
532 log.write("Last-Modified: " + str(int(time.time()) - int(last_modified)) + "\n")
533 log.write("Queue: " + type + "\n")
535 (name, mail) = maint.split(":", 1)
536 log.write("Maintainer: " + name + " <"+mail+">" + "\n")
538 (name, mail) = changedby.split(":", 1)
539 log.write("Changed-By: " + name + " <"+mail+">" + "\n")
541 log.write("Sponsored-By: " + "@".join(sponsor.split("@")[:2]) + "\n")
542 log.write("Distribution:")
543 for dist in distribution:
544 log.write(" " + dist)
546 log.write("Fingerprint: " + fingerprint + "\n")
550 bug_string += "#"+bugs+", "
551 log.write("Closes: " + bug_string[:-2] + "\n")
552 log.write("Changes-File: " + os.path.basename(changes_file) + "\n")
555 if Cnf.has_key("Queue-Report::Options::New"):
556 direction.append([5,1,"ao"])
557 entries.sort(lambda x, y: sortfunc(x, y))
558 # Output for a html file. First table header. then table_footer.
559 # Any line between them is then a <tr> printed from subroutine table_row.
561 total_count = len(changes_files)
562 source_count = len(per_source_items)
563 table_header(type.upper(), source_count, total_count)
564 for entry in entries:
565 (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, undef) = entry
566 table_row(source, version_list, arch_list, time_pp(last_modified), maint, distribution, closes, fingerprint, sponsor, changedby)
567 table_footer(type.upper())
568 elif not Cnf.has_key("Queue-Report::Options::822"):
569 # The "normal" output without any formatting.
570 format="%%-%ds | %%-%ds | %%-%ds%%s | %%s old\n" % (max_source_len, max_version_len, max_arch_len)
573 for entry in entries:
574 (source, binary, version_list, arch_list, note, last_modified, undef, undef, undef, undef, undef, undef, undef) = entry
575 msg += format % (source, version_list, arch_list, note, time_pp(last_modified))
578 total_count = len(queue.uploads)
579 source_count = len(per_source_items)
584 print "%s %s source package%s / %s %s package%s in total." % (source_count, type, plural(source_count), total_count, type, plural(total_count))
587 ################################################################################
592 Cnf = utils.get_conf()
593 Arguments = [('h',"help","Queue-Report::Options::Help"),
594 ('n',"new","Queue-Report::Options::New"),
595 ('8','822',"Queue-Report::Options::822"),
596 ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
597 ('a',"age","Queue-Report::Options::Age", "HasArg"),
598 ('r',"rrd","Queue-Report::Options::Rrd", "HasArg"),
599 ('d',"directories","Queue-Report::Options::Directories", "HasArg")]
601 if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
602 Cnf["Queue-Report::Options::%s" % (i)] = ""
604 apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
606 Options = Cnf.subtree("Queue-Report::Options")
610 if Cnf.has_key("Queue-Report::Options::New"):
615 if Cnf.has_key("Queue-Report::Options::Directories"):
616 for i in Cnf["Queue-Report::Options::Directories"].split(","):
617 queue_names.append(i)
618 elif Cnf.has_key("Queue-Report::Directories"):
619 queue_names = Cnf.value_list("Queue-Report::Directories")
621 queue_names = [ "byhand", "new" ]
623 if Cnf.has_key("Queue-Report::Options::Rrd"):
624 rrd_dir = Cnf["Queue-Report::Options::Rrd"]
625 elif Cnf.has_key("Dir::Rrd"):
626 rrd_dir = Cnf["Dir::Rrd"]
631 if Cnf.has_key("Queue-Report::Options::822"):
632 # Open the report file
633 f = open(Cnf["Queue-Report::ReportLocations::822Location"], "w")
635 session = DBConn().session()
637 for queue_name in queue_names:
638 queue = session.query(PolicyQueue).filter_by(queue_name=queue_name).first()
639 if queue is not None:
640 process_queue(queue, f, rrd_dir)
642 utils.warn("Cannot find queue %s" % queue_name)
644 if Cnf.has_key("Queue-Report::Options::822"):
647 if Cnf.has_key("Queue-Report::Options::New"):
650 ################################################################################
652 if __name__ == '__main__':