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 ################################################################################
37 import copy, glob, os, stat, sys, time
40 from daklib import queue
41 from daklib import utils
42 from daklib.dak_exceptions import *
49 ################################################################################
51 def usage(exit_code=0):
52 print """Usage: dak queue-report
53 Prints a report of packages in queue directories (usually new and byhand).
55 -h, --help show this help and exit.
56 -n, --new produce html-output
57 -s, --sort=key sort output according to key, see below.
58 -a, --age=key if using sort by age, how should time be treated?
59 If not given a default of hours will be used.
61 Sorting Keys: ao=age, oldest first. an=age, newest first.
62 na=name, ascending nd=name, descending
63 nf=notes, first nl=notes, last
65 Age Keys: m=minutes, h=hours, d=days, w=weeks, o=months, y=years
70 ################################################################################
78 ################################################################################
102 return "%s %s%s" % (x, unit, plural(x))
104 ################################################################################
106 def sg_compare (a, b):
109 """Sort by have note, time of oldest upload."""
111 a_note_state = a["note_state"]
112 b_note_state = b["note_state"]
113 if a_note_state < b_note_state:
115 elif a_note_state > b_note_state:
118 # Sort by time of oldest upload
119 return cmp(a["oldest"], b["oldest"])
121 ############################################################
124 for sorting in direction:
125 (sortkey, way, time) = sorting
131 x=int(a[sortkey]/3600)
132 y=int(b[sortkey]/3600)
134 x=int(a[sortkey]/86400)
135 y=int(b[sortkey]/86400)
137 x=int(a[sortkey]/604800)
138 y=int(b[sortkey]/604800)
140 x=int(a[sortkey]/2419200)
141 y=int(b[sortkey]/2419200)
143 x=int(a[sortkey]/29030400)
144 y=int(b[sortkey]/29030400)
158 ############################################################
161 print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
162 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
163 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
165 <meta http-equiv="content-type" content="text/xhtml+xml; charset=utf-8" />
166 <link type="text/css" rel="stylesheet" href="style.css" />
167 <link rel="shortcut icon" href="http://www.debian.org/favicon.ico" />
169 Debian NEW and BYHAND Packages
174 <a href="http://www.debian.org/">
175 <img src="http://www.debian.org/logos/openlogo-nd-50.png"
176 alt="debian logo" /></a>
177 <a href="http://www.debian.org/">
178 <img src="http://www.debian.org/Pics/debian.png"
179 alt="Debian Project" /></a>
181 <div id="titleblock">
183 <img src="http://www.debian.org/Pics/red-upperleft.png"
184 id="red-upperleft" alt="corner image"/>
185 <img src="http://www.debian.org/Pics/red-lowerleft.png"
186 id="red-lowerleft" alt="corner image"/>
187 <img src="http://www.debian.org/Pics/red-upperright.png"
188 id="red-upperright" alt="corner image"/>
189 <img src="http://www.debian.org/Pics/red-lowerright.png"
190 id="red-lowerright" alt="corner image"/>
192 Debian NEW and BYHAND Packages
198 print "<p class=\"timestamp\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
202 <p>Hint: Age is the youngest upload of the package, if there is more than
204 You may want to look at <a href="http://ftp-master.debian.org/REJECT-FAQ.html">the REJECT-FAQ</a>
205 for possible reasons why one of the above packages may get rejected.</p>
207 <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10"
208 alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
209 <a href="http://jigsaw.w3.org/css-validator/">
210 <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss"
214 </div> </body> </html>
217 def table_header(type, source_count, total_count):
218 print "<h1>Summary for: %s</h1>" % (type)
223 print "Package count in <strong>%s</strong>: <em>%s</em> | Total Package count: <em>%s</em>" % (type, source_count, total_count)
231 <th>Distribution</th>
240 def table_footer(type):
241 print "</tbody></table>"
244 def table_row(source, version, arch, last_mod, maint, distribution, closes, fingerprint, sponsor, changedby):
249 for dist in distribution:
250 if dist == "experimental":
253 if row_number % 2 != 0:
254 print "<tr class=\"%s even\">" % (trclass)
256 print "<tr class=\"%s odd\">" % (trclass)
258 print "<td class=\"package\">%s</td>" % (source)
259 print "<td class=\"version\">"
260 for vers in version.split():
261 print "<a href=\"/new/%s_%s.html\">%s</a><br/>" % (source, utils.html_escape(vers), utils.html_escape(vers))
263 print "<td class=\"arch\">%s</td>" % (arch)
264 print "<td class=\"distribution\">"
265 for dist in distribution:
266 print "%s<br/>" % (dist)
268 print "<td class=\"age\">%s</td>" % (last_mod)
269 (name, mail) = maint.split(":")
271 print "<td class=\"upload-data\">"
272 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))
273 (name, mail) = changedby.split(":")
274 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))
277 (login, domain) = sponsor.split("@")
278 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))
282 print "<span class=\"signature\">Fingerprint: %s</span>" % (fingerprint)
285 print "<td class=\"closes\">"
287 print "<a href=\"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s\">#%s</a><br/>" % (utils.html_escape(close), utils.html_escape(close))
291 ############################################################
293 def process_changes_files(changes_files, type):
296 # Read in all the .changes files
297 for filename in changes_files:
299 Upload.pkg.changes_file = filename
302 cache[filename] = copy.copy(Upload.pkg.changes)
303 cache[filename]["filename"] = filename
306 # Divide the .changes into per-source groups
308 for filename in cache.keys():
309 source = cache[filename]["source"]
310 if not per_source.has_key(source):
311 per_source[source] = {}
312 per_source[source]["list"] = []
313 per_source[source]["list"].append(cache[filename])
314 # Determine oldest time and have note status for each source group
315 for source in per_source.keys():
316 source_list = per_source[source]["list"]
317 first = source_list[0]
318 oldest = os.stat(first["filename"])[stat.ST_MTIME]
320 for d in per_source[source]["list"]:
321 mtime = os.stat(d["filename"])[stat.ST_MTIME]
322 if Cnf.has_key("Queue-Report::Options::New"):
328 have_note += (d.has_key("process-new note"))
329 per_source[source]["oldest"] = oldest
331 per_source[source]["note_state"] = 0; # none
332 elif have_note < len(source_list):
333 per_source[source]["note_state"] = 1; # some
335 per_source[source]["note_state"] = 2; # all
336 per_source_items = per_source.items()
337 per_source_items.sort(sg_compare)
343 for i in per_source_items:
352 last_modified = time.time()-i[1]["oldest"]
353 source = i[1]["list"][0]["source"]
354 if len(source) > max_source_len:
355 max_source_len = len(source)
358 for j in i[1]["list"]:
359 if Cnf.has_key("Queue-Report::Options::New"):
361 (maintainer["maintainer822"], maintainer["maintainer2047"],
362 maintainer["maintainername"], maintainer["maintaineremail"]) = \
363 utils.fix_maintainer (j["maintainer"])
364 except ParseMaintError, msg:
365 print "Problems while parsing maintainer address\n"
366 maintainer["maintainername"] = "Unknown"
367 maintainer["maintaineremail"] = "Unknown"
368 maint="%s:%s" % (maintainer["maintainername"], maintainer["maintaineremail"])
369 # ...likewise for the Changed-By: field if it exists.
371 (changeby["changedby822"], changeby["changedby2047"],
372 changeby["changedbyname"], changeby["changedbyemail"]) = \
373 utils.fix_maintainer (j["changed-by"])
374 except ParseMaintError, msg:
375 (changeby["changedby822"], changeby["changedby2047"],
376 changeby["changedbyname"], changeby["changedbyemail"]) = \
378 changedby="%s:%s" % (changeby["changedbyname"], changeby["changedbyemail"])
380 distribution=j["distribution"].keys()
381 closes=j["closes"].keys()
382 fingerprint=j["fingerprint"]
383 if j.has_key("sponsoremail"):
384 sponsor=j["sponsoremail"]
385 for arch in j["architecture"].keys():
387 version = j["version"]
388 versions[version] = ""
389 arches_list = arches.keys()
390 arches_list.sort(utils.arch_compare_sw)
391 arch_list = " ".join(arches_list)
392 version_list = " ".join(versions.keys())
393 if len(version_list) > max_version_len:
394 max_version_len = len(version_list)
395 if len(arch_list) > max_arch_len:
396 max_arch_len = len(arch_list)
397 if i[1]["note_state"]:
401 entries.append([source, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby])
403 # direction entry consists of "Which field, which direction, time-consider" where
404 # time-consider says how we should treat last_modified. Thats all.
406 # Look for the options for sort and then do the sort.
408 if Cnf.has_key("Queue-Report::Options::Age"):
409 age = Cnf["Queue-Report::Options::Age"]
410 if Cnf.has_key("Queue-Report::Options::New"):
411 # If we produce html we always have oldest first.
412 direction.append([4,-1,"ao"])
414 if Cnf.has_key("Queue-Report::Options::Sort"):
415 for i in Cnf["Queue-Report::Options::Sort"].split(","):
418 direction.append([4,-1,age])
421 direction.append([4,1,age])
424 direction.append([0,1,0])
427 direction.append([0,-1,0])
430 direction.append([3,1,0])
433 direction.append([3,-1,0])
434 entries.sort(lambda x, y: sortfunc(x, y))
435 # Yes, in theory you can add several sort options at the commandline with. But my mind is to small
436 # at the moment to come up with a real good sorting function that considers all the sidesteps you
437 # have with it. (If you combine options it will simply take the last one at the moment).
438 # Will be enhanced in the future.
440 if Cnf.has_key("Queue-Report::Options::New"):
441 direction.append([4,1,"ao"])
442 entries.sort(lambda x, y: sortfunc(x, y))
443 # Output for a html file. First table header. then table_footer.
444 # Any line between them is then a <tr> printed from subroutine table_row.
446 total_count = len(changes_files)
447 source_count = len(per_source_items)
448 table_header(type.upper(), source_count, total_count)
449 for entry in entries:
450 (source, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby) = entry
451 table_row(source, version_list, arch_list, time_pp(last_modified), maint, distribution, closes, fingerprint, sponsor, changedby)
452 table_footer(type.upper())
454 # The "normal" output without any formatting.
455 format="%%-%ds | %%-%ds | %%-%ds%%s | %%s old\n" % (max_source_len, max_version_len, max_arch_len)
458 for entry in entries:
459 (source, version_list, arch_list, note, last_modified, undef, undef, undef, undef, undef, undef) = entry
460 msg += format % (source, version_list, arch_list, note, time_pp(last_modified))
463 total_count = len(changes_files)
464 source_count = len(per_source_items)
469 print "%s %s source package%s / %s %s package%s in total." % (source_count, type, plural(source_count), total_count, type, plural(total_count))
473 ################################################################################
478 Cnf = utils.get_conf()
479 Arguments = [('h',"help","Queue-Report::Options::Help"),
480 ('n',"new","Queue-Report::Options::New"),
481 ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
482 ('a',"age","Queue-Report::Options::Age", "HasArg")]
484 if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
485 Cnf["Queue-Report::Options::%s" % (i)] = ""
487 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
489 Options = Cnf.SubTree("Queue-Report::Options")
493 Upload = queue.Upload(Cnf)
495 if Cnf.has_key("Queue-Report::Options::New"):
498 directories = Cnf.ValueList("Queue-Report::Directories")
500 directories = [ "byhand", "new" ]
502 for directory in directories:
503 changes_files = glob.glob("%s/*.changes" % (Cnf["Dir::Queue::%s" % (directory)]))
504 process_changes_files(changes_files, directory)
506 if Cnf.has_key("Queue-Report::Options::New"):
509 ################################################################################
511 if __name__ == '__main__':