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 warnings.filterwarnings('ignore', \
39 "apt_pkg\.ParseTagFile\(\) is deprecated\. Please see apt_pkg\.TagFile\(\) for the replacement\.", \
41 warnings.filterwarnings('ignore', \
42 "Attribute '.*' of the 'apt_pkg\.TagFile' object is deprecated, use '.*' instead\.", \
45 ################################################################################
48 import glob, os, stat, sys, time
55 from daklib import utils
56 from daklib.queue import Upload
57 from daklib.dbconn import DBConn, has_new_comment, DBChange, DBSource, get_uid_from_fingerprint
58 from daklib.textutils import fix_maintainer
59 from daklib.dak_exceptions import *
65 ################################################################################
67 def usage(exit_code=0):
68 print """Usage: dak queue-report
69 Prints a report of packages in queue directories (usually new and byhand).
71 -h, --help show this help and exit.
72 -8, --822 writes 822 formated output to the location set in dak.conf
73 -n, --new produce html-output
74 -s, --sort=key sort output according to key, see below.
75 -a, --age=key if using sort by age, how should time be treated?
76 If not given a default of hours will be used.
77 -r, --rrd=key Directory where rrd files to be updated are stored
78 -d, --directories=key A comma seperated list of queues to be scanned
80 Sorting Keys: ao=age, oldest first. an=age, newest first.
81 na=name, ascending nd=name, descending
82 nf=notes, first nl=notes, last
84 Age Keys: m=minutes, h=hours, d=days, w=weeks, o=months, y=years
89 ################################################################################
97 ################################################################################
121 return "%s %s%s" % (x, unit, plural(x))
123 ################################################################################
125 def sg_compare (a, b):
128 """Sort by have note, time of oldest upload."""
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">
191 function togglePkg() {
192 var children = document.getElementsByTagName("*");
193 for (var i = 0; i < children.length; i++) {
194 if(!children[i].hasAttribute("class"))
196 c = children[i].getAttribute("class").split(" ");
197 for(var j = 0; j < c.length; j++) {
198 if(c[j] == "binNEW") {
199 if (children[i].style.display == '')
200 children[i].style.display = 'none';
201 else children[i].style.display = '';
210 <a href="http://www.debian.org/">
211 <img src="http://www.debian.org/logos/openlogo-nd-50.png"
212 alt="debian logo" /></a>
213 <a href="http://www.debian.org/">
214 <img src="http://www.debian.org/Pics/debian.png"
215 alt="Debian Project" /></a>
217 <div id="titleblock">
219 <img src="http://www.debian.org/Pics/red-upperleft.png"
220 id="red-upperleft" alt="corner image"/>
221 <img src="http://www.debian.org/Pics/red-lowerleft.png"
222 id="red-lowerleft" alt="corner image"/>
223 <img src="http://www.debian.org/Pics/red-upperright.png"
224 id="red-upperright" alt="corner image"/>
225 <img src="http://www.debian.org/Pics/red-lowerright.png"
226 id="red-lowerright" alt="corner image"/>
228 Debian NEW and BYHAND Packages
234 print "<p class=\"timestamp\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
235 print "<p class=\"timestamp\">There are <a href=\"/stat.html\">graphs about the queues</a> available.</p>"
239 <p>Hint: Age is the youngest upload of the package, if there is more than
241 You may want to look at <a href="http://ftp-master.debian.org/REJECT-FAQ.html">the REJECT-FAQ</a>
242 for possible reasons why one of the above packages may get rejected.</p>
244 <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10"
245 alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
246 <a href="http://jigsaw.w3.org/css-validator/">
247 <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss"
251 </div> </body> </html>
254 def table_header(type, source_count, total_count):
255 print "<h1 class='binNEW'>Summary for: %s</h1>" % (type)
256 print "<h1 class='binNEW' style='display: none'>Summary for: binary-%s only</h1>" % (type)
259 <p class="togglepkg" onclick="togglePkg()">Click to toggle all/binary-NEW packages</p>
260 <caption class="binNEW">
262 print "Package count in <strong>%s</strong>: <em>%s</em> | Total Package count: <em>%s</em>" % (type, source_count, total_count)
270 <th>Distribution</th>
279 def table_footer(type):
280 print "</tbody></table>"
283 def table_row(source, version, arch, last_mod, maint, distribution, closes, fingerprint, sponsor, changedby):
288 session = DBConn().session()
289 for dist in distribution:
290 if dist == "experimental":
293 if not len(session.query(DBSource).filter_by(source = source).all()):
297 if row_number % 2 != 0:
298 print "<tr class=\"%s even\">" % (trclass)
300 print "<tr class=\"%s odd\">" % (trclass)
302 print "<td class=\"package\">%s</td>" % (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></span>@debian.org<br/>" % (utils.html_escape(login), utils.html_escape(login))
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, e:
368 print('warning: queue_report: rrdtool error, skipping %s.rrd: %s' % (type, e))
372 ############################################################
374 def process_changes_files(changes_files, type, log, rrd_dir):
377 # Read in all the .changes files
378 for filename in changes_files:
381 u.load_changes(filename)
382 cache[filename] = copy(u.pkg.changes)
383 cache[filename]["filename"] = filename
385 print "WARNING: Exception %s" % e
387 # Divide the .changes into per-source groups
389 for filename in cache.keys():
390 source = cache[filename]["source"]
391 if not per_source.has_key(source):
392 per_source[source] = {}
393 per_source[source]["list"] = []
394 per_source[source]["list"].append(cache[filename])
395 # Determine oldest time and have note status for each source group
396 for source in per_source.keys():
397 source_list = per_source[source]["list"]
398 first = source_list[0]
399 oldest = os.stat(first["filename"])[stat.ST_MTIME]
401 for d in per_source[source]["list"]:
402 mtime = os.stat(d["filename"])[stat.ST_MTIME]
403 if Cnf.has_key("Queue-Report::Options::New"):
409 have_note += has_new_comment(d["source"], d["version"])
410 per_source[source]["oldest"] = oldest
412 per_source[source]["note_state"] = 0; # none
413 elif have_note < len(source_list):
414 per_source[source]["note_state"] = 1; # some
416 per_source[source]["note_state"] = 2; # all
417 per_source_items = per_source.items()
418 per_source_items.sort(sg_compare)
420 update_graph_database(rrd_dir, type, len(per_source_items), len(changes_files))
426 for i in per_source_items:
435 filename=i[1]["list"][0]["filename"]
436 last_modified = time.time()-i[1]["oldest"]
437 source = i[1]["list"][0]["source"]
438 if len(source) > max_source_len:
439 max_source_len = len(source)
440 binary_list = i[1]["list"][0]["binary"].keys()
441 binary = ', '.join(binary_list)
444 for j in i[1]["list"]:
445 changesbase = os.path.basename(j["filename"])
447 session = DBConn().session()
448 dbc = session.query(DBChange).filter_by(changesname=changesbase).one()
451 print "Can't find changes file in NEW for %s (%s)" % (changesbase, e)
454 if Cnf.has_key("Queue-Report::Options::New") or Cnf.has_key("Queue-Report::Options::822"):
456 (maintainer["maintainer822"], maintainer["maintainer2047"],
457 maintainer["maintainername"], maintainer["maintaineremail"]) = \
458 fix_maintainer (j["maintainer"])
459 except ParseMaintError, msg:
460 print "Problems while parsing maintainer address\n"
461 maintainer["maintainername"] = "Unknown"
462 maintainer["maintaineremail"] = "Unknown"
463 maint="%s:%s" % (maintainer["maintainername"], maintainer["maintaineremail"])
464 # ...likewise for the Changed-By: field if it exists.
466 (changeby["changedby822"], changeby["changedby2047"],
467 changeby["changedbyname"], changeby["changedbyemail"]) = \
468 fix_maintainer (j["changed-by"])
469 except ParseMaintError, msg:
470 (changeby["changedby822"], changeby["changedby2047"],
471 changeby["changedbyname"], changeby["changedbyemail"]) = \
473 changedby="%s:%s" % (changeby["changedbyname"], changeby["changedbyemail"])
475 distribution=j["distribution"].keys()
476 closes=j["closes"].keys()
478 fingerprint = dbc.fingerprint
479 sponsor_name = get_uid_from_fingerprint(fingerprint).name
480 sponsor_email = get_uid_from_fingerprint(fingerprint).uid + "@debian.org"
481 if sponsor_name != maintainer["maintainername"] and sponsor_name != changeby["changedbyname"] and \
482 sponsor_email != maintainer["maintaineremail"] and sponsor_name != changeby["changedbyemail"]:
483 sponsor = sponsor_email
485 for arch in j["architecture"].keys():
487 version = j["version"]
488 versions[version] = ""
489 arches_list = arches.keys()
490 arches_list.sort(utils.arch_compare_sw)
491 arch_list = " ".join(arches_list)
492 version_list = " ".join(versions.keys())
493 if len(version_list) > max_version_len:
494 max_version_len = len(version_list)
495 if len(arch_list) > max_arch_len:
496 max_arch_len = len(arch_list)
497 if i[1]["note_state"]:
501 entries.append([source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, filename])
503 # direction entry consists of "Which field, which direction, time-consider" where
504 # time-consider says how we should treat last_modified. Thats all.
506 # Look for the options for sort and then do the sort.
508 if Cnf.has_key("Queue-Report::Options::Age"):
509 age = Cnf["Queue-Report::Options::Age"]
510 if Cnf.has_key("Queue-Report::Options::New"):
511 # If we produce html we always have oldest first.
512 direction.append([5,-1,"ao"])
514 if Cnf.has_key("Queue-Report::Options::Sort"):
515 for i in Cnf["Queue-Report::Options::Sort"].split(","):
518 direction.append([5,-1,age])
521 direction.append([5,1,age])
524 direction.append([0,1,0])
527 direction.append([0,-1,0])
530 direction.append([4,1,0])
533 direction.append([4,-1,0])
534 entries.sort(lambda x, y: sortfunc(x, y))
535 # Yes, in theory you can add several sort options at the commandline with. But my mind is to small
536 # at the moment to come up with a real good sorting function that considers all the sidesteps you
537 # have with it. (If you combine options it will simply take the last one at the moment).
538 # Will be enhanced in the future.
540 if Cnf.has_key("Queue-Report::Options::822"):
541 # print stuff out in 822 format
542 for entry in entries:
543 (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, changes_file) = entry
545 # We'll always have Source, Version, Arch, Mantainer, and Dist
546 # For the rest, check to see if we have them, then print them out
547 log.write("Source: " + source + "\n")
548 log.write("Binary: " + binary + "\n")
549 log.write("Version: " + version_list + "\n")
550 log.write("Architectures: ")
551 log.write( (", ".join(arch_list.split(" "))) + "\n")
552 log.write("Age: " + time_pp(last_modified) + "\n")
553 log.write("Last-Modified: " + str(int(time.time()) - int(last_modified)) + "\n")
554 log.write("Queue: " + type + "\n")
556 (name, mail) = maint.split(":", 1)
557 log.write("Maintainer: " + name + " <"+mail+">" + "\n")
559 (name, mail) = changedby.split(":", 1)
560 log.write("Changed-By: " + name + " <"+mail+">" + "\n")
562 log.write("Sponsored-By: " + sponsor + "\n")
563 log.write("Distribution:")
564 for dist in distribution:
565 log.write(" " + dist)
567 log.write("Fingerprint: " + fingerprint + "\n")
571 bug_string += "#"+bugs+", "
572 log.write("Closes: " + bug_string[:-2] + "\n")
573 log.write("Changes-File: " + os.path.basename(changes_file) + "\n")
576 if Cnf.has_key("Queue-Report::Options::New"):
577 direction.append([5,1,"ao"])
578 entries.sort(lambda x, y: sortfunc(x, y))
579 # Output for a html file. First table header. then table_footer.
580 # Any line between them is then a <tr> printed from subroutine table_row.
582 total_count = len(changes_files)
583 source_count = len(per_source_items)
584 table_header(type.upper(), source_count, total_count)
585 for entry in entries:
586 (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, undef) = entry
587 table_row(source, version_list, arch_list, time_pp(last_modified), maint, distribution, closes, fingerprint, sponsor, changedby)
588 table_footer(type.upper())
589 elif not Cnf.has_key("Queue-Report::Options::822"):
590 # The "normal" output without any formatting.
591 format="%%-%ds | %%-%ds | %%-%ds%%s | %%s old\n" % (max_source_len, max_version_len, max_arch_len)
594 for entry in entries:
595 (source, binary, version_list, arch_list, note, last_modified, undef, undef, undef, undef, undef, undef, undef) = entry
596 msg += format % (source, version_list, arch_list, note, time_pp(last_modified))
599 total_count = len(changes_files)
600 source_count = len(per_source_items)
605 print "%s %s source package%s / %s %s package%s in total." % (source_count, type, plural(source_count), total_count, type, plural(total_count))
609 ################################################################################
614 Cnf = utils.get_conf()
615 Arguments = [('h',"help","Queue-Report::Options::Help"),
616 ('n',"new","Queue-Report::Options::New"),
617 ('8','822',"Queue-Report::Options::822"),
618 ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
619 ('a',"age","Queue-Report::Options::Age", "HasArg"),
620 ('r',"rrd","Queue-Report::Options::Rrd", "HasArg"),
621 ('d',"directories","Queue-Report::Options::Directories", "HasArg")]
623 if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
624 Cnf["Queue-Report::Options::%s" % (i)] = ""
626 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
628 Options = Cnf.SubTree("Queue-Report::Options")
632 if Cnf.has_key("Queue-Report::Options::New"):
635 # Initialize db so we can get the NEW comments
640 if Cnf.has_key("Queue-Report::Options::Directories"):
641 for i in Cnf["Queue-Report::Options::Directories"].split(","):
642 directories.append(i)
643 elif Cnf.has_key("Queue-Report::Directories"):
644 directories = Cnf.ValueList("Queue-Report::Directories")
646 directories = [ "byhand", "new" ]
648 if Cnf.has_key("Queue-Report::Options::Rrd"):
649 rrd_dir = Cnf["Queue-Report::Options::Rrd"]
650 elif Cnf.has_key("Dir::Rrd"):
651 rrd_dir = Cnf["Dir::Rrd"]
656 if Cnf.has_key("Queue-Report::Options::822"):
657 # Open the report file
658 f = open(Cnf["Queue-Report::ReportLocations::822Location"], "w")
660 for directory in directories:
661 changes_files = glob.glob("%s/*.changes" % (Cnf["Dir::Queue::%s" % (directory)]))
662 process_changes_files(changes_files, directory, f, rrd_dir)
664 if Cnf.has_key("Queue-Report::Options::822"):
667 if Cnf.has_key("Queue-Report::Options::New"):
670 ################################################################################
672 if __name__ == '__main__':