]> git.decadent.org.uk Git - dak.git/blob - dak/queue_report.py
Merge remote-tracking branch 'drkranz/misc' into merge
[dak.git] / dak / queue_report.py
1 #!/usr/bin/env python
2
3 """ Produces a report on NEW and BYHAND packages """
4 # Copyright (C) 2001, 2002, 2003, 2005, 2006  James Troup <james@nocrew.org>
5
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.
10
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.
15
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
19
20 ################################################################################
21
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....
29 # <o-o> grr s/the/to/
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?
34
35 ################################################################################
36
37 from copy import copy
38 import glob, os, stat, sys, time
39 import apt_pkg
40 try:
41     import rrdtool
42 except ImportError:
43     pass
44
45 from daklib import utils
46 from daklib.queue import Upload
47 from daklib.dbconn import DBConn, has_new_comment, DBChange, DBSource, \
48                           get_uid_from_fingerprint, get_policy_queue
49 from daklib.textutils import fix_maintainer
50 from daklib.dak_exceptions import *
51
52 Cnf = None
53 direction = []
54 row_number = 0
55
56 ################################################################################
57
58 def usage(exit_code=0):
59     print """Usage: dak queue-report
60 Prints a report of packages in queues (usually new and byhand).
61
62   -h, --help                show this help and exit.
63   -8, --822                 writes 822 formated output to the location set in dak.conf
64   -n, --new                 produce html-output
65   -s, --sort=key            sort output according to key, see below.
66   -a, --age=key             if using sort by age, how should time be treated?
67                             If not given a default of hours will be used.
68   -r, --rrd=key             Directory where rrd files to be updated are stored
69   -d, --directories=key     A comma seperated list of queues to be scanned
70
71      Sorting Keys: ao=age,   oldest first.   an=age,   newest first.
72                    na=name,  ascending       nd=name,  descending
73                    nf=notes, first           nl=notes, last
74
75      Age Keys: m=minutes, h=hours, d=days, w=weeks, o=months, y=years
76
77 """
78     sys.exit(exit_code)
79
80 ################################################################################
81
82 def plural(x):
83     if x > 1:
84         return "s"
85     else:
86         return ""
87
88 ################################################################################
89
90 def time_pp(x):
91     if x < 60:
92         unit="second"
93     elif x < 3600:
94         x /= 60
95         unit="minute"
96     elif x < 86400:
97         x /= 3600
98         unit="hour"
99     elif x < 604800:
100         x /= 86400
101         unit="day"
102     elif x < 2419200:
103         x /= 604800
104         unit="week"
105     elif x < 29030400:
106         x /= 2419200
107         unit="month"
108     else:
109         x /= 29030400
110         unit="year"
111     x = int(x)
112     return "%s %s%s" % (x, unit, plural(x))
113
114 ################################################################################
115
116 def sg_compare (a, b):
117     a = a[1]
118     b = b[1]
119     """Sort by have note, time of oldest upload."""
120     # Sort by have note
121     a_note_state = a["note_state"]
122     b_note_state = b["note_state"]
123     if a_note_state < b_note_state:
124         return -1
125     elif a_note_state > b_note_state:
126         return 1
127
128     # Sort by time of oldest upload
129     return cmp(a["oldest"], b["oldest"])
130
131 ############################################################
132
133 def sortfunc(a,b):
134     for sorting in direction:
135         (sortkey, way, time) = sorting
136         ret = 0
137         if time == "m":
138             x=int(a[sortkey]/60)
139             y=int(b[sortkey]/60)
140         elif time == "h":
141             x=int(a[sortkey]/3600)
142             y=int(b[sortkey]/3600)
143         elif time == "d":
144             x=int(a[sortkey]/86400)
145             y=int(b[sortkey]/86400)
146         elif time == "w":
147             x=int(a[sortkey]/604800)
148             y=int(b[sortkey]/604800)
149         elif time == "o":
150             x=int(a[sortkey]/2419200)
151             y=int(b[sortkey]/2419200)
152         elif time == "y":
153             x=int(a[sortkey]/29030400)
154             y=int(b[sortkey]/29030400)
155         else:
156             x=a[sortkey]
157             y=b[sortkey]
158         if x < y:
159             ret = -1
160         elif x > y:
161             ret = 1
162         if ret != 0:
163             if way < 0:
164                 ret = ret*-1
165             return ret
166     return 0
167
168 ############################################################
169
170 def header():
171     print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
172 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
173 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
174   <head>
175     <meta http-equiv="content-type" content="text/xhtml+xml; charset=utf-8" />
176     <link type="text/css" rel="stylesheet" href="style.css" />
177     <link rel="shortcut icon" href="http://www.debian.org/favicon.ico" />
178     <title>
179       Debian NEW and BYHAND Packages
180     </title>
181     <script type="text/javascript">
182     function togglePkg() {
183         var children = document.getElementsByTagName("*");
184         for (var i = 0; i < children.length; i++) {
185             if(!children[i].hasAttribute("class"))
186                 continue;
187             c = children[i].getAttribute("class").split(" ");
188             for(var j = 0; j < c.length; j++) {
189                 if(c[j] == "binNEW") {
190                     if (children[i].style.display == '')
191                         children[i].style.display = 'none';
192                     else children[i].style.display = '';
193                 }
194             }
195         }
196     }
197     </script>
198   </head>
199   <body id="NEW">
200     <div id="logo">
201       <a href="http://www.debian.org/">
202         <img src="http://www.debian.org/logos/openlogo-nd-50.png"
203         alt="debian logo" /></a>
204       <a href="http://www.debian.org/">
205         <img src="http://www.debian.org/Pics/debian.png"
206         alt="Debian Project" /></a>
207     </div>
208     <div id="titleblock">
209
210       <img src="http://www.debian.org/Pics/red-upperleft.png"
211       id="red-upperleft" alt="corner image"/>
212       <img src="http://www.debian.org/Pics/red-lowerleft.png"
213       id="red-lowerleft" alt="corner image"/>
214       <img src="http://www.debian.org/Pics/red-upperright.png"
215       id="red-upperright" alt="corner image"/>
216       <img src="http://www.debian.org/Pics/red-lowerright.png"
217       id="red-lowerright" alt="corner image"/>
218       <span class="title">
219         Debian NEW and BYHAND Packages
220       </span>
221     </div>
222     """
223
224 def footer():
225     print "<p class=\"timestamp\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
226     print "<p class=\"timestamp\">There are <a href=\"/stat.html\">graphs about the queues</a> available.</p>"
227
228     print """
229     <div class="footer">
230     <p>Hint: Age is the youngest upload of the package, if there is more than
231     one version.<br />
232     You may want to look at <a href="http://ftp-master.debian.org/REJECT-FAQ.html">the REJECT-FAQ</a>
233       for possible reasons why one of the above packages may get rejected.</p>
234       <p>
235       <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10"
236         alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
237       <a href="http://jigsaw.w3.org/css-validator/">
238         <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss"
239         alt="Valid CSS!" />
240       </a>
241       </p>
242     </div> </body> </html>
243     """
244
245 def table_header(type, source_count, total_count):
246     print "<h1 class='binNEW'>Summary for: %s</h1>" % (type)
247     print "<h1 class='binNEW' style='display: none'>Summary for: binary-%s only</h1>" % (type)
248     print """
249     <table class="NEW">
250       <p class="togglepkg" onclick="togglePkg()">Click to toggle all/binary-NEW packages</p>
251       <caption class="binNEW">
252     """
253     print "Package count in <strong>%s</strong>: <em>%s</em>&nbsp;|&nbsp; Total Package count: <em>%s</em>" % (type, source_count, total_count)
254     print """
255       </caption>
256       <thead>
257         <tr>
258           <th>Package</th>
259           <th>Version</th>
260           <th>Arch</th>
261           <th>Distribution</th>
262           <th>Age</th>
263           <th>Upload info</th>
264           <th>Closes</th>
265         </tr>
266       </thead>
267       <tbody>
268     """
269
270 def table_footer(type):
271     print "</tbody></table>"
272
273
274 def table_row(source, version, arch, last_mod, maint, distribution, closes, fingerprint, sponsor, changedby):
275
276     global row_number
277
278     trclass = "sid"
279     session = DBConn().session()
280     for dist in distribution:
281         if dist == "experimental":
282             trclass = "exp"
283
284     if not len(session.query(DBSource).filter_by(source = source).all()):
285         trclass += " binNEW"
286     session.commit()
287
288     if row_number % 2 != 0:
289         print "<tr class=\"%s even\">" % (trclass)
290     else:
291         print "<tr class=\"%s odd\">" % (trclass)
292
293     print "<td class=\"package\">%s</td>" % (source)
294     print "<td class=\"version\">"
295     for vers in version.split():
296         print "<a href=\"new/%s_%s.html\">%s</a><br/>" % (source, utils.html_escape(vers), utils.html_escape(vers))
297     print "</td>"
298     print "<td class=\"arch\">%s</td>" % (arch)
299     print "<td class=\"distribution\">"
300     for dist in distribution:
301         print "%s<br/>" % (dist)
302     print "</td>"
303     print "<td class=\"age\">%s</td>" % (last_mod)
304     (name, mail) = maint.split(":", 1)
305
306     print "<td class=\"upload-data\">"
307     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))
308     (name, mail) = changedby.split(":", 1)
309     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))
310
311     if sponsor:
312         try:
313             (login, domain) = sponsor.split("@", 1)
314             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))
315         except Exception as e:
316             pass
317
318     print "<span class=\"signature\">Fingerprint: %s</span>" % (fingerprint)
319     print "</td>"
320
321     print "<td class=\"closes\">"
322     for close in closes:
323         print "<a href=\"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s\">#%s</a><br/>" % (utils.html_escape(close), utils.html_escape(close))
324     print "</td></tr>"
325     row_number+=1
326
327 ############################################################
328
329 def update_graph_database(rrd_dir, type, n_source, n_binary):
330     if not rrd_dir:
331         return
332
333     rrd_file = os.path.join(rrd_dir, type.lower()+'.rrd')
334     update = [rrd_file, "N:%s:%s" % (n_source, n_binary)]
335
336     try:
337         rrdtool.update(*update)
338     except rrdtool.error:
339         create = [rrd_file]+"""
340 --step
341 300
342 --start
343 0
344 DS:ds0:GAUGE:7200:0:1000
345 DS:ds1:GAUGE:7200:0:1000
346 RRA:AVERAGE:0.5:1:599
347 RRA:AVERAGE:0.5:6:700
348 RRA:AVERAGE:0.5:24:775
349 RRA:AVERAGE:0.5:288:795
350 RRA:MAX:0.5:1:600
351 RRA:MAX:0.5:6:700
352 RRA:MAX:0.5:24:775
353 RRA:MAX:0.5:288:795
354 """.strip().split("\n")
355         try:
356             rc = rrdtool.create(*create)
357             ru = rrdtool.update(*update)
358         except rrdtool.error as e:
359             print('warning: queue_report: rrdtool error, skipping %s.rrd: %s' % (type, e))
360     except NameError:
361         pass
362
363 ############################################################
364
365 def process_changes_files(changes_files, type, log, rrd_dir):
366     msg = ""
367     cache = {}
368     # Read in all the .changes files
369     for filename in changes_files:
370         try:
371             u = Upload()
372             u.load_changes(filename)
373             cache[filename] = copy(u.pkg.changes)
374             cache[filename]["filename"] = filename
375         except Exception as e:
376             print "WARNING: Exception %s" % e
377             continue
378     # Divide the .changes into per-source groups
379     per_source = {}
380     for filename in cache.keys():
381         source = cache[filename]["source"]
382         if not per_source.has_key(source):
383             per_source[source] = {}
384             per_source[source]["list"] = []
385         per_source[source]["list"].append(cache[filename])
386     # Determine oldest time and have note status for each source group
387     for source in per_source.keys():
388         source_list = per_source[source]["list"]
389         first = source_list[0]
390         oldest = os.stat(first["filename"])[stat.ST_MTIME]
391         have_note = 0
392         for d in per_source[source]["list"]:
393             mtime = os.stat(d["filename"])[stat.ST_MTIME]
394             if Cnf.has_key("Queue-Report::Options::New"):
395                 if mtime > oldest:
396                     oldest = mtime
397             else:
398                 if mtime < oldest:
399                     oldest = mtime
400             have_note += has_new_comment(d["source"], d["version"])
401         per_source[source]["oldest"] = oldest
402         if not have_note:
403             per_source[source]["note_state"] = 0; # none
404         elif have_note < len(source_list):
405             per_source[source]["note_state"] = 1; # some
406         else:
407             per_source[source]["note_state"] = 2; # all
408     per_source_items = per_source.items()
409     per_source_items.sort(sg_compare)
410
411     update_graph_database(rrd_dir, type, len(per_source_items), len(changes_files))
412
413     entries = []
414     max_source_len = 0
415     max_version_len = 0
416     max_arch_len = 0
417     for i in per_source_items:
418         maintainer = {}
419         maint=""
420         distribution=""
421         closes=""
422         fingerprint=""
423         changeby = {}
424         changedby=""
425         sponsor=""
426         filename=i[1]["list"][0]["filename"]
427         last_modified = time.time()-i[1]["oldest"]
428         source = i[1]["list"][0]["source"]
429         if len(source) > max_source_len:
430             max_source_len = len(source)
431         binary_list = i[1]["list"][0]["binary"].keys()
432         binary = ', '.join(binary_list)
433         arches = {}
434         versions = {}
435         for j in i[1]["list"]:
436             changesbase = os.path.basename(j["filename"])
437             try:
438                 session = DBConn().session()
439                 dbc = session.query(DBChange).filter_by(changesname=changesbase).one()
440                 session.close()
441             except Exception as e:
442                 print "Can't find changes file in NEW for %s (%s)" % (changesbase, e)
443                 dbc = None
444
445             if Cnf.has_key("Queue-Report::Options::New") or Cnf.has_key("Queue-Report::Options::822"):
446                 try:
447                     (maintainer["maintainer822"], maintainer["maintainer2047"],
448                     maintainer["maintainername"], maintainer["maintaineremail"]) = \
449                     fix_maintainer (j["maintainer"])
450                 except ParseMaintError as msg:
451                     print "Problems while parsing maintainer address\n"
452                     maintainer["maintainername"] = "Unknown"
453                     maintainer["maintaineremail"] = "Unknown"
454                 maint="%s:%s" % (maintainer["maintainername"], maintainer["maintaineremail"])
455                 # ...likewise for the Changed-By: field if it exists.
456                 try:
457                     (changeby["changedby822"], changeby["changedby2047"],
458                      changeby["changedbyname"], changeby["changedbyemail"]) = \
459                      fix_maintainer (j["changed-by"])
460                 except ParseMaintError as msg:
461                     (changeby["changedby822"], changeby["changedby2047"],
462                      changeby["changedbyname"], changeby["changedbyemail"]) = \
463                      ("", "", "", "")
464                 changedby="%s:%s" % (changeby["changedbyname"], changeby["changedbyemail"])
465
466                 distribution=j["distribution"].keys()
467                 closes=j["closes"].keys()
468                 if dbc:
469                     fingerprint = dbc.fingerprint
470                     sponsor_name = get_uid_from_fingerprint(fingerprint).name
471                     sponsor_email = get_uid_from_fingerprint(fingerprint).uid + "@debian.org"
472                     if sponsor_name != maintainer["maintainername"] and sponsor_name != changeby["changedbyname"] and \
473                     sponsor_email != maintainer["maintaineremail"] and sponsor_name != changeby["changedbyemail"]:
474                         sponsor = sponsor_email
475
476             for arch in j["architecture"].keys():
477                 arches[arch] = ""
478             version = j["version"]
479             versions[version] = ""
480         arches_list = arches.keys()
481         arches_list.sort(utils.arch_compare_sw)
482         arch_list = " ".join(arches_list)
483         version_list = " ".join(versions.keys())
484         if len(version_list) > max_version_len:
485             max_version_len = len(version_list)
486         if len(arch_list) > max_arch_len:
487             max_arch_len = len(arch_list)
488         if i[1]["note_state"]:
489             note = " | [N]"
490         else:
491             note = ""
492         entries.append([source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, filename])
493
494     # direction entry consists of "Which field, which direction, time-consider" where
495     # time-consider says how we should treat last_modified. Thats all.
496
497     # Look for the options for sort and then do the sort.
498     age = "h"
499     if Cnf.has_key("Queue-Report::Options::Age"):
500         age =  Cnf["Queue-Report::Options::Age"]
501     if Cnf.has_key("Queue-Report::Options::New"):
502     # If we produce html we always have oldest first.
503         direction.append([5,-1,"ao"])
504     else:
505         if Cnf.has_key("Queue-Report::Options::Sort"):
506             for i in Cnf["Queue-Report::Options::Sort"].split(","):
507                 if i == "ao":
508                     # Age, oldest first.
509                     direction.append([5,-1,age])
510                 elif i == "an":
511                     # Age, newest first.
512                     direction.append([5,1,age])
513                 elif i == "na":
514                     # Name, Ascending.
515                     direction.append([0,1,0])
516                 elif i == "nd":
517                     # Name, Descending.
518                     direction.append([0,-1,0])
519                 elif i == "nl":
520                     # Notes last.
521                     direction.append([4,1,0])
522                 elif i == "nf":
523                     # Notes first.
524                     direction.append([4,-1,0])
525     entries.sort(lambda x, y: sortfunc(x, y))
526     # Yes, in theory you can add several sort options at the commandline with. But my mind is to small
527     # at the moment to come up with a real good sorting function that considers all the sidesteps you
528     # have with it. (If you combine options it will simply take the last one at the moment).
529     # Will be enhanced in the future.
530
531     if Cnf.has_key("Queue-Report::Options::822"):
532         # print stuff out in 822 format
533         for entry in entries:
534             (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, changes_file) = entry
535
536             # We'll always have Source, Version, Arch, Mantainer, and Dist
537             # For the rest, check to see if we have them, then print them out
538             log.write("Source: " + source + "\n")
539             log.write("Binary: " + binary + "\n")
540             log.write("Version: " + version_list + "\n")
541             log.write("Architectures: ")
542             log.write( (", ".join(arch_list.split(" "))) + "\n")
543             log.write("Age: " + time_pp(last_modified) + "\n")
544             log.write("Last-Modified: " + str(int(time.time()) - int(last_modified)) + "\n")
545             log.write("Queue: " + type + "\n")
546
547             (name, mail) = maint.split(":", 1)
548             log.write("Maintainer: " + name + " <"+mail+">" + "\n")
549             if changedby:
550                (name, mail) = changedby.split(":", 1)
551                log.write("Changed-By: " + name + " <"+mail+">" + "\n")
552             if sponsor:
553                log.write("Sponsored-By: " + "@".join(sponsor.split("@")[:2]) + "\n")
554             log.write("Distribution:")
555             for dist in distribution:
556                log.write(" " + dist)
557             log.write("\n")
558             log.write("Fingerprint: " + fingerprint + "\n")
559             if closes:
560                 bug_string = ""
561                 for bugs in closes:
562                     bug_string += "#"+bugs+", "
563                 log.write("Closes: " + bug_string[:-2] + "\n")
564             log.write("Changes-File: " + os.path.basename(changes_file) + "\n")
565             log.write("\n")
566
567     if Cnf.has_key("Queue-Report::Options::New"):
568         direction.append([5,1,"ao"])
569         entries.sort(lambda x, y: sortfunc(x, y))
570     # Output for a html file. First table header. then table_footer.
571     # Any line between them is then a <tr> printed from subroutine table_row.
572         if len(entries) > 0:
573             total_count = len(changes_files)
574             source_count = len(per_source_items)
575             table_header(type.upper(), source_count, total_count)
576             for entry in entries:
577                 (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, undef) = entry
578                 table_row(source, version_list, arch_list, time_pp(last_modified), maint, distribution, closes, fingerprint, sponsor, changedby)
579             table_footer(type.upper())
580     elif not Cnf.has_key("Queue-Report::Options::822"):
581     # The "normal" output without any formatting.
582         format="%%-%ds | %%-%ds | %%-%ds%%s | %%s old\n" % (max_source_len, max_version_len, max_arch_len)
583
584         msg = ""
585         for entry in entries:
586             (source, binary, version_list, arch_list, note, last_modified, undef, undef, undef, undef, undef, undef, undef) = entry
587             msg += format % (source, version_list, arch_list, note, time_pp(last_modified))
588
589         if msg:
590             total_count = len(changes_files)
591             source_count = len(per_source_items)
592             print type.upper()
593             print "-"*len(type)
594             print
595             print msg
596             print "%s %s source package%s / %s %s package%s in total." % (source_count, type, plural(source_count), total_count, type, plural(total_count))
597             print
598
599
600 ################################################################################
601
602 def main():
603     global Cnf
604
605     Cnf = utils.get_conf()
606     Arguments = [('h',"help","Queue-Report::Options::Help"),
607                  ('n',"new","Queue-Report::Options::New"),
608                  ('8','822',"Queue-Report::Options::822"),
609                  ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
610                  ('a',"age","Queue-Report::Options::Age", "HasArg"),
611                  ('r',"rrd","Queue-Report::Options::Rrd", "HasArg"),
612                  ('d',"directories","Queue-Report::Options::Directories", "HasArg")]
613     for i in [ "help" ]:
614         if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
615             Cnf["Queue-Report::Options::%s" % (i)] = ""
616
617     apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
618
619     Options = Cnf.SubTree("Queue-Report::Options")
620     if Options["Help"]:
621         usage()
622
623     if Cnf.has_key("Queue-Report::Options::New"):
624         header()
625
626     # Initialize db so we can get the NEW comments
627     dbconn = DBConn()
628
629     queue_names = [ ]
630
631     if Cnf.has_key("Queue-Report::Options::Directories"):
632         for i in Cnf["Queue-Report::Options::Directories"].split(","):
633             queue_names.append(i)
634     elif Cnf.has_key("Queue-Report::Directories"):
635         queue_names = Cnf.ValueList("Queue-Report::Directories")
636     else:
637         queue_names = [ "byhand", "new" ]
638
639     if Cnf.has_key("Queue-Report::Options::Rrd"):
640         rrd_dir = Cnf["Queue-Report::Options::Rrd"]
641     elif Cnf.has_key("Dir::Rrd"):
642         rrd_dir = Cnf["Dir::Rrd"]
643     else:
644         rrd_dir = None
645
646     f = None
647     if Cnf.has_key("Queue-Report::Options::822"):
648         # Open the report file
649         f = open(Cnf["Queue-Report::ReportLocations::822Location"], "w")
650
651     session = dbconn.session()
652
653     for queue_name in queue_names:
654         queue = get_policy_queue(queue_name, session)
655         if queue:
656             directory = os.path.abspath(queue.path)
657             changes_files = glob.glob("%s/*.changes" % (directory))
658             process_changes_files(changes_files, os.path.basename(directory), f, rrd_dir)
659         else:
660             utils.warn("Cannot find queue %s" % queue_name)
661
662     if Cnf.has_key("Queue-Report::Options::822"):
663         f.close()
664
665     if Cnf.has_key("Queue-Report::Options::New"):
666         footer()
667
668 ################################################################################
669
670 if __name__ == '__main__':
671     main()