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