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
39 import daklib.queue as queue
40 import daklib.utils as utils
47 ################################################################################
49 def usage(exit_code=0):
50 print """Usage: dak queue-report
51 Prints a report of packages in queue directories (usually new and byhand).
53 -h, --help show this help and exit.
54 -n, --new produce html-output
55 -s, --sort=key sort output according to key, see below.
56 -a, --age=key if using sort by age, how should time be treated?
57 If not given a default of hours will be used.
59 Sorting Keys: ao=age, oldest first. an=age, newest first.
60 na=name, ascending nd=name, descending
61 nf=notes, first nl=notes, last
63 Age Keys: m=minutes, h=hours, d=days, w=weeks, o=months, y=years
68 ################################################################################
76 ################################################################################
100 return "%s %s%s" % (x, unit, plural(x))
102 ################################################################################
104 def sg_compare (a, b):
107 """Sort by have note, time of oldest upload."""
109 a_note_state = a["note_state"]
110 b_note_state = b["note_state"]
111 if a_note_state < b_note_state:
113 elif a_note_state > b_note_state:
116 # Sort by time of oldest upload
117 return cmp(a["oldest"], b["oldest"])
119 ############################################################
122 for sorting in direction:
123 (sortkey, way, time) = sorting
129 x=int(a[sortkey]/3600)
130 y=int(b[sortkey]/3600)
132 x=int(a[sortkey]/86400)
133 y=int(b[sortkey]/86400)
135 x=int(a[sortkey]/604800)
136 y=int(b[sortkey]/604800)
138 x=int(a[sortkey]/2419200)
139 y=int(b[sortkey]/2419200)
141 x=int(a[sortkey]/29030400)
142 y=int(b[sortkey]/29030400)
156 ############################################################
159 print """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
160 <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
161 <title>Debian NEW and BYHAND Packages</title>
162 <link type="text/css" rel="stylesheet" href="style.css">
163 <link rel="shortcut icon" href="http://www.debian.org/favicon.ico">
167 <a href="http://www.debian.org/">
168 <img src="http://www.debian.org/logos/openlogo-nd-50.png" border="0" hspace="0" vspace="0" alt=""></a>
169 <a href="http://www.debian.org/">
170 <img src="http://www.debian.org/Pics/debian.png" border="0" hspace="0" vspace="0" alt="Debian Project"></a>
173 <table class="reddy" width="100%">
176 <img src="http://www.debian.org/Pics/red-upperleft.png" align="left" border="0" hspace="0" vspace="0"
177 alt="" width="15" height="16"></td>
178 <td rowspan="2" class="reddy">Debian NEW and BYHAND Packages</td>
180 <img src="http://www.debian.org/Pics/red-upperright.png" align="right" border="0" hspace="0" vspace="0"
181 alt="" width="16" height="16"></td>
185 <img src="http://www.debian.org/Pics/red-lowerleft.png" align="left" border="0" hspace="0" vspace="0"
186 alt="" width="16" height="16"></td>
188 <img src="http://www.debian.org/Pics/red-lowerright.png" align="right" border="0" hspace="0" vspace="0"
189 alt="" width="15" height="16"></td>
195 print "<p class=\"validate\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
196 print "<hr><p>Hint: Age is the youngest upload of the package, if there is more than one version.</p>"
197 print "<p>You may want to look at <a href=\"http://ftp-master.debian.org/REJECT-FAQ.html\">the REJECT-FAQ</a> for possible reasons why one of the above packages may get rejected.</p>"
198 print """<a href="http://validator.w3.org/check?uri=referer">
199 <img border="0" src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" height="31" width="88"></a>
200 <a href="http://jigsaw.w3.org/css-validator/check/referer">
201 <img border="0" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"
202 height="31" width="88"></a>
204 print "</body></html>"
206 def table_header(type):
207 print "<h1>Summary for: %s</h1>" % (type)
208 print """<center><table border="0">
210 <th align="center">Package</th>
211 <th align="center">Version</th>
212 <th align="center">Arch</th>
213 <th align="center">Distribution</th>
214 <th align="center">Age</th>
215 <th align="center">Maintainer</th>
216 <th align="center">Closes</th>
220 def table_footer(type, source_count, total_count):
221 print "</table></center><br>\n"
222 print "<p class=\"validate\">Package count in <b>%s</b>: <i>%s</i>\n" % (type, source_count)
223 print "<br>Total Package count: <i>%s</i></p>\n" % (total_count)
226 def table_row(source, version, arch, last_mod, maint, distribution, closes):
230 if row_number % 2 != 0:
231 print "<tr class=\"even\">"
233 print "<tr class=\"odd\">"
236 for dist in distribution:
237 if dist == "experimental":
239 print "<td valign=\"top\" class=\"%s\">%s</td>" % (tdclass, source)
240 print "<td valign=\"top\" class=\"%s\">" % (tdclass)
241 for vers in version.split():
242 print "<a href=\"/new/%s_%s.html\">%s</a><br>" % (source, vers, vers)
243 print "</td><td valign=\"top\" class=\"%s\">%s</td><td valign=\"top\" class=\"%s\">" % (tdclass, arch, tdclass)
244 for dist in distribution:
245 print "%s<br>" % (dist)
246 print "</td><td valign=\"top\" class=\"%s\">%s</td>" % (tdclass, last_mod)
247 (name, mail) = maint.split(":")
249 print "<td valign=\"top\" class=\"%s\"><a href=\"http://qa.debian.org/developer.php?login=%s\">%s</a></td>" % (tdclass, mail, name)
250 print "<td valign=\"top\" class=\"%s\">" % (tdclass)
252 print "<a href=\"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s\">#%s</a><br>" % (close, close)
256 ############################################################
258 def process_changes_files(changes_files, type):
261 # Read in all the .changes files
262 for filename in changes_files:
264 Upload.pkg.changes_file = filename
267 cache[filename] = copy.copy(Upload.pkg.changes)
268 cache[filename]["filename"] = filename
271 # Divide the .changes into per-source groups
273 for filename in cache.keys():
274 source = cache[filename]["source"]
275 if not per_source.has_key(source):
276 per_source[source] = {}
277 per_source[source]["list"] = []
278 per_source[source]["list"].append(cache[filename])
279 # Determine oldest time and have note status for each source group
280 for source in per_source.keys():
281 source_list = per_source[source]["list"]
282 first = source_list[0]
283 oldest = os.stat(first["filename"])[stat.ST_MTIME]
285 for d in per_source[source]["list"]:
286 mtime = os.stat(d["filename"])[stat.ST_MTIME]
287 if Cnf.has_key("Queue-Report::Options::New"):
293 have_note += (d.has_key("process-new note"))
294 per_source[source]["oldest"] = oldest
296 per_source[source]["note_state"] = 0; # none
297 elif have_note < len(source_list):
298 per_source[source]["note_state"] = 1; # some
300 per_source[source]["note_state"] = 2; # all
301 per_source_items = per_source.items()
302 per_source_items.sort(sg_compare)
312 for i in per_source_items:
313 last_modified = time.time()-i[1]["oldest"]
314 source = i[1]["list"][0]["source"]
315 if len(source) > max_source_len:
316 max_source_len = len(source)
319 for j in i[1]["list"]:
320 if Cnf.has_key("Queue-Report::Options::New"):
322 (maintainer["maintainer822"], maintainer["maintainer2047"],
323 maintainer["maintainername"], maintainer["maintaineremail"]) = \
324 utils.fix_maintainer (j["maintainer"])
325 except utils.ParseMaintError, msg:
326 print "Problems while parsing maintainer address\n"
327 maintainer["maintainername"] = "Unknown"
328 maintainer["maintaineremail"] = "Unknown"
329 maint="%s:%s" % (maintainer["maintainername"], maintainer["maintaineremail"])
330 distribution=j["distribution"].keys()
331 closes=j["closes"].keys()
332 for arch in j["architecture"].keys():
334 version = j["version"]
335 versions[version] = ""
336 arches_list = arches.keys()
337 arches_list.sort(utils.arch_compare_sw)
338 arch_list = " ".join(arches_list)
339 version_list = " ".join(versions.keys())
340 if len(version_list) > max_version_len:
341 max_version_len = len(version_list)
342 if len(arch_list) > max_arch_len:
343 max_arch_len = len(arch_list)
344 if i[1]["note_state"]:
348 entries.append([source, version_list, arch_list, note, last_modified, maint, distribution, closes])
350 # direction entry consists of "Which field, which direction, time-consider" where
351 # time-consider says how we should treat last_modified. Thats all.
353 # Look for the options for sort and then do the sort.
355 if Cnf.has_key("Queue-Report::Options::Age"):
356 age = Cnf["Queue-Report::Options::Age"]
357 if Cnf.has_key("Queue-Report::Options::New"):
358 # If we produce html we always have oldest first.
359 direction.append([4,-1,"ao"])
361 if Cnf.has_key("Queue-Report::Options::Sort"):
362 for i in Cnf["Queue-Report::Options::Sort"].split(","):
365 direction.append([4,-1,age])
368 direction.append([4,1,age])
371 direction.append([0,1,0])
374 direction.append([0,-1,0])
377 direction.append([3,1,0])
380 direction.append([3,-1,0])
381 entries.sort(lambda x, y: sortfunc(x, y))
382 # Yes, in theory you can add several sort options at the commandline with. But my mind is to small
383 # at the moment to come up with a real good sorting function that considers all the sidesteps you
384 # have with it. (If you combine options it will simply take the last one at the moment).
385 # Will be enhanced in the future.
387 if Cnf.has_key("Queue-Report::Options::New"):
388 direction.append([4,1,"ao"])
389 entries.sort(lambda x, y: sortfunc(x, y))
390 # Output for a html file. First table header. then table_footer.
391 # Any line between them is then a <tr> printed from subroutine table_row.
393 table_header(type.upper())
394 for entry in entries:
395 (source, version_list, arch_list, note, last_modified, maint, distribution, closes) = entry
396 table_row(source, version_list, arch_list, time_pp(last_modified), maint, distribution, closes)
397 total_count = len(changes_files)
398 source_count = len(per_source_items)
399 table_footer(type.upper(), source_count, total_count)
401 # The "normal" output without any formatting.
402 format="%%-%ds | %%-%ds | %%-%ds%%s | %%s old\n" % (max_source_len, max_version_len, max_arch_len)
405 for entry in entries:
406 (source, version_list, arch_list, note, last_modified, undef, undef, undef) = entry
407 msg += format % (source, version_list, arch_list, note, time_pp(last_modified))
410 total_count = len(changes_files)
411 source_count = len(per_source_items)
416 print "%s %s source package%s / %s %s package%s in total." % (source_count, type, plural(source_count), total_count, type, plural(total_count))
420 ################################################################################
425 Cnf = utils.get_conf()
426 Arguments = [('h',"help","Queue-Report::Options::Help"),
427 ('n',"new","Queue-Report::Options::New"),
428 ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
429 ('a',"age","Queue-Report::Options::Age", "HasArg")]
431 if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
432 Cnf["Queue-Report::Options::%s" % (i)] = ""
434 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
436 Options = Cnf.SubTree("Queue-Report::Options")
440 Upload = queue.Upload(Cnf)
442 if Cnf.has_key("Queue-Report::Options::New"):
445 directories = Cnf.ValueList("Queue-Report::Directories")
447 directories = [ "byhand", "new" ]
449 for directory in directories:
450 changes_files = glob.glob("%s/*.changes" % (Cnf["Dir::Queue::%s" % (directory)]))
451 process_changes_files(changes_files, directory)
453 if Cnf.has_key("Queue-Report::Options::New"):
456 ################################################################################
458 if __name__ == '__main__':