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.utils import get_logins_from_ldap
51 from daklib.dak_exceptions import *
57 ################################################################################
59 def usage(exit_code=0):
60 print """Usage: dak queue-report
61 Prints a report of packages in queues (usually new and byhand).
63 -h, --help show this help and exit.
64 -8, --822 writes 822 formated output to the location set in dak.conf
65 -n, --new produce html-output
66 -s, --sort=key sort output according to key, see below.
67 -a, --age=key if using sort by age, how should time be treated?
68 If not given a default of hours will be used.
69 -r, --rrd=key Directory where rrd files to be updated are stored
70 -d, --directories=key A comma seperated list of queues to be scanned
72 Sorting Keys: ao=age, oldest first. an=age, newest first.
73 na=name, ascending nd=name, descending
74 nf=notes, first nl=notes, last
76 Age Keys: m=minutes, h=hours, d=days, w=weeks, o=months, y=years
81 ################################################################################
89 ################################################################################
113 return "%s %s%s" % (x, unit, plural(x))
115 ################################################################################
117 def sg_compare (a, b):
120 """Sort by have pending action, have note, time of oldest upload."""
121 # Sort by have pending action
122 a_note_state = a["processed"]
123 b_note_state = b["processed"]
124 if a_note_state < b_note_state:
126 elif a_note_state > b_note_state:
130 a_note_state = a["note_state"]
131 b_note_state = b["note_state"]
132 if a_note_state < b_note_state:
134 elif a_note_state > b_note_state:
137 # Sort by time of oldest upload
138 return cmp(a["oldest"], b["oldest"])
140 ############################################################
143 for sorting in direction:
144 (sortkey, way, time) = sorting
150 x=int(a[sortkey]/3600)
151 y=int(b[sortkey]/3600)
153 x=int(a[sortkey]/86400)
154 y=int(b[sortkey]/86400)
156 x=int(a[sortkey]/604800)
157 y=int(b[sortkey]/604800)
159 x=int(a[sortkey]/2419200)
160 y=int(b[sortkey]/2419200)
162 x=int(a[sortkey]/29030400)
163 y=int(b[sortkey]/29030400)
177 ############################################################
180 print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
181 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
182 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
184 <meta http-equiv="content-type" content="text/xhtml+xml; charset=utf-8" />
185 <link type="text/css" rel="stylesheet" href="style.css" />
186 <link rel="shortcut icon" href="http://www.debian.org/favicon.ico" />
188 Debian NEW and BYHAND Packages
190 <script type="text/javascript">
192 function togglePkg() {
193 var children = document.getElementsByTagName("*");
194 for (var i = 0; i < children.length; i++) {
195 if(!children[i].hasAttribute("class"))
197 c = children[i].getAttribute("class").split(" ");
198 for(var j = 0; j < c.length; j++) {
199 if(c[j] == "sourceNEW") {
200 if (children[i].style.display == '')
201 children[i].style.display = 'none';
202 else children[i].style.display = '';
212 <a href="http://www.debian.org/">
213 <img src="http://www.debian.org/logos/openlogo-nd-50.png"
214 alt="debian logo" /></a>
215 <a href="http://www.debian.org/">
216 <img src="http://www.debian.org/Pics/debian.png"
217 alt="Debian Project" /></a>
219 <div id="titleblock">
221 <img src="http://www.debian.org/Pics/red-upperleft.png"
222 id="red-upperleft" alt="corner image"/>
223 <img src="http://www.debian.org/Pics/red-lowerleft.png"
224 id="red-lowerleft" alt="corner image"/>
225 <img src="http://www.debian.org/Pics/red-upperright.png"
226 id="red-upperright" alt="corner image"/>
227 <img src="http://www.debian.org/Pics/red-lowerright.png"
228 id="red-lowerright" alt="corner image"/>
230 Debian NEW and BYHAND Packages
236 print "<p class=\"timestamp\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
237 print "<p class=\"timestamp\">There are <a href=\"/stat.html\">graphs about the queues</a> available.</p>"
241 <p>Hint: Age is the youngest upload of the package, if there is more than
243 You may want to look at <a href="http://ftp-master.debian.org/REJECT-FAQ.html">the REJECT-FAQ</a>
244 for possible reasons why one of the above packages may get rejected.</p>
246 <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10"
247 alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
248 <a href="http://jigsaw.w3.org/css-validator/">
249 <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss"
253 </div> </body> </html>
256 def table_header(type, source_count, total_count):
257 print "<h1 class='sourceNEW'>Summary for: %s</h1>" % (type)
258 print "<h1 class='sourceNEW' style='display: none'>Summary for: binary-%s only</h1>" % (type)
260 <p class="togglepkg" onclick="togglePkg()">Click to toggle all/binary-NEW packages</p>
262 <caption class="sourceNEW">
264 print "Package count in <strong>%s</strong>: <em>%s</em> | Total Package count: <em>%s</em>" % (type, source_count, total_count)
272 <th>Distribution</th>
281 def table_footer(type):
282 print "</tbody></table>"
285 def table_row(source, version, arch, last_mod, maint, distribution, closes, fingerprint, sponsor, changedby):
290 session = DBConn().session()
291 for dist in distribution:
292 if dist == "experimental":
295 query = '''SELECT source
297 WHERE source = :source
298 AND suite_name IN ('unstable', 'experimental')'''
299 if not session.execute(query, {'source': source}).rowcount:
300 trclass += " sourceNEW"
303 if row_number % 2 != 0:
304 print "<tr class=\"%s even\">" % (trclass)
306 print "<tr class=\"%s odd\">" % (trclass)
308 if "sourceNEW" in trclass:
309 print "<td class=\"package\">%s</td>" % (source)
311 print "<td class=\"package\"><a href=\"http://packages.qa.debian.org/%(source)s\">%(source)s</a></td>" % {'source': source}
312 print "<td class=\"version\">"
313 for vers in version.split():
314 print "<a href=\"new/%s_%s.html\">%s</a><br/>" % (source, utils.html_escape(vers), utils.html_escape(vers))
316 print "<td class=\"arch\">%s</td>" % (arch)
317 print "<td class=\"distribution\">"
318 for dist in distribution:
319 print "%s<br/>" % (dist)
321 print "<td class=\"age\">%s</td>" % (last_mod)
322 (name, mail) = maint.split(":", 1)
324 print "<td class=\"upload-data\">"
325 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))
326 (name, mail) = changedby.split(":", 1)
327 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))
330 print "<span class=\"sponsor\">Sponsor: <a href=\"http://qa.debian.org/developer.php?login=%s\">%s</a>@debian.org</span><br/>" % (utils.html_escape(sponsor), utils.html_escape(sponsor))
332 print "<span class=\"signature\">Fingerprint: %s</span>" % (fingerprint)
335 print "<td class=\"closes\">"
337 print "<a href=\"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s\">#%s</a><br/>" % (utils.html_escape(close), utils.html_escape(close))
341 ############################################################
343 def update_graph_database(rrd_dir, type, n_source, n_binary):
347 rrd_file = os.path.join(rrd_dir, type.lower()+'.rrd')
348 update = [rrd_file, "N:%s:%s" % (n_source, n_binary)]
351 rrdtool.update(*update)
352 except rrdtool.error:
353 create = [rrd_file]+"""
358 DS:ds0:GAUGE:7200:0:1000
359 DS:ds1:GAUGE:7200:0:1000
360 RRA:AVERAGE:0.5:1:599
361 RRA:AVERAGE:0.5:6:700
362 RRA:AVERAGE:0.5:24:775
363 RRA:AVERAGE:0.5:288:795
368 """.strip().split("\n")
370 rc = rrdtool.create(*create)
371 ru = rrdtool.update(*update)
372 except rrdtool.error as e:
373 print('warning: queue_report: rrdtool error, skipping %s.rrd: %s' % (type, e))
377 ############################################################
379 def process_queue(queue, log, rrd_dir):
381 type = queue.queue_name
382 session = DBConn().session()
384 # Divide the .changes into per-source groups
387 for upload in queue.uploads:
388 source = upload.changes.source
389 if source not in per_source:
390 per_source[source] = {}
391 per_source[source]["list"] = []
392 per_source[source]["processed"] = ""
393 handler = PolicyQueueUploadHandler(upload, session)
394 if handler.get_action():
395 per_source[source]["processed"] = "PENDING %s" % handler.get_action()
397 per_source[source]["list"].append(upload)
398 per_source[source]["list"].sort(lambda x, y: cmp(x.changes.created, y.changes.created), reverse=True)
399 # Determine oldest time and have note status for each source group
400 for source in per_source.keys():
401 source_list = per_source[source]["list"]
402 first = source_list[0]
403 oldest = time.mktime(first.changes.created.timetuple())
405 for d in per_source[source]["list"]:
406 mtime = time.mktime(d.changes.created.timetuple())
407 if Cnf.has_key("Queue-Report::Options::New"):
413 have_note += has_new_comment(d.policy_queue, d.changes.source, d.changes.version)
414 per_source[source]["oldest"] = oldest
416 per_source[source]["note_state"] = 0; # none
417 elif have_note < len(source_list):
418 per_source[source]["note_state"] = 1; # some
420 per_source[source]["note_state"] = 2; # all
421 per_source_items = per_source.items()
422 per_source_items.sort(sg_compare)
424 update_graph_database(rrd_dir, type, len(per_source_items), len(queue.uploads))
431 logins = get_logins_from_ldap()
434 for i in per_source_items:
443 filename=i[1]["list"][0].changes.changesname
444 last_modified = time.time()-i[1]["oldest"]
445 source = i[1]["list"][0].changes.source
446 if len(source) > max_source_len:
447 max_source_len = len(source)
448 binary_list = i[1]["list"][0].binaries
449 binary = ', '.join([ b.package for b in binary_list ])
452 for j in i[1]["list"]:
454 changesbase = dbc.changesname
456 if Cnf.has_key("Queue-Report::Options::New") or Cnf.has_key("Queue-Report::Options::822"):
458 (maintainer["maintainer822"], maintainer["maintainer2047"],
459 maintainer["maintainername"], maintainer["maintaineremail"]) = \
460 fix_maintainer (dbc.maintainer)
461 except ParseMaintError as msg:
462 print "Problems while parsing maintainer address\n"
463 maintainer["maintainername"] = "Unknown"
464 maintainer["maintaineremail"] = "Unknown"
465 maint="%s:%s" % (maintainer["maintainername"], maintainer["maintaineremail"])
466 # ...likewise for the Changed-By: field if it exists.
468 (changeby["changedby822"], changeby["changedby2047"],
469 changeby["changedbyname"], changeby["changedbyemail"]) = \
470 fix_maintainer (dbc.changedby)
471 except ParseMaintError as msg:
472 (changeby["changedby822"], changeby["changedby2047"],
473 changeby["changedbyname"], changeby["changedbyemail"]) = \
475 changedby="%s:%s" % (changeby["changedbyname"], changeby["changedbyemail"])
477 distribution=dbc.distribution.split()
480 fingerprint = dbc.fingerprint
481 sponsor_name = get_uid_from_fingerprint(fingerprint).name
482 sponsor_login = get_uid_from_fingerprint(fingerprint).uid
483 if '@' in sponsor_login:
484 if fingerprint in logins:
485 sponsor_login = logins[fingerprint]
486 if (sponsor_name != maintainer["maintainername"] and
487 sponsor_name != changeby["changedbyname"] and
488 sponsor_login + '@debian.org' != maintainer["maintaineremail"] and
489 sponsor_name != changeby["changedbyemail"]):
490 sponsor = sponsor_login
492 for arch in dbc.architecture.split():
494 versions.add(dbc.version)
495 arches_list = list(arches)
496 arches_list.sort(utils.arch_compare_sw)
497 arch_list = " ".join(arches_list)
498 version_list = " ".join(sorted(versions, reverse=True))
499 if len(version_list) > max_version_len:
500 max_version_len = len(version_list)
501 if len(arch_list) > max_arch_len:
502 max_arch_len = len(arch_list)
503 if i[1]["note_state"]:
507 entries.append([source, binary, version_list, arch_list, per_source[source]["processed"], note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, filename])
509 # direction entry consists of "Which field, which direction, time-consider" where
510 # time-consider says how we should treat last_modified. Thats all.
512 # Look for the options for sort and then do the sort.
514 if Cnf.has_key("Queue-Report::Options::Age"):
515 age = Cnf["Queue-Report::Options::Age"]
516 if Cnf.has_key("Queue-Report::Options::New"):
517 # If we produce html we always have oldest first.
518 direction.append([6,-1,"ao"])
520 if Cnf.has_key("Queue-Report::Options::Sort"):
521 for i in Cnf["Queue-Report::Options::Sort"].split(","):
524 direction.append([6,-1,age])
527 direction.append([6,1,age])
530 direction.append([0,1,0])
533 direction.append([0,-1,0])
536 direction.append([5,1,0])
539 direction.append([5,-1,0])
540 entries.sort(lambda x, y: sortfunc(x, y))
541 # Yes, in theory you can add several sort options at the commandline with. But my mind is to small
542 # at the moment to come up with a real good sorting function that considers all the sidesteps you
543 # have with it. (If you combine options it will simply take the last one at the moment).
544 # Will be enhanced in the future.
546 if Cnf.has_key("Queue-Report::Options::822"):
547 # print stuff out in 822 format
548 for entry in entries:
549 (source, binary, version_list, arch_list, processed, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, changes_file) = entry
551 # We'll always have Source, Version, Arch, Mantainer, and Dist
552 # For the rest, check to see if we have them, then print them out
553 log.write("Source: " + source + "\n")
554 log.write("Binary: " + binary + "\n")
555 log.write("Version: " + version_list + "\n")
556 log.write("Architectures: ")
557 log.write( (", ".join(arch_list.split(" "))) + "\n")
558 log.write("Age: " + time_pp(last_modified) + "\n")
559 log.write("Last-Modified: " + str(int(time.time()) - int(last_modified)) + "\n")
560 log.write("Queue: " + type + "\n")
562 (name, mail) = maint.split(":", 1)
563 log.write("Maintainer: " + name + " <"+mail+">" + "\n")
565 (name, mail) = changedby.split(":", 1)
566 log.write("Changed-By: " + name + " <"+mail+">" + "\n")
568 log.write("Sponsored-By: %s@debian.org\n" % sponsor)
569 log.write("Distribution:")
570 for dist in distribution:
571 log.write(" " + dist)
573 log.write("Fingerprint: " + fingerprint + "\n")
577 bug_string += "#"+bugs+", "
578 log.write("Closes: " + bug_string[:-2] + "\n")
579 log.write("Changes-File: " + os.path.basename(changes_file) + "\n")
582 total_count = len(queue.uploads)
583 source_count = len(per_source_items)
585 if Cnf.has_key("Queue-Report::Options::New"):
586 direction.append([6,1,"ao"])
587 entries.sort(lambda x, y: sortfunc(x, y))
588 # Output for a html file. First table header. then table_footer.
589 # Any line between them is then a <tr> printed from subroutine table_row.
591 table_header(type.upper(), source_count, total_count)
592 for entry in entries:
593 (source, binary, version_list, arch_list, processed, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, undef) = entry
594 table_row(source, version_list, arch_list, time_pp(last_modified), maint, distribution, closes, fingerprint, sponsor, changedby)
595 table_footer(type.upper())
596 elif not Cnf.has_key("Queue-Report::Options::822"):
597 # The "normal" output without any formatting.
599 for entry in entries:
600 (source, binary, version_list, arch_list, processed, note, last_modified, undef, undef, undef, undef, undef, undef, undef) = entry
602 format="%%-%ds | %%-%ds | %%-%ds | %%s\n" % (max_source_len, max_version_len, max_arch_len)
603 msg += format % (source, version_list, arch_list, processed)
605 format="%%-%ds | %%-%ds | %%-%ds%%s | %%s old\n" % (max_source_len, max_version_len, max_arch_len)
606 msg += format % (source, version_list, arch_list, note, time_pp(last_modified))
613 print ("%s %s source package%s / %s %s package%s in total / %s %s package%s to be processed." %
614 (source_count, type, plural(source_count),
615 total_count, type, plural(total_count),
616 total_pending, type, plural(total_pending)))
619 ################################################################################
624 Cnf = utils.get_conf()
625 Arguments = [('h',"help","Queue-Report::Options::Help"),
626 ('n',"new","Queue-Report::Options::New"),
627 ('8','822',"Queue-Report::Options::822"),
628 ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
629 ('a',"age","Queue-Report::Options::Age", "HasArg"),
630 ('r',"rrd","Queue-Report::Options::Rrd", "HasArg"),
631 ('d',"directories","Queue-Report::Options::Directories", "HasArg")]
633 if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
634 Cnf["Queue-Report::Options::%s" % (i)] = ""
636 apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
638 Options = Cnf.subtree("Queue-Report::Options")
642 if Cnf.has_key("Queue-Report::Options::New"):
647 if Cnf.has_key("Queue-Report::Options::Directories"):
648 for i in Cnf["Queue-Report::Options::Directories"].split(","):
649 queue_names.append(i)
650 elif Cnf.has_key("Queue-Report::Directories"):
651 queue_names = Cnf.value_list("Queue-Report::Directories")
653 queue_names = [ "byhand", "new" ]
655 if Cnf.has_key("Queue-Report::Options::Rrd"):
656 rrd_dir = Cnf["Queue-Report::Options::Rrd"]
657 elif Cnf.has_key("Dir::Rrd"):
658 rrd_dir = Cnf["Dir::Rrd"]
663 if Cnf.has_key("Queue-Report::Options::822"):
664 # Open the report file
665 f = open(Cnf["Queue-Report::ReportLocations::822Location"], "w")
667 session = DBConn().session()
669 for queue_name in queue_names:
670 queue = session.query(PolicyQueue).filter_by(queue_name=queue_name).first()
671 if queue is not None:
672 process_queue(queue, f, rrd_dir)
674 utils.warn("Cannot find queue %s" % queue_name)
676 if Cnf.has_key("Queue-Report::Options::822"):
679 if Cnf.has_key("Queue-Report::Options::New"):
682 ################################################################################
684 if __name__ == '__main__':