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