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.queue import Upload
47 from daklib.dbconn import DBConn, has_new_comment, DBChange, DBSource, 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 queue directories (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">
181 function togglePkg() {
182 var children = document.getElementsByTagName("*");
183 for (var i = 0; i < children.length; i++) {
184 if(!children[i].hasAttribute("class"))
186 c = children[i].getAttribute("class").split(" ");
187 for(var j = 0; j < c.length; j++) {
188 if(c[j] == "binNEW") {
189 if (children[i].style.display == '')
190 children[i].style.display = 'none';
191 else children[i].style.display = '';
200 <a href="http://www.debian.org/">
201 <img src="http://www.debian.org/logos/openlogo-nd-50.png"
202 alt="debian logo" /></a>
203 <a href="http://www.debian.org/">
204 <img src="http://www.debian.org/Pics/debian.png"
205 alt="Debian Project" /></a>
207 <div id="titleblock">
209 <img src="http://www.debian.org/Pics/red-upperleft.png"
210 id="red-upperleft" alt="corner image"/>
211 <img src="http://www.debian.org/Pics/red-lowerleft.png"
212 id="red-lowerleft" alt="corner image"/>
213 <img src="http://www.debian.org/Pics/red-upperright.png"
214 id="red-upperright" alt="corner image"/>
215 <img src="http://www.debian.org/Pics/red-lowerright.png"
216 id="red-lowerright" alt="corner image"/>
218 Debian NEW and BYHAND Packages
224 print "<p class=\"timestamp\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
225 print "<p class=\"timestamp\">There are <a href=\"/stat.html\">graphs about the queues</a> available.</p>"
229 <p>Hint: Age is the youngest upload of the package, if there is more than
231 You may want to look at <a href="http://ftp-master.debian.org/REJECT-FAQ.html">the REJECT-FAQ</a>
232 for possible reasons why one of the above packages may get rejected.</p>
234 <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10"
235 alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
236 <a href="http://jigsaw.w3.org/css-validator/">
237 <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss"
241 </div> </body> </html>
244 def table_header(type, source_count, total_count):
245 print "<h1 class='binNEW'>Summary for: %s</h1>" % (type)
246 print "<h1 class='binNEW' style='display: none'>Summary for: binary-%s only</h1>" % (type)
249 <p class="togglepkg" onclick="togglePkg()">Click to toggle all/binary-NEW packages</p>
250 <caption class="binNEW">
252 print "Package count in <strong>%s</strong>: <em>%s</em> | Total Package count: <em>%s</em>" % (type, source_count, total_count)
260 <th>Distribution</th>
269 def table_footer(type):
270 print "</tbody></table>"
273 def table_row(source, version, arch, last_mod, maint, distribution, closes, fingerprint, sponsor, changedby):
278 session = DBConn().session()
279 for dist in distribution:
280 if dist == "experimental":
283 if not len(session.query(DBSource).filter_by(source = source).all()):
287 if row_number % 2 != 0:
288 print "<tr class=\"%s even\">" % (trclass)
290 print "<tr class=\"%s odd\">" % (trclass)
292 print "<td class=\"package\">%s</td>" % (source)
293 print "<td class=\"version\">"
294 for vers in version.split():
295 print "<a href=\"new/%s_%s.html\">%s</a><br/>" % (source, utils.html_escape(vers), utils.html_escape(vers))
297 print "<td class=\"arch\">%s</td>" % (arch)
298 print "<td class=\"distribution\">"
299 for dist in distribution:
300 print "%s<br/>" % (dist)
302 print "<td class=\"age\">%s</td>" % (last_mod)
303 (name, mail) = maint.split(":", 1)
305 print "<td class=\"upload-data\">"
306 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))
307 (name, mail) = changedby.split(":", 1)
308 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))
312 (login, domain) = sponsor.split("@", 1)
313 print "<span class=\"sponsor\">Sponsor: <a href=\"http://qa.debian.org/developer.php?login=%s\">%s</a></span>@debian.org<br/>" % (utils.html_escape(login), utils.html_escape(login))
317 print "<span class=\"signature\">Fingerprint: %s</span>" % (fingerprint)
320 print "<td class=\"closes\">"
322 print "<a href=\"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s\">#%s</a><br/>" % (utils.html_escape(close), utils.html_escape(close))
326 ############################################################
328 def update_graph_database(rrd_dir, type, n_source, n_binary):
332 rrd_file = os.path.join(rrd_dir, type.lower()+'.rrd')
333 update = [rrd_file, "N:%s:%s" % (n_source, n_binary)]
336 rrdtool.update(*update)
337 except rrdtool.error:
338 create = [rrd_file]+"""
343 DS:ds0:GAUGE:7200:0:1000
344 DS:ds1:GAUGE:7200:0:1000
345 RRA:AVERAGE:0.5:1:599
346 RRA:AVERAGE:0.5:6:700
347 RRA:AVERAGE:0.5:24:775
348 RRA:AVERAGE:0.5:288:795
353 """.strip().split("\n")
355 rc = rrdtool.create(*create)
356 ru = rrdtool.update(*update)
357 except rrdtool.error, e:
358 print('warning: queue_report: rrdtool error, skipping %s.rrd: %s' % (type, e))
362 ############################################################
364 def process_changes_files(changes_files, type, log, rrd_dir):
367 # Read in all the .changes files
368 for filename in changes_files:
371 u.load_changes(filename)
372 cache[filename] = copy(u.pkg.changes)
373 cache[filename]["filename"] = filename
375 print "WARNING: Exception %s" % e
377 # Divide the .changes into per-source groups
379 for filename in cache.keys():
380 source = cache[filename]["source"]
381 if not per_source.has_key(source):
382 per_source[source] = {}
383 per_source[source]["list"] = []
384 per_source[source]["list"].append(cache[filename])
385 # Determine oldest time and have note status for each source group
386 for source in per_source.keys():
387 source_list = per_source[source]["list"]
388 first = source_list[0]
389 oldest = os.stat(first["filename"])[stat.ST_MTIME]
391 for d in per_source[source]["list"]:
392 mtime = os.stat(d["filename"])[stat.ST_MTIME]
393 if Cnf.has_key("Queue-Report::Options::New"):
399 have_note += has_new_comment(d["source"], d["version"])
400 per_source[source]["oldest"] = oldest
402 per_source[source]["note_state"] = 0; # none
403 elif have_note < len(source_list):
404 per_source[source]["note_state"] = 1; # some
406 per_source[source]["note_state"] = 2; # all
407 per_source_items = per_source.items()
408 per_source_items.sort(sg_compare)
410 update_graph_database(rrd_dir, type, len(per_source_items), len(changes_files))
416 for i in per_source_items:
425 filename=i[1]["list"][0]["filename"]
426 last_modified = time.time()-i[1]["oldest"]
427 source = i[1]["list"][0]["source"]
428 if len(source) > max_source_len:
429 max_source_len = len(source)
430 binary_list = i[1]["list"][0]["binary"].keys()
431 binary = ', '.join(binary_list)
434 for j in i[1]["list"]:
435 changesbase = os.path.basename(j["filename"])
437 session = DBConn().session()
438 dbc = session.query(DBChange).filter_by(changesname=changesbase).one()
441 print "Can't find changes file in NEW for %s (%s)" % (changesbase, e)
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 (j["maintainer"])
449 except ParseMaintError, 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 (j["changed-by"])
459 except ParseMaintError, msg:
460 (changeby["changedby822"], changeby["changedby2047"],
461 changeby["changedbyname"], changeby["changedbyemail"]) = \
463 changedby="%s:%s" % (changeby["changedbyname"], changeby["changedbyemail"])
465 distribution=j["distribution"].keys()
466 closes=j["closes"].keys()
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 j["architecture"].keys():
477 version = j["version"]
478 versions[version] = ""
479 arches_list = arches.keys()
480 arches_list.sort(utils.arch_compare_sw)
481 arch_list = " ".join(arches_list)
482 version_list = " ".join(versions.keys())
483 if len(version_list) > max_version_len:
484 max_version_len = len(version_list)
485 if len(arch_list) > max_arch_len:
486 max_arch_len = len(arch_list)
487 if i[1]["note_state"]:
491 entries.append([source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, filename])
493 # direction entry consists of "Which field, which direction, time-consider" where
494 # time-consider says how we should treat last_modified. Thats all.
496 # Look for the options for sort and then do the sort.
498 if Cnf.has_key("Queue-Report::Options::Age"):
499 age = Cnf["Queue-Report::Options::Age"]
500 if Cnf.has_key("Queue-Report::Options::New"):
501 # If we produce html we always have oldest first.
502 direction.append([5,-1,"ao"])
504 if Cnf.has_key("Queue-Report::Options::Sort"):
505 for i in Cnf["Queue-Report::Options::Sort"].split(","):
508 direction.append([5,-1,age])
511 direction.append([5,1,age])
514 direction.append([0,1,0])
517 direction.append([0,-1,0])
520 direction.append([4,1,0])
523 direction.append([4,-1,0])
524 entries.sort(lambda x, y: sortfunc(x, y))
525 # Yes, in theory you can add several sort options at the commandline with. But my mind is to small
526 # at the moment to come up with a real good sorting function that considers all the sidesteps you
527 # have with it. (If you combine options it will simply take the last one at the moment).
528 # Will be enhanced in the future.
530 if Cnf.has_key("Queue-Report::Options::822"):
531 # print stuff out in 822 format
532 for entry in entries:
533 (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, changes_file) = entry
535 # We'll always have Source, Version, Arch, Mantainer, and Dist
536 # For the rest, check to see if we have them, then print them out
537 log.write("Source: " + source + "\n")
538 log.write("Binary: " + binary + "\n")
539 log.write("Version: " + version_list + "\n")
540 log.write("Architectures: ")
541 log.write( (", ".join(arch_list.split(" "))) + "\n")
542 log.write("Age: " + time_pp(last_modified) + "\n")
543 log.write("Last-Modified: " + str(int(time.time()) - int(last_modified)) + "\n")
544 log.write("Queue: " + type + "\n")
546 (name, mail) = maint.split(":", 1)
547 log.write("Maintainer: " + name + " <"+mail+">" + "\n")
549 (name, mail) = changedby.split(":", 1)
550 log.write("Changed-By: " + name + " <"+mail+">" + "\n")
552 log.write("Sponsored-By: " + sponsor + "\n")
553 log.write("Distribution:")
554 for dist in distribution:
555 log.write(" " + dist)
557 log.write("Fingerprint: " + fingerprint + "\n")
561 bug_string += "#"+bugs+", "
562 log.write("Closes: " + bug_string[:-2] + "\n")
563 log.write("Changes-File: " + os.path.basename(changes_file) + "\n")
566 if Cnf.has_key("Queue-Report::Options::New"):
567 direction.append([5,1,"ao"])
568 entries.sort(lambda x, y: sortfunc(x, y))
569 # Output for a html file. First table header. then table_footer.
570 # Any line between them is then a <tr> printed from subroutine table_row.
572 total_count = len(changes_files)
573 source_count = len(per_source_items)
574 table_header(type.upper(), source_count, total_count)
575 for entry in entries:
576 (source, binary, version_list, arch_list, 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\n" % (max_source_len, max_version_len, max_arch_len)
584 for entry in entries:
585 (source, binary, version_list, arch_list, note, last_modified, undef, undef, undef, undef, undef, undef, undef) = entry
586 msg += format % (source, version_list, arch_list, note, time_pp(last_modified))
589 total_count = len(changes_files)
590 source_count = len(per_source_items)
595 print "%s %s source package%s / %s %s package%s in total." % (source_count, type, plural(source_count), total_count, type, plural(total_count))
599 ################################################################################
604 Cnf = utils.get_conf()
605 Arguments = [('h',"help","Queue-Report::Options::Help"),
606 ('n',"new","Queue-Report::Options::New"),
607 ('8','822',"Queue-Report::Options::822"),
608 ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
609 ('a',"age","Queue-Report::Options::Age", "HasArg"),
610 ('r',"rrd","Queue-Report::Options::Rrd", "HasArg"),
611 ('d',"directories","Queue-Report::Options::Directories", "HasArg")]
613 if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
614 Cnf["Queue-Report::Options::%s" % (i)] = ""
616 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
618 Options = Cnf.SubTree("Queue-Report::Options")
622 if Cnf.has_key("Queue-Report::Options::New"):
625 # Initialize db so we can get the NEW comments
630 if Cnf.has_key("Queue-Report::Options::Directories"):
631 for i in Cnf["Queue-Report::Options::Directories"].split(","):
632 directories.append(i)
633 elif Cnf.has_key("Queue-Report::Directories"):
634 directories = Cnf.ValueList("Queue-Report::Directories")
636 directories = [ "byhand", "new" ]
638 if Cnf.has_key("Queue-Report::Options::Rrd"):
639 rrd_dir = Cnf["Queue-Report::Options::Rrd"]
640 elif Cnf.has_key("Dir::Rrd"):
641 rrd_dir = Cnf["Dir::Rrd"]
646 if Cnf.has_key("Queue-Report::Options::822"):
647 # Open the report file
648 f = open(Cnf["Queue-Report::ReportLocations::822Location"], "w")
650 for directory in directories:
651 changes_files = glob.glob("%s/*.changes" % (Cnf["Dir::Queue::%s" % (directory)]))
652 process_changes_files(changes_files, directory, f, rrd_dir)
654 if Cnf.has_key("Queue-Report::Options::822"):
657 if Cnf.has_key("Queue-Report::Options::New"):
660 ################################################################################
662 if __name__ == '__main__':