]> git.decadent.org.uk Git - dak.git/blob - dak/queue_report.py
Merge remote-tracking branch 'ansgar/pu/postgresql-9.1' 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     if "binNEW" in trclass:
294         print "<td class=\"package\">%s</td>" % (source)
295     else:
296         print "<td class=\"package\"><a href=\"http://packages.qa.debian.org/%(source)s\">%(source)s</a></td>" % {'source': source}
297     print "<td class=\"version\">"
298     for vers in version.split():
299         print "<a href=\"new/%s_%s.html\">%s</a><br/>" % (source, utils.html_escape(vers), utils.html_escape(vers))
300     print "</td>"
301     print "<td class=\"arch\">%s</td>" % (arch)
302     print "<td class=\"distribution\">"
303     for dist in distribution:
304         print "%s<br/>" % (dist)
305     print "</td>"
306     print "<td class=\"age\">%s</td>" % (last_mod)
307     (name, mail) = maint.split(":", 1)
308
309     print "<td class=\"upload-data\">"
310     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))
311     (name, mail) = changedby.split(":", 1)
312     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))
313
314     if sponsor:
315         try:
316             (login, domain) = sponsor.split("@", 1)
317             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))
318         except Exception as e:
319             pass
320
321     print "<span class=\"signature\">Fingerprint: %s</span>" % (fingerprint)
322     print "</td>"
323
324     print "<td class=\"closes\">"
325     for close in closes:
326         print "<a href=\"http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s\">#%s</a><br/>" % (utils.html_escape(close), utils.html_escape(close))
327     print "</td></tr>"
328     row_number+=1
329
330 ############################################################
331
332 def update_graph_database(rrd_dir, type, n_source, n_binary):
333     if not rrd_dir:
334         return
335
336     rrd_file = os.path.join(rrd_dir, type.lower()+'.rrd')
337     update = [rrd_file, "N:%s:%s" % (n_source, n_binary)]
338
339     try:
340         rrdtool.update(*update)
341     except rrdtool.error:
342         create = [rrd_file]+"""
343 --step
344 300
345 --start
346 0
347 DS:ds0:GAUGE:7200:0:1000
348 DS:ds1:GAUGE:7200:0:1000
349 RRA:AVERAGE:0.5:1:599
350 RRA:AVERAGE:0.5:6:700
351 RRA:AVERAGE:0.5:24:775
352 RRA:AVERAGE:0.5:288:795
353 RRA:MAX:0.5:1:600
354 RRA:MAX:0.5:6:700
355 RRA:MAX:0.5:24:775
356 RRA:MAX:0.5:288:795
357 """.strip().split("\n")
358         try:
359             rc = rrdtool.create(*create)
360             ru = rrdtool.update(*update)
361         except rrdtool.error as e:
362             print('warning: queue_report: rrdtool error, skipping %s.rrd: %s' % (type, e))
363     except NameError:
364         pass
365
366 ############################################################
367
368 def process_changes_files(changes_files, type, log, rrd_dir):
369     msg = ""
370     cache = {}
371     # Read in all the .changes files
372     for filename in changes_files:
373         try:
374             u = Upload()
375             u.load_changes(filename)
376             cache[filename] = copy(u.pkg.changes)
377             cache[filename]["filename"] = filename
378         except Exception as e:
379             print "WARNING: Exception %s" % e
380             continue
381     # Divide the .changes into per-source groups
382     per_source = {}
383     for filename in cache.keys():
384         source = cache[filename]["source"]
385         if not per_source.has_key(source):
386             per_source[source] = {}
387             per_source[source]["list"] = []
388         per_source[source]["list"].append(cache[filename])
389     # Determine oldest time and have note status for each source group
390     for source in per_source.keys():
391         source_list = per_source[source]["list"]
392         first = source_list[0]
393         oldest = os.stat(first["filename"])[stat.ST_MTIME]
394         have_note = 0
395         for d in per_source[source]["list"]:
396             mtime = os.stat(d["filename"])[stat.ST_MTIME]
397             if Cnf.has_key("Queue-Report::Options::New"):
398                 if mtime > oldest:
399                     oldest = mtime
400             else:
401                 if mtime < oldest:
402                     oldest = mtime
403             have_note += has_new_comment(d["source"], d["version"])
404         per_source[source]["oldest"] = oldest
405         if not have_note:
406             per_source[source]["note_state"] = 0; # none
407         elif have_note < len(source_list):
408             per_source[source]["note_state"] = 1; # some
409         else:
410             per_source[source]["note_state"] = 2; # all
411     per_source_items = per_source.items()
412     per_source_items.sort(sg_compare)
413
414     update_graph_database(rrd_dir, type, len(per_source_items), len(changes_files))
415
416     entries = []
417     max_source_len = 0
418     max_version_len = 0
419     max_arch_len = 0
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]["filename"]
430         last_modified = time.time()-i[1]["oldest"]
431         source = i[1]["list"][0]["source"]
432         if len(source) > max_source_len:
433             max_source_len = len(source)
434         binary_list = i[1]["list"][0]["binary"].keys()
435         binary = ', '.join(binary_list)
436         arches = {}
437         versions = {}
438         for j in i[1]["list"]:
439             changesbase = os.path.basename(j["filename"])
440             try:
441                 session = DBConn().session()
442                 dbc = session.query(DBChange).filter_by(changesname=changesbase).one()
443                 session.close()
444             except Exception as e:
445                 print "Can't find changes file in NEW for %s (%s)" % (changesbase, e)
446                 dbc = None
447
448             if Cnf.has_key("Queue-Report::Options::New") or Cnf.has_key("Queue-Report::Options::822"):
449                 try:
450                     (maintainer["maintainer822"], maintainer["maintainer2047"],
451                     maintainer["maintainername"], maintainer["maintaineremail"]) = \
452                     fix_maintainer (j["maintainer"])
453                 except ParseMaintError as msg:
454                     print "Problems while parsing maintainer address\n"
455                     maintainer["maintainername"] = "Unknown"
456                     maintainer["maintaineremail"] = "Unknown"
457                 maint="%s:%s" % (maintainer["maintainername"], maintainer["maintaineremail"])
458                 # ...likewise for the Changed-By: field if it exists.
459                 try:
460                     (changeby["changedby822"], changeby["changedby2047"],
461                      changeby["changedbyname"], changeby["changedbyemail"]) = \
462                      fix_maintainer (j["changed-by"])
463                 except ParseMaintError as msg:
464                     (changeby["changedby822"], changeby["changedby2047"],
465                      changeby["changedbyname"], changeby["changedbyemail"]) = \
466                      ("", "", "", "")
467                 changedby="%s:%s" % (changeby["changedbyname"], changeby["changedbyemail"])
468
469                 distribution=j["distribution"].keys()
470                 closes=j["closes"].keys()
471                 if dbc:
472                     fingerprint = dbc.fingerprint
473                     sponsor_name = get_uid_from_fingerprint(fingerprint).name
474                     sponsor_email = get_uid_from_fingerprint(fingerprint).uid + "@debian.org"
475                     if sponsor_name != maintainer["maintainername"] and sponsor_name != changeby["changedbyname"] and \
476                     sponsor_email != maintainer["maintaineremail"] and sponsor_name != changeby["changedbyemail"]:
477                         sponsor = sponsor_email
478
479             for arch in j["architecture"].keys():
480                 arches[arch] = ""
481             version = j["version"]
482             versions[version] = ""
483         arches_list = arches.keys()
484         arches_list.sort(utils.arch_compare_sw)
485         arch_list = " ".join(arches_list)
486         version_list = " ".join(versions.keys())
487         if len(version_list) > max_version_len:
488             max_version_len = len(version_list)
489         if len(arch_list) > max_arch_len:
490             max_arch_len = len(arch_list)
491         if i[1]["note_state"]:
492             note = " | [N]"
493         else:
494             note = ""
495         entries.append([source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, filename])
496
497     # direction entry consists of "Which field, which direction, time-consider" where
498     # time-consider says how we should treat last_modified. Thats all.
499
500     # Look for the options for sort and then do the sort.
501     age = "h"
502     if Cnf.has_key("Queue-Report::Options::Age"):
503         age =  Cnf["Queue-Report::Options::Age"]
504     if Cnf.has_key("Queue-Report::Options::New"):
505     # If we produce html we always have oldest first.
506         direction.append([5,-1,"ao"])
507     else:
508         if Cnf.has_key("Queue-Report::Options::Sort"):
509             for i in Cnf["Queue-Report::Options::Sort"].split(","):
510                 if i == "ao":
511                     # Age, oldest first.
512                     direction.append([5,-1,age])
513                 elif i == "an":
514                     # Age, newest first.
515                     direction.append([5,1,age])
516                 elif i == "na":
517                     # Name, Ascending.
518                     direction.append([0,1,0])
519                 elif i == "nd":
520                     # Name, Descending.
521                     direction.append([0,-1,0])
522                 elif i == "nl":
523                     # Notes last.
524                     direction.append([4,1,0])
525                 elif i == "nf":
526                     # Notes first.
527                     direction.append([4,-1,0])
528     entries.sort(lambda x, y: sortfunc(x, y))
529     # Yes, in theory you can add several sort options at the commandline with. But my mind is to small
530     # at the moment to come up with a real good sorting function that considers all the sidesteps you
531     # have with it. (If you combine options it will simply take the last one at the moment).
532     # Will be enhanced in the future.
533
534     if Cnf.has_key("Queue-Report::Options::822"):
535         # print stuff out in 822 format
536         for entry in entries:
537             (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, changes_file) = entry
538
539             # We'll always have Source, Version, Arch, Mantainer, and Dist
540             # For the rest, check to see if we have them, then print them out
541             log.write("Source: " + source + "\n")
542             log.write("Binary: " + binary + "\n")
543             log.write("Version: " + version_list + "\n")
544             log.write("Architectures: ")
545             log.write( (", ".join(arch_list.split(" "))) + "\n")
546             log.write("Age: " + time_pp(last_modified) + "\n")
547             log.write("Last-Modified: " + str(int(time.time()) - int(last_modified)) + "\n")
548             log.write("Queue: " + type + "\n")
549
550             (name, mail) = maint.split(":", 1)
551             log.write("Maintainer: " + name + " <"+mail+">" + "\n")
552             if changedby:
553                (name, mail) = changedby.split(":", 1)
554                log.write("Changed-By: " + name + " <"+mail+">" + "\n")
555             if sponsor:
556                log.write("Sponsored-By: " + "@".join(sponsor.split("@")[:2]) + "\n")
557             log.write("Distribution:")
558             for dist in distribution:
559                log.write(" " + dist)
560             log.write("\n")
561             log.write("Fingerprint: " + fingerprint + "\n")
562             if closes:
563                 bug_string = ""
564                 for bugs in closes:
565                     bug_string += "#"+bugs+", "
566                 log.write("Closes: " + bug_string[:-2] + "\n")
567             log.write("Changes-File: " + os.path.basename(changes_file) + "\n")
568             log.write("\n")
569
570     if Cnf.has_key("Queue-Report::Options::New"):
571         direction.append([5,1,"ao"])
572         entries.sort(lambda x, y: sortfunc(x, y))
573     # Output for a html file. First table header. then table_footer.
574     # Any line between them is then a <tr> printed from subroutine table_row.
575         if len(entries) > 0:
576             total_count = len(changes_files)
577             source_count = len(per_source_items)
578             table_header(type.upper(), source_count, total_count)
579             for entry in entries:
580                 (source, binary, version_list, arch_list, note, last_modified, maint, distribution, closes, fingerprint, sponsor, changedby, undef) = entry
581                 table_row(source, version_list, arch_list, time_pp(last_modified), maint, distribution, closes, fingerprint, sponsor, changedby)
582             table_footer(type.upper())
583     elif not Cnf.has_key("Queue-Report::Options::822"):
584     # The "normal" output without any formatting.
585         format="%%-%ds | %%-%ds | %%-%ds%%s | %%s old\n" % (max_source_len, max_version_len, max_arch_len)
586
587         msg = ""
588         for entry in entries:
589             (source, binary, version_list, arch_list, note, last_modified, undef, undef, undef, undef, undef, undef, undef) = entry
590             msg += format % (source, version_list, arch_list, note, time_pp(last_modified))
591
592         if msg:
593             total_count = len(changes_files)
594             source_count = len(per_source_items)
595             print type.upper()
596             print "-"*len(type)
597             print
598             print msg
599             print "%s %s source package%s / %s %s package%s in total." % (source_count, type, plural(source_count), total_count, type, plural(total_count))
600             print
601
602
603 ################################################################################
604
605 def main():
606     global Cnf
607
608     Cnf = utils.get_conf()
609     Arguments = [('h',"help","Queue-Report::Options::Help"),
610                  ('n',"new","Queue-Report::Options::New"),
611                  ('8','822',"Queue-Report::Options::822"),
612                  ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
613                  ('a',"age","Queue-Report::Options::Age", "HasArg"),
614                  ('r',"rrd","Queue-Report::Options::Rrd", "HasArg"),
615                  ('d',"directories","Queue-Report::Options::Directories", "HasArg")]
616     for i in [ "help" ]:
617         if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
618             Cnf["Queue-Report::Options::%s" % (i)] = ""
619
620     apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
621
622     Options = Cnf.SubTree("Queue-Report::Options")
623     if Options["Help"]:
624         usage()
625
626     if Cnf.has_key("Queue-Report::Options::New"):
627         header()
628
629     # Initialize db so we can get the NEW comments
630     dbconn = DBConn()
631
632     queue_names = [ ]
633
634     if Cnf.has_key("Queue-Report::Options::Directories"):
635         for i in Cnf["Queue-Report::Options::Directories"].split(","):
636             queue_names.append(i)
637     elif Cnf.has_key("Queue-Report::Directories"):
638         queue_names = Cnf.ValueList("Queue-Report::Directories")
639     else:
640         queue_names = [ "byhand", "new" ]
641
642     if Cnf.has_key("Queue-Report::Options::Rrd"):
643         rrd_dir = Cnf["Queue-Report::Options::Rrd"]
644     elif Cnf.has_key("Dir::Rrd"):
645         rrd_dir = Cnf["Dir::Rrd"]
646     else:
647         rrd_dir = None
648
649     f = None
650     if Cnf.has_key("Queue-Report::Options::822"):
651         # Open the report file
652         f = open(Cnf["Queue-Report::ReportLocations::822Location"], "w")
653
654     session = dbconn.session()
655
656     for queue_name in queue_names:
657         queue = get_policy_queue(queue_name, session)
658         if queue:
659             directory = os.path.abspath(queue.path)
660             changes_files = glob.glob("%s/*.changes" % (directory))
661             process_changes_files(changes_files, os.path.basename(directory), f, rrd_dir)
662         else:
663             utils.warn("Cannot find queue %s" % queue_name)
664
665     if Cnf.has_key("Queue-Report::Options::822"):
666         f.close()
667
668     if Cnf.has_key("Queue-Report::Options::New"):
669         footer()
670
671 ################################################################################
672
673 if __name__ == '__main__':
674     main()