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="https://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="https://www.debian.org/">
213 <img src="https://www.debian.org/logos/openlogo-nd-50.png"
214 alt="debian logo" /></a>
215 <a href="https://www.debian.org/">
216 <img src="https://www.debian.org/Pics/debian.png"
217 alt="Debian Project" /></a>
219 <div id="titleblock">
221 <img src="https://www.debian.org/Pics/red-upperleft.png"
222 id="red-upperleft" alt="corner image"/>
223 <img src="https://www.debian.org/Pics/red-lowerleft.png"
224 id="red-lowerleft" alt="corner image"/>
225 <img src="https://www.debian.org/Pics/red-upperright.png"
226 id="red-upperright" alt="corner image"/>
227 <img src="https://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="https://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>
245 </div> </body> </html>
248 def table_header(type, source_count, total_count):
249 print "<h1 class='sourceNEW'>Summary for: %s</h1>" % (type)
250 print "<h1 class='sourceNEW' style='display: none'>Summary for: binary-%s only</h1>" % (type)
252 <p class="togglepkg" onclick="togglePkg()">Click to toggle all/binary-NEW packages</p>
254 <caption class="sourceNEW">
256 print "Package count in <strong>%s</strong>: <em>%s</em> | Total Package count: <em>%s</em>" % (type, source_count, total_count)
264 <th>Distribution</th>
273 def table_footer(type):
274 print "</tbody></table>"
277 def table_row(source, version, arch, last_mod, maint, distribution, closes, fingerprint, sponsor, changedby):
282 session = DBConn().session()
283 for dist in distribution:
284 if dist == "experimental":
287 query = '''SELECT source
289 WHERE source = :source
290 AND suite_name IN ('unstable', 'experimental')'''
291 if not session.execute(query, {'source': source}).rowcount:
292 trclass += " sourceNEW"
295 if row_number % 2 != 0:
296 print "<tr class=\"%s even\">" % (trclass)
298 print "<tr class=\"%s odd\">" % (trclass)
300 if "sourceNEW" in trclass:
301 print "<td class=\"package\">%s</td>" % (source)
303 print "<td class=\"package\"><a href=\"https://tracker.debian.org/pkg/%(source)s\">%(source)s</a></td>" % {'source': source}
304 print "<td class=\"version\">"
305 for vers in version.split():
306 print "<a href=\"new/%s_%s.html\">%s</a><br/>" % (source, utils.html_escape(vers), utils.html_escape(vers))
308 print "<td class=\"arch\">%s</td>" % (arch)
309 print "<td class=\"distribution\">"
310 for dist in distribution:
311 print "%s<br/>" % (dist)
313 print "<td class=\"age\">%s</td>" % (last_mod)
314 (name, mail) = maint.split(":", 1)
316 print "<td class=\"upload-data\">"
317 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))
318 (name, mail) = changedby.split(":", 1)
319 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 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))
324 print "<span class=\"signature\">Fingerprint: %s</span>" % (fingerprint)
327 print "<td class=\"closes\">"
329 print "<a href=\"https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s\">#%s</a><br/>" % (utils.html_escape(close), utils.html_escape(close))
333 ############################################################
335 def update_graph_database(rrd_dir, type, n_source, n_binary):
339 rrd_file = os.path.join(rrd_dir, type.lower()+'.rrd')
340 update = [rrd_file, "N:%s:%s" % (n_source, n_binary)]
343 rrdtool.update(*update)
344 except rrdtool.error:
345 create = [rrd_file]+"""
350 DS:ds0:GAUGE:7200:0:1000
351 DS:ds1:GAUGE:7200:0:1000
352 RRA:AVERAGE:0.5:1:599
353 RRA:AVERAGE:0.5:6:700
354 RRA:AVERAGE:0.5:24:775
355 RRA:AVERAGE:0.5:288:795
360 """.strip().split("\n")
362 rc = rrdtool.create(*create)
363 ru = rrdtool.update(*update)
364 except rrdtool.error as e:
365 print('warning: queue_report: rrdtool error, skipping %s.rrd: %s' % (type, e))
369 ############################################################
371 def process_queue(queue, log, rrd_dir):
373 type = queue.queue_name
374 session = DBConn().session()
376 # Divide the .changes into per-source groups
379 for upload in queue.uploads:
380 source = upload.changes.source
381 if source not in per_source:
382 per_source[source] = {}
383 per_source[source]["list"] = []
384 per_source[source]["processed"] = ""
385 handler = PolicyQueueUploadHandler(upload, session)
386 if handler.get_action():
387 per_source[source]["processed"] = "PENDING %s" % handler.get_action()
389 per_source[source]["list"].append(upload)
390 per_source[source]["list"].sort(lambda x, y: cmp(x.changes.created, y.changes.created), reverse=True)
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.policy_queue, 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))
423 logins = get_logins_from_ldap()
426 for i in per_source_items:
435 filename=i[1]["list"][0].changes.changesname
436 last_modified = time.time()-i[1]["oldest"]
437 source = i[1]["list"][0].changes.source
438 if len(source) > max_source_len:
439 max_source_len = len(source)
440 binary_list = i[1]["list"][0].binaries
441 binary = ', '.join([ b.package for b in binary_list ])
444 for j in i[1]["list"]:
446 changesbase = dbc.changesname
448 if Cnf.has_key("Queue-Report::Options::New") or Cnf.has_key("Queue-Report::Options::822"):
450 (maintainer["maintainer822"], maintainer["maintainer2047"],
451 maintainer["maintainername"], maintainer["maintaineremail"]) = \
452 fix_maintainer (dbc.maintainer)
453 except ParseMaintError as msg:
454 print "Problems while parsing maintainer address\n"
455 maintainer["maintainername"] = "Unknown"
456 maintainer["maintaineremail"] = "Unknown"
457 maint="%s:%s" % (maintainer["maintainername"], maintainer["maintaineremail"])
458 # ...likewise for the Changed-By: field if it exists.
460 (changeby["changedby822"], changeby["changedby2047"],
461 changeby["changedbyname"], changeby["changedbyemail"]) = \
462 fix_maintainer (dbc.changedby)
463 except ParseMaintError as msg:
464 (changeby["changedby822"], changeby["changedby2047"],
465 changeby["changedbyname"], changeby["changedbyemail"]) = \
467 changedby="%s:%s" % (changeby["changedbyname"], changeby["changedbyemail"])
469 distribution=dbc.distribution.split()
472 fingerprint = dbc.fingerprint
473 sponsor_name = get_uid_from_fingerprint(fingerprint).name
474 sponsor_login = get_uid_from_fingerprint(fingerprint).uid
475 if '@' in sponsor_login:
476 if fingerprint in logins:
477 sponsor_login = logins[fingerprint]
478 if (sponsor_name != maintainer["maintainername"] and
479 sponsor_name != changeby["changedbyname"] and
480 sponsor_login + '@debian.org' != maintainer["maintaineremail"] and
481 sponsor_name != changeby["changedbyemail"]):
482 sponsor = sponsor_login
484 for arch in dbc.architecture.split():
486 versions.add(dbc.version)
487 arches_list = list(arches)
488 arches_list.sort(utils.arch_compare_sw)
489 arch_list = " ".join(arches_list)
490 version_list = " ".join(sorted(versions, reverse=True))
491 if len(version_list) > max_version_len:
492 max_version_len = len(version_list)
493 if len(arch_list) > max_arch_len:
494 max_arch_len = len(arch_list)
495 if i[1]["note_state"]:
499 entries.append([source, binary, version_list, arch_list, per_source[source]["processed"], note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, filename])
501 # direction entry consists of "Which field, which direction, time-consider" where
502 # time-consider says how we should treat last_modified. Thats all.
504 # Look for the options for sort and then do the sort.
506 if Cnf.has_key("Queue-Report::Options::Age"):
507 age = Cnf["Queue-Report::Options::Age"]
508 if Cnf.has_key("Queue-Report::Options::New"):
509 # If we produce html we always have oldest first.
510 direction.append([6,-1,"ao"])
512 if Cnf.has_key("Queue-Report::Options::Sort"):
513 for i in Cnf["Queue-Report::Options::Sort"].split(","):
516 direction.append([6,-1,age])
519 direction.append([6,1,age])
522 direction.append([0,1,0])
525 direction.append([0,-1,0])
528 direction.append([5,1,0])
531 direction.append([5,-1,0])
532 entries.sort(lambda x, y: sortfunc(x, y))
533 # Yes, in theory you can add several sort options at the commandline with. But my mind is to small
534 # at the moment to come up with a real good sorting function that considers all the sidesteps you
535 # have with it. (If you combine options it will simply take the last one at the moment).
536 # Will be enhanced in the future.
538 if Cnf.has_key("Queue-Report::Options::822"):
539 # print stuff out in 822 format
540 for entry in entries:
541 (source, binary, version_list, arch_list, processed, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, changes_file) = entry
543 # We'll always have Source, Version, Arch, Mantainer, and Dist
544 # For the rest, check to see if we have them, then print them out
545 log.write("Source: " + source + "\n")
546 log.write("Binary: " + binary + "\n")
547 log.write("Version: " + version_list + "\n")
548 log.write("Architectures: ")
549 log.write( (", ".join(arch_list.split(" "))) + "\n")
550 log.write("Age: " + time_pp(last_modified) + "\n")
551 log.write("Last-Modified: " + str(int(time.time()) - int(last_modified)) + "\n")
552 log.write("Queue: " + type + "\n")
554 (name, mail) = maint.split(":", 1)
555 log.write("Maintainer: " + name + " <"+mail+">" + "\n")
557 (name, mail) = changedby.split(":", 1)
558 log.write("Changed-By: " + name + " <"+mail+">" + "\n")
560 log.write("Sponsored-By: %s@debian.org\n" % sponsor)
561 log.write("Distribution:")
562 for dist in distribution:
563 log.write(" " + dist)
565 log.write("Fingerprint: " + fingerprint + "\n")
569 bug_string += "#"+bugs+", "
570 log.write("Closes: " + bug_string[:-2] + "\n")
571 log.write("Changes-File: " + os.path.basename(changes_file) + "\n")
574 total_count = len(queue.uploads)
575 source_count = len(per_source_items)
577 if Cnf.has_key("Queue-Report::Options::New"):
578 direction.append([6,1,"ao"])
579 entries.sort(lambda x, y: sortfunc(x, y))
580 # Output for a html file. First table header. then table_footer.
581 # Any line between them is then a <tr> printed from subroutine table_row.
583 table_header(type.upper(), source_count, total_count)
584 for entry in entries:
585 (source, binary, version_list, arch_list, processed, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, undef) = entry
586 table_row(source, version_list, arch_list, time_pp(last_modified), maint, distribution, closes, fingerprint, sponsor, changedby)
587 table_footer(type.upper())
588 elif not Cnf.has_key("Queue-Report::Options::822"):
589 # The "normal" output without any formatting.
591 for entry in entries:
592 (source, binary, version_list, arch_list, processed, note, last_modified, undef, undef, undef, undef, undef, undef, undef) = entry
594 format="%%-%ds | %%-%ds | %%-%ds | %%s\n" % (max_source_len, max_version_len, max_arch_len)
595 msg += format % (source, version_list, arch_list, processed)
597 format="%%-%ds | %%-%ds | %%-%ds%%s | %%s old\n" % (max_source_len, max_version_len, max_arch_len)
598 msg += format % (source, version_list, arch_list, note, time_pp(last_modified))
605 print ("%s %s source package%s / %s %s package%s in total / %s %s package%s to be processed." %
606 (source_count, type, plural(source_count),
607 total_count, type, plural(total_count),
608 total_pending, type, plural(total_pending)))
611 ################################################################################
616 Cnf = utils.get_conf()
617 Arguments = [('h',"help","Queue-Report::Options::Help"),
618 ('n',"new","Queue-Report::Options::New"),
619 ('8','822',"Queue-Report::Options::822"),
620 ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
621 ('a',"age","Queue-Report::Options::Age", "HasArg"),
622 ('r',"rrd","Queue-Report::Options::Rrd", "HasArg"),
623 ('d',"directories","Queue-Report::Options::Directories", "HasArg")]
625 if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
626 Cnf["Queue-Report::Options::%s" % (i)] = ""
628 apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
630 Options = Cnf.subtree("Queue-Report::Options")
634 if Cnf.has_key("Queue-Report::Options::New"):
639 if Cnf.has_key("Queue-Report::Options::Directories"):
640 for i in Cnf["Queue-Report::Options::Directories"].split(","):
641 queue_names.append(i)
642 elif Cnf.has_key("Queue-Report::Directories"):
643 queue_names = Cnf.value_list("Queue-Report::Directories")
645 queue_names = [ "byhand", "new" ]
647 if Cnf.has_key("Queue-Report::Options::Rrd"):
648 rrd_dir = Cnf["Queue-Report::Options::Rrd"]
649 elif Cnf.has_key("Dir::Rrd"):
650 rrd_dir = Cnf["Dir::Rrd"]
655 if Cnf.has_key("Queue-Report::Options::822"):
656 # Open the report file
658 filename822 = Cnf.get("Queue-Report::ReportLocations::822Location")
660 f = open(filename822, "w")
662 session = DBConn().session()
664 for queue_name in queue_names:
665 queue = session.query(PolicyQueue).filter_by(queue_name=queue_name).first()
666 if queue is not None:
667 process_queue(queue, f, rrd_dir)
669 utils.warn("Cannot find queue %s" % queue_name)
671 if Cnf.has_key("Queue-Report::Options::822"):
674 if Cnf.has_key("Queue-Report::Options::New"):
677 ################################################################################
679 if __name__ == '__main__':