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
41 from daklib import utils
42 from daklib.queue import Upload
43 from daklib.dbconn import DBConn, has_new_comment, DBChange, DBSource, get_uid_from_fingerprint
44 from daklib.textutils import fix_maintainer
45 from daklib.dak_exceptions import *
51 ################################################################################
53 def usage(exit_code=0):
54 print """Usage: dak queue-report
55 Prints a report of packages in queue directories (usually new and byhand).
57 -h, --help show this help and exit.
58 -8, --822 writes 822 formated output to the location set in dak.conf
59 -n, --new produce html-output
60 -s, --sort=key sort output according to key, see below.
61 -a, --age=key if using sort by age, how should time be treated?
62 If not given a default of hours will be used.
63 -d, --directories=key A comma seperated list of queues to be scanned
65 Sorting Keys: ao=age, oldest first. an=age, newest first.
66 na=name, ascending nd=name, descending
67 nf=notes, first nl=notes, last
69 Age Keys: m=minutes, h=hours, d=days, w=weeks, o=months, y=years
74 ################################################################################
82 ################################################################################
106 return "%s %s%s" % (x, unit, plural(x))
108 ################################################################################
110 def sg_compare (a, b):
113 """Sort by have note, time of oldest upload."""
115 a_note_state = a["note_state"]
116 b_note_state = b["note_state"]
117 if a_note_state < b_note_state:
119 elif a_note_state > b_note_state:
122 # Sort by time of oldest upload
123 return cmp(a["oldest"], b["oldest"])
125 ############################################################
128 for sorting in direction:
129 (sortkey, way, time) = sorting
135 x=int(a[sortkey]/3600)
136 y=int(b[sortkey]/3600)
138 x=int(a[sortkey]/86400)
139 y=int(b[sortkey]/86400)
141 x=int(a[sortkey]/604800)
142 y=int(b[sortkey]/604800)
144 x=int(a[sortkey]/2419200)
145 y=int(b[sortkey]/2419200)
147 x=int(a[sortkey]/29030400)
148 y=int(b[sortkey]/29030400)
162 ############################################################
165 print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
166 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
167 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
169 <meta http-equiv="content-type" content="text/xhtml+xml; charset=utf-8" />
170 <link type="text/css" rel="stylesheet" href="style.css" />
171 <link rel="shortcut icon" href="http://www.debian.org/favicon.ico" />
173 Debian NEW and BYHAND Packages
175 <script type="text/javascript">
176 function togglePkg() {
177 var children = document.getElementsByTagName("*");
178 for (var i = 0; i < children.length; i++) {
179 if(!children[i].hasAttribute("class"))
181 c = children[i].getAttribute("class").split(" ");
182 for(var j = 0; j < c.length; j++) {
183 if(c[j] == "binNEW") {
184 if (children[i].style.display == '')
185 children[i].style.display = 'none';
186 else children[i].style.display = '';
195 <a href="http://www.debian.org/">
196 <img src="http://www.debian.org/logos/openlogo-nd-50.png"
197 alt="debian logo" /></a>
198 <a href="http://www.debian.org/">
199 <img src="http://www.debian.org/Pics/debian.png"
200 alt="Debian Project" /></a>
202 <div id="titleblock">
204 <img src="http://www.debian.org/Pics/red-upperleft.png"
205 id="red-upperleft" alt="corner image"/>
206 <img src="http://www.debian.org/Pics/red-lowerleft.png"
207 id="red-lowerleft" alt="corner image"/>
208 <img src="http://www.debian.org/Pics/red-upperright.png"
209 id="red-upperright" alt="corner image"/>
210 <img src="http://www.debian.org/Pics/red-lowerright.png"
211 id="red-lowerright" alt="corner image"/>
213 Debian NEW and BYHAND Packages
219 print "<p class=\"timestamp\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
223 <p>Hint: Age is the youngest upload of the package, if there is more than
225 You may want to look at <a href="http://ftp-master.debian.org/REJECT-FAQ.html">the REJECT-FAQ</a>
226 for possible reasons why one of the above packages may get rejected.</p>
228 <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10"
229 alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
230 <a href="http://jigsaw.w3.org/css-validator/">
231 <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss"
235 </div> </body> </html>
238 def table_header(type, source_count, total_count):
239 print "<h1>Summary for: %s</h1>" % (type)
242 <p class="togglepkg" onclick="togglePkg()">Click to toggle all/binary-NEW packages</p>
245 print "Package count in <strong>%s</strong>: <em>%s</em> | Total Package count: <em>%s</em>" % (type, source_count, total_count)
253 <th>Distribution</th>
262 def table_footer(type):
263 print "</tbody></table>"
266 def table_row(source, version, arch, last_mod, maint, distribution, closes, fingerprint, sponsor, changedby):
271 session = DBConn().session()
272 for dist in distribution:
273 if dist == "experimental":
276 if not len(session.query(DBSource).filter_by(source = source).all()):
280 if row_number % 2 != 0:
281 print "<tr class=\"%s even\">" % (trclass)
283 print "<tr class=\"%s odd\">" % (trclass)
285 print "<td class=\"package\">%s</td>" % (source)
286 print "<td class=\"version\">"
287 for vers in version.split():
288 print "<a href=\"/new/%s_%s.html\">%s</a><br/>" % (source, utils.html_escape(vers), utils.html_escape(vers))
290 print "<td class=\"arch\">%s</td>" % (arch)
291 print "<td class=\"distribution\">"
292 for dist in distribution:
293 print "%s<br/>" % (dist)
295 print "<td class=\"age\">%s</td>" % (last_mod)
296 (name, mail) = maint.split(":", 1)
298 print "<td class=\"upload-data\">"
299 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))
300 (name, mail) = changedby.split(":", 1)
301 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))
305 (login, domain) = sponsor.split("@", 1)
306 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))
310 print "<span class=\"signature\">Fingerprint: %s</span>" % (fingerprint)
313 print "<td class=\"closes\">"
315 print "<a href=\"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s\">#%s</a><br/>" % (utils.html_escape(close), utils.html_escape(close))
319 ############################################################
321 def process_changes_files(changes_files, type, log):
322 session = DBConn().session()
325 # Read in all the .changes files
326 for filename in changes_files:
329 u.load_changes(filename)
330 cache[filename] = copy(u.pkg.changes)
331 cache[filename]["filename"] = filename
333 print "WARNING: Exception %s" % e
335 # Divide the .changes into per-source groups
337 for filename in cache.keys():
338 source = cache[filename]["source"]
339 if not per_source.has_key(source):
340 per_source[source] = {}
341 per_source[source]["list"] = []
342 per_source[source]["list"].append(cache[filename])
343 # Determine oldest time and have note status for each source group
344 for source in per_source.keys():
345 source_list = per_source[source]["list"]
346 first = source_list[0]
347 oldest = os.stat(first["filename"])[stat.ST_MTIME]
349 for d in per_source[source]["list"]:
350 mtime = os.stat(d["filename"])[stat.ST_MTIME]
351 if Cnf.has_key("Queue-Report::Options::New"):
357 have_note += has_new_comment(d["source"], d["version"])
358 per_source[source]["oldest"] = oldest
360 per_source[source]["note_state"] = 0; # none
361 elif have_note < len(source_list):
362 per_source[source]["note_state"] = 1; # some
364 per_source[source]["note_state"] = 2; # all
365 per_source_items = per_source.items()
366 per_source_items.sort(sg_compare)
372 for i in per_source_items:
381 filename=i[1]["list"][0]["filename"]
382 last_modified = time.time()-i[1]["oldest"]
383 source = i[1]["list"][0]["source"]
384 if len(source) > max_source_len:
385 max_source_len = len(source)
386 binary_list = i[1]["list"][0]["binary"].keys()
387 binary = ', '.join(binary_list)
390 for j in i[1]["list"]:
391 changesbase = os.path.basename(j["filename"])
393 dbc = session.query(DBChange).filter_by(changesname=changesbase).one()
395 print "Can't find changes file in NEW for %s (%s)" % (changesbase, e)
398 if Cnf.has_key("Queue-Report::Options::New") or Cnf.has_key("Queue-Report::Options::822"):
400 (maintainer["maintainer822"], maintainer["maintainer2047"],
401 maintainer["maintainername"], maintainer["maintaineremail"]) = \
402 fix_maintainer (j["maintainer"])
403 except ParseMaintError, msg:
404 print "Problems while parsing maintainer address\n"
405 maintainer["maintainername"] = "Unknown"
406 maintainer["maintaineremail"] = "Unknown"
407 maint="%s:%s" % (maintainer["maintainername"], maintainer["maintaineremail"])
408 # ...likewise for the Changed-By: field if it exists.
410 (changeby["changedby822"], changeby["changedby2047"],
411 changeby["changedbyname"], changeby["changedbyemail"]) = \
412 fix_maintainer (j["changed-by"])
413 except ParseMaintError, msg:
414 (changeby["changedby822"], changeby["changedby2047"],
415 changeby["changedbyname"], changeby["changedbyemail"]) = \
417 changedby="%s:%s" % (changeby["changedbyname"], changeby["changedbyemail"])
419 distribution=j["distribution"].keys()
420 closes=j["closes"].keys()
422 fingerprint = dbc.fingerprint
423 sponsor_name = get_uid_from_fingerprint(fingerprint).name
424 sponsor_email = get_uid_from_fingerprint(fingerprint).uid + "@debian.org"
425 if sponsor_name != maintainer["maintainername"] and sponsor_name != changeby["changedbyname"] and \
426 sponsor_email != maintainer["maintaineremail"] and sponsor_name != changeby["changedbyemail"]:
427 sponsor = sponsor_email
429 for arch in j["architecture"].keys():
431 version = j["version"]
432 versions[version] = ""
433 arches_list = arches.keys()
434 arches_list.sort(utils.arch_compare_sw)
435 arch_list = " ".join(arches_list)
436 version_list = " ".join(versions.keys())
437 if len(version_list) > max_version_len:
438 max_version_len = len(version_list)
439 if len(arch_list) > max_arch_len:
440 max_arch_len = len(arch_list)
441 if i[1]["note_state"]:
445 entries.append([source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, filename])
447 # direction entry consists of "Which field, which direction, time-consider" where
448 # time-consider says how we should treat last_modified. Thats all.
450 # Look for the options for sort and then do the sort.
452 if Cnf.has_key("Queue-Report::Options::Age"):
453 age = Cnf["Queue-Report::Options::Age"]
454 if Cnf.has_key("Queue-Report::Options::New"):
455 # If we produce html we always have oldest first.
456 direction.append([5,-1,"ao"])
458 if Cnf.has_key("Queue-Report::Options::Sort"):
459 for i in Cnf["Queue-Report::Options::Sort"].split(","):
462 direction.append([5,-1,age])
465 direction.append([5,1,age])
468 direction.append([0,1,0])
471 direction.append([0,-1,0])
474 direction.append([4,1,0])
477 direction.append([4,-1,0])
478 entries.sort(lambda x, y: sortfunc(x, y))
479 # Yes, in theory you can add several sort options at the commandline with. But my mind is to small
480 # at the moment to come up with a real good sorting function that considers all the sidesteps you
481 # have with it. (If you combine options it will simply take the last one at the moment).
482 # Will be enhanced in the future.
484 if Cnf.has_key("Queue-Report::Options::822"):
485 # print stuff out in 822 format
486 for entry in entries:
487 (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, changes_file) = entry
489 # We'll always have Source, Version, Arch, Mantainer, and Dist
490 # For the rest, check to see if we have them, then print them out
491 log.write("Source: " + source + "\n")
492 log.write("Binary: " + binary + "\n")
493 log.write("Version: " + version_list + "\n")
494 log.write("Architectures: ")
495 log.write( (", ".join(arch_list.split(" "))) + "\n")
496 log.write("Age: " + time_pp(last_modified) + "\n")
497 log.write("Last-Modified: " + str(int(time.time()) - int(last_modified)) + "\n")
498 log.write("Queue: " + type + "\n")
500 (name, mail) = maint.split(":", 1)
501 log.write("Maintainer: " + name + " <"+mail+">" + "\n")
503 (name, mail) = changedby.split(":", 1)
504 log.write("Changed-By: " + name + " <"+mail+">" + "\n")
506 log.write("Sponsored-By: " + sponsor + "\n")
507 log.write("Distribution:")
508 for dist in distribution:
509 log.write(" " + dist)
511 log.write("Fingerprint: " + fingerprint + "\n")
515 bug_string += "#"+bugs+", "
516 log.write("Closes: " + bug_string[:-2] + "\n")
517 log.write("Changes-File: " + os.path.basename(changes_file) + "\n")
520 if Cnf.has_key("Queue-Report::Options::New"):
521 direction.append([5,1,"ao"])
522 entries.sort(lambda x, y: sortfunc(x, y))
523 # Output for a html file. First table header. then table_footer.
524 # Any line between them is then a <tr> printed from subroutine table_row.
526 total_count = len(changes_files)
527 source_count = len(per_source_items)
528 table_header(type.upper(), source_count, total_count)
529 for entry in entries:
530 (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, undef) = entry
531 table_row(source, version_list, arch_list, time_pp(last_modified), maint, distribution, closes, fingerprint, sponsor, changedby)
532 table_footer(type.upper())
533 elif not Cnf.has_key("Queue-Report::Options::822"):
534 # The "normal" output without any formatting.
535 format="%%-%ds | %%-%ds | %%-%ds%%s | %%s old\n" % (max_source_len, max_version_len, max_arch_len)
538 for entry in entries:
539 (source, binary, version_list, arch_list, note, last_modified, undef, undef, undef, undef, undef, undef, undef) = entry
540 msg += format % (source, version_list, arch_list, note, time_pp(last_modified))
543 total_count = len(changes_files)
544 source_count = len(per_source_items)
549 print "%s %s source package%s / %s %s package%s in total." % (source_count, type, plural(source_count), total_count, type, plural(total_count))
553 ################################################################################
558 Cnf = utils.get_conf()
559 Arguments = [('h',"help","Queue-Report::Options::Help"),
560 ('n',"new","Queue-Report::Options::New"),
561 ('8','822',"Queue-Report::Options::822"),
562 ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
563 ('a',"age","Queue-Report::Options::Age", "HasArg"),
564 ('d',"directories","Queue-Report::Options::Directories", "HasArg")]
566 if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
567 Cnf["Queue-Report::Options::%s" % (i)] = ""
569 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
571 Options = Cnf.SubTree("Queue-Report::Options")
575 if Cnf.has_key("Queue-Report::Options::New"):
578 # Initialize db so we can get the NEW comments
583 if Cnf.has_key("Queue-Report::Options::Directories"):
584 for i in Cnf["Queue-Report::Options::Directories"].split(","):
585 directories.append(i)
586 elif Cnf.has_key("Queue-Report::Directories"):
587 directories = Cnf.ValueList("Queue-Report::Directories")
589 directories = [ "byhand", "new" ]
592 if Cnf.has_key("Queue-Report::Options::822"):
593 # Open the report file
594 f = open(Cnf["Queue-Report::ReportLocations::822Location"], "w")
596 for directory in directories:
597 changes_files = glob.glob("%s/*.changes" % (Cnf["Dir::Queue::%s" % (directory)]))
598 process_changes_files(changes_files, directory, f)
600 if Cnf.has_key("Queue-Report::Options::822"):
603 if Cnf.has_key("Queue-Report::Options::New"):
606 ################################################################################
608 if __name__ == '__main__':