]> git.decadent.org.uk Git - dak.git/blob - dak/queue_report.py
Merge remote-tracking branch 'ansgar/pu/wheezy' 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     //<![CDATA[
183     function togglePkg() {
184         var children = document.getElementsByTagName("*");
185         for (var i = 0; i < children.length; i++) {
186             if(!children[i].hasAttribute("class"))
187                 continue;
188             c = children[i].getAttribute("class").split(" ");
189             for(var j = 0; j < c.length; j++) {
190                 if(c[j] == "binNEW") {
191                     if (children[i].style.display == '')
192                         children[i].style.display = 'none';
193                     else children[i].style.display = '';
194                 }
195             }
196         }
197     }
198     //]]>
199     </script>
200   </head>
201   <body id="NEW">
202     <div id="logo">
203       <a href="http://www.debian.org/">
204         <img src="http://www.debian.org/logos/openlogo-nd-50.png"
205         alt="debian logo" /></a>
206       <a href="http://www.debian.org/">
207         <img src="http://www.debian.org/Pics/debian.png"
208         alt="Debian Project" /></a>
209     </div>
210     <div id="titleblock">
211
212       <img src="http://www.debian.org/Pics/red-upperleft.png"
213       id="red-upperleft" alt="corner image"/>
214       <img src="http://www.debian.org/Pics/red-lowerleft.png"
215       id="red-lowerleft" alt="corner image"/>
216       <img src="http://www.debian.org/Pics/red-upperright.png"
217       id="red-upperright" alt="corner image"/>
218       <img src="http://www.debian.org/Pics/red-lowerright.png"
219       id="red-lowerright" alt="corner image"/>
220       <span class="title">
221         Debian NEW and BYHAND Packages
222       </span>
223     </div>
224     """
225
226 def footer():
227     print "<p class=\"timestamp\">Timestamp: %s (UTC)</p>" % (time.strftime("%d.%m.%Y / %H:%M:%S", time.gmtime()))
228     print "<p class=\"timestamp\">There are <a href=\"/stat.html\">graphs about the queues</a> available.</p>"
229
230     print """
231     <div class="footer">
232     <p>Hint: Age is the youngest upload of the package, if there is more than
233     one version.<br />
234     You may want to look at <a href="http://ftp-master.debian.org/REJECT-FAQ.html">the REJECT-FAQ</a>
235       for possible reasons why one of the above packages may get rejected.</p>
236       <p>
237       <a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10"
238         alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
239       <a href="http://jigsaw.w3.org/css-validator/">
240         <img style="border:0;width:88px;height:31px" src="http://jigsaw.w3.org/css-validator/images/vcss"
241         alt="Valid CSS!" />
242       </a>
243       </p>
244     </div> </body> </html>
245     """
246
247 def table_header(type, source_count, total_count):
248     print "<h1 class='binNEW'>Summary for: %s</h1>" % (type)
249     print "<h1 class='binNEW' style='display: none'>Summary for: binary-%s only</h1>" % (type)
250     print """
251     <p class="togglepkg" onclick="togglePkg()">Click to toggle all/binary-NEW packages</p>
252     <table class="NEW">
253       <caption class="binNEW">
254     """
255     print "Package count in <strong>%s</strong>: <em>%s</em>&nbsp;|&nbsp; Total Package count: <em>%s</em>" % (type, source_count, total_count)
256     print """
257       </caption>
258       <thead>
259         <tr>
260           <th>Package</th>
261           <th>Version</th>
262           <th>Arch</th>
263           <th>Distribution</th>
264           <th>Age</th>
265           <th>Upload info</th>
266           <th>Closes</th>
267         </tr>
268       </thead>
269       <tbody>
270     """
271
272 def table_footer(type):
273     print "</tbody></table>"
274
275
276 def table_row(source, version, arch, last_mod, maint, distribution, closes, fingerprint, sponsor, changedby):
277
278     global row_number
279
280     trclass = "sid"
281     session = DBConn().session()
282     for dist in distribution:
283         if dist == "experimental":
284             trclass = "exp"
285
286     if not len(session.query(DBSource).filter_by(source = source).all()):
287         trclass += " binNEW"
288     session.commit()
289
290     if row_number % 2 != 0:
291         print "<tr class=\"%s even\">" % (trclass)
292     else:
293         print "<tr class=\"%s odd\">" % (trclass)
294
295     if "binNEW" in trclass:
296         print "<td class=\"package\">%s</td>" % (source)
297     else:
298         print "<td class=\"package\"><a href=\"http://packages.qa.debian.org/%(source)s\">%(source)s</a></td>" % {'source': source}
299     print "<td class=\"version\">"
300     for vers in version.split():
301         print "<a href=\"new/%s_%s.html\">%s</a><br/>" % (source, utils.html_escape(vers), utils.html_escape(vers))
302     print "</td>"
303     print "<td class=\"arch\">%s</td>" % (arch)
304     print "<td class=\"distribution\">"
305     for dist in distribution:
306         print "%s<br/>" % (dist)
307     print "</td>"
308     print "<td class=\"age\">%s</td>" % (last_mod)
309     (name, mail) = maint.split(":", 1)
310
311     print "<td class=\"upload-data\">"
312     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))
313     (name, mail) = changedby.split(":", 1)
314     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))
315
316     if sponsor:
317         try:
318             (login, domain) = sponsor.split("@", 1)
319             print "<span class=\"sponsor\">Sponsor: <a href=\"http://qa.debian.org/developer.php?login=%s\">%s</a>@debian.org</span><br/>" % (utils.html_escape(login), utils.html_escape(login))
320         except Exception as e:
321             pass
322
323     print "<span class=\"signature\">Fingerprint: %s</span>" % (fingerprint)
324     print "</td>"
325
326     print "<td class=\"closes\">"
327     for close in closes:
328         print "<a href=\"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s\">#%s</a><br/>" % (utils.html_escape(close), utils.html_escape(close))
329     print "</td></tr>"
330     row_number+=1
331
332 ############################################################
333
334 def update_graph_database(rrd_dir, type, n_source, n_binary):
335     if not rrd_dir:
336         return
337
338     rrd_file = os.path.join(rrd_dir, type.lower()+'.rrd')
339     update = [rrd_file, "N:%s:%s" % (n_source, n_binary)]
340
341     try:
342         rrdtool.update(*update)
343     except rrdtool.error:
344         create = [rrd_file]+"""
345 --step
346 300
347 --start
348 0
349 DS:ds0:GAUGE:7200:0:1000
350 DS:ds1:GAUGE:7200:0:1000
351 RRA:AVERAGE:0.5:1:599
352 RRA:AVERAGE:0.5:6:700
353 RRA:AVERAGE:0.5:24:775
354 RRA:AVERAGE:0.5:288:795
355 RRA:MAX:0.5:1:600
356 RRA:MAX:0.5:6:700
357 RRA:MAX:0.5:24:775
358 RRA:MAX:0.5:288:795
359 """.strip().split("\n")
360         try:
361             rc = rrdtool.create(*create)
362             ru = rrdtool.update(*update)
363         except rrdtool.error as e:
364             print('warning: queue_report: rrdtool error, skipping %s.rrd: %s' % (type, e))
365     except NameError:
366         pass
367
368 ############################################################
369
370 def process_changes_files(changes_files, type, log, rrd_dir):
371     msg = ""
372     cache = {}
373     # Read in all the .changes files
374     for filename in changes_files:
375         try:
376             u = Upload()
377             u.load_changes(filename)
378             cache[filename] = copy(u.pkg.changes)
379             cache[filename]["filename"] = filename
380         except Exception as e:
381             print "WARNING: Exception %s" % e
382             continue
383     # Divide the .changes into per-source groups
384     per_source = {}
385     for filename in cache.keys():
386         source = cache[filename]["source"]
387         if not per_source.has_key(source):
388             per_source[source] = {}
389             per_source[source]["list"] = []
390         per_source[source]["list"].append(cache[filename])
391     # Determine oldest time and have note status for each source group
392     for source in per_source.keys():
393         source_list = per_source[source]["list"]
394         first = source_list[0]
395         oldest = os.stat(first["filename"])[stat.ST_MTIME]
396         have_note = 0
397         for d in per_source[source]["list"]:
398             mtime = os.stat(d["filename"])[stat.ST_MTIME]
399             if Cnf.has_key("Queue-Report::Options::New"):
400                 if mtime > oldest:
401                     oldest = mtime
402             else:
403                 if mtime < oldest:
404                     oldest = mtime
405             have_note += has_new_comment(d["source"], d["version"])
406         per_source[source]["oldest"] = oldest
407         if not have_note:
408             per_source[source]["note_state"] = 0; # none
409         elif have_note < len(source_list):
410             per_source[source]["note_state"] = 1; # some
411         else:
412             per_source[source]["note_state"] = 2; # all
413     per_source_items = per_source.items()
414     per_source_items.sort(sg_compare)
415
416     update_graph_database(rrd_dir, type, len(per_source_items), len(changes_files))
417
418     entries = []
419     max_source_len = 0
420     max_version_len = 0
421     max_arch_len = 0
422     for i in per_source_items:
423         maintainer = {}
424         maint=""
425         distribution=""
426         closes=""
427         fingerprint=""
428         changeby = {}
429         changedby=""
430         sponsor=""
431         filename=i[1]["list"][0]["filename"]
432         last_modified = time.time()-i[1]["oldest"]
433         source = i[1]["list"][0]["source"]
434         if len(source) > max_source_len:
435             max_source_len = len(source)
436         binary_list = i[1]["list"][0]["binary"].keys()
437         binary = ', '.join(binary_list)
438         arches = {}
439         versions = {}
440         for j in i[1]["list"]:
441             changesbase = os.path.basename(j["filename"])
442             try:
443                 session = DBConn().session()
444                 dbc = session.query(DBChange).filter_by(changesname=changesbase).one()
445                 session.close()
446             except Exception as e:
447                 print "Can't find changes file in NEW for %s (%s)" % (changesbase, e)
448                 dbc = None
449
450             if Cnf.has_key("Queue-Report::Options::New") or Cnf.has_key("Queue-Report::Options::822"):
451                 try:
452                     (maintainer["maintainer822"], maintainer["maintainer2047"],
453                     maintainer["maintainername"], maintainer["maintaineremail"]) = \
454                     fix_maintainer (j["maintainer"])
455                 except ParseMaintError as msg:
456                     print "Problems while parsing maintainer address\n"
457                     maintainer["maintainername"] = "Unknown"
458                     maintainer["maintaineremail"] = "Unknown"
459                 maint="%s:%s" % (maintainer["maintainername"], maintainer["maintaineremail"])
460                 # ...likewise for the Changed-By: field if it exists.
461                 try:
462                     (changeby["changedby822"], changeby["changedby2047"],
463                      changeby["changedbyname"], changeby["changedbyemail"]) = \
464                      fix_maintainer (j["changed-by"])
465                 except ParseMaintError as msg:
466                     (changeby["changedby822"], changeby["changedby2047"],
467                      changeby["changedbyname"], changeby["changedbyemail"]) = \
468                      ("", "", "", "")
469                 changedby="%s:%s" % (changeby["changedbyname"], changeby["changedbyemail"])
470
471                 distribution=j["distribution"].keys()
472                 closes=j["closes"].keys()
473                 if dbc:
474                     fingerprint = dbc.fingerprint
475                     sponsor_name = get_uid_from_fingerprint(fingerprint).name
476                     sponsor_email = get_uid_from_fingerprint(fingerprint).uid + "@debian.org"
477                     if sponsor_name != maintainer["maintainername"] and sponsor_name != changeby["changedbyname"] and \
478                     sponsor_email != maintainer["maintaineremail"] and sponsor_name != changeby["changedbyemail"]:
479                         sponsor = sponsor_email
480
481             for arch in j["architecture"].keys():
482                 arches[arch] = ""
483             version = j["version"]
484             versions[version] = ""
485         arches_list = arches.keys()
486         arches_list.sort(utils.arch_compare_sw)
487         arch_list = " ".join(arches_list)
488         version_list = " ".join(versions.keys())
489         if len(version_list) > max_version_len:
490             max_version_len = len(version_list)
491         if len(arch_list) > max_arch_len:
492             max_arch_len = len(arch_list)
493         if i[1]["note_state"]:
494             note = " | [N]"
495         else:
496             note = ""
497         entries.append([source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, filename])
498
499     # direction entry consists of "Which field, which direction, time-consider" where
500     # time-consider says how we should treat last_modified. Thats all.
501
502     # Look for the options for sort and then do the sort.
503     age = "h"
504     if Cnf.has_key("Queue-Report::Options::Age"):
505         age =  Cnf["Queue-Report::Options::Age"]
506     if Cnf.has_key("Queue-Report::Options::New"):
507     # If we produce html we always have oldest first.
508         direction.append([5,-1,"ao"])
509     else:
510         if Cnf.has_key("Queue-Report::Options::Sort"):
511             for i in Cnf["Queue-Report::Options::Sort"].split(","):
512                 if i == "ao":
513                     # Age, oldest first.
514                     direction.append([5,-1,age])
515                 elif i == "an":
516                     # Age, newest first.
517                     direction.append([5,1,age])
518                 elif i == "na":
519                     # Name, Ascending.
520                     direction.append([0,1,0])
521                 elif i == "nd":
522                     # Name, Descending.
523                     direction.append([0,-1,0])
524                 elif i == "nl":
525                     # Notes last.
526                     direction.append([4,1,0])
527                 elif i == "nf":
528                     # Notes first.
529                     direction.append([4,-1,0])
530     entries.sort(lambda x, y: sortfunc(x, y))
531     # Yes, in theory you can add several sort options at the commandline with. But my mind is to small
532     # at the moment to come up with a real good sorting function that considers all the sidesteps you
533     # have with it. (If you combine options it will simply take the last one at the moment).
534     # Will be enhanced in the future.
535
536     if Cnf.has_key("Queue-Report::Options::822"):
537         # print stuff out in 822 format
538         for entry in entries:
539             (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, changes_file) = entry
540
541             # We'll always have Source, Version, Arch, Mantainer, and Dist
542             # For the rest, check to see if we have them, then print them out
543             log.write("Source: " + source + "\n")
544             log.write("Binary: " + binary + "\n")
545             log.write("Version: " + version_list + "\n")
546             log.write("Architectures: ")
547             log.write( (", ".join(arch_list.split(" "))) + "\n")
548             log.write("Age: " + time_pp(last_modified) + "\n")
549             log.write("Last-Modified: " + str(int(time.time()) - int(last_modified)) + "\n")
550             log.write("Queue: " + type + "\n")
551
552             (name, mail) = maint.split(":", 1)
553             log.write("Maintainer: " + name + " <"+mail+">" + "\n")
554             if changedby:
555                (name, mail) = changedby.split(":", 1)
556                log.write("Changed-By: " + name + " <"+mail+">" + "\n")
557             if sponsor:
558                log.write("Sponsored-By: " + "@".join(sponsor.split("@")[:2]) + "\n")
559             log.write("Distribution:")
560             for dist in distribution:
561                log.write(" " + dist)
562             log.write("\n")
563             log.write("Fingerprint: " + fingerprint + "\n")
564             if closes:
565                 bug_string = ""
566                 for bugs in closes:
567                     bug_string += "#"+bugs+", "
568                 log.write("Closes: " + bug_string[:-2] + "\n")
569             log.write("Changes-File: " + os.path.basename(changes_file) + "\n")
570             log.write("\n")
571
572     if Cnf.has_key("Queue-Report::Options::New"):
573         direction.append([5,1,"ao"])
574         entries.sort(lambda x, y: sortfunc(x, y))
575     # Output for a html file. First table header. then table_footer.
576     # Any line between them is then a <tr> printed from subroutine table_row.
577         if len(entries) > 0:
578             total_count = len(changes_files)
579             source_count = len(per_source_items)
580             table_header(type.upper(), source_count, total_count)
581             for entry in entries:
582                 (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, undef) = entry
583                 table_row(source, version_list, arch_list, time_pp(last_modified), maint, distribution, closes, fingerprint, sponsor, changedby)
584             table_footer(type.upper())
585     elif not Cnf.has_key("Queue-Report::Options::822"):
586     # The "normal" output without any formatting.
587         format="%%-%ds | %%-%ds | %%-%ds%%s | %%s old\n" % (max_source_len, max_version_len, max_arch_len)
588
589         msg = ""
590         for entry in entries:
591             (source, binary, version_list, arch_list, note, last_modified, undef, undef, undef, undef, undef, undef, undef) = entry
592             msg += format % (source, version_list, arch_list, note, time_pp(last_modified))
593
594         if msg:
595             total_count = len(changes_files)
596             source_count = len(per_source_items)
597             print type.upper()
598             print "-"*len(type)
599             print
600             print msg
601             print "%s %s source package%s / %s %s package%s in total." % (source_count, type, plural(source_count), total_count, type, plural(total_count))
602             print
603
604
605 ################################################################################
606
607 def main():
608     global Cnf
609
610     Cnf = utils.get_conf()
611     Arguments = [('h',"help","Queue-Report::Options::Help"),
612                  ('n',"new","Queue-Report::Options::New"),
613                  ('8','822',"Queue-Report::Options::822"),
614                  ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
615                  ('a',"age","Queue-Report::Options::Age", "HasArg"),
616                  ('r',"rrd","Queue-Report::Options::Rrd", "HasArg"),
617                  ('d',"directories","Queue-Report::Options::Directories", "HasArg")]
618     for i in [ "help" ]:
619         if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
620             Cnf["Queue-Report::Options::%s" % (i)] = ""
621
622     apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
623
624     Options = Cnf.subtree("Queue-Report::Options")
625     if Options["Help"]:
626         usage()
627
628     if Cnf.has_key("Queue-Report::Options::New"):
629         header()
630
631     # Initialize db so we can get the NEW comments
632     dbconn = DBConn()
633
634     queue_names = [ ]
635
636     if Cnf.has_key("Queue-Report::Options::Directories"):
637         for i in Cnf["Queue-Report::Options::Directories"].split(","):
638             queue_names.append(i)
639     elif Cnf.has_key("Queue-Report::Directories"):
640         queue_names = Cnf.value_list("Queue-Report::Directories")
641     else:
642         queue_names = [ "byhand", "new" ]
643
644     if Cnf.has_key("Queue-Report::Options::Rrd"):
645         rrd_dir = Cnf["Queue-Report::Options::Rrd"]
646     elif Cnf.has_key("Dir::Rrd"):
647         rrd_dir = Cnf["Dir::Rrd"]
648     else:
649         rrd_dir = None
650
651     f = None
652     if Cnf.has_key("Queue-Report::Options::822"):
653         # Open the report file
654         f = open(Cnf["Queue-Report::ReportLocations::822Location"], "w")
655
656     session = dbconn.session()
657
658     for queue_name in queue_names:
659         queue = get_policy_queue(queue_name, session)
660         if queue:
661             directory = os.path.abspath(queue.path)
662             changes_files = glob.glob("%s/*.changes" % (directory))
663             process_changes_files(changes_files, os.path.basename(directory), f, rrd_dir)
664         else:
665             utils.warn("Cannot find queue %s" % queue_name)
666
667     if Cnf.has_key("Queue-Report::Options::822"):
668         f.close()
669
670     if Cnf.has_key("Queue-Report::Options::New"):
671         footer()
672
673 ################################################################################
674
675 if __name__ == '__main__':
676     main()