3 """ Produces a set of graphs of NEW/BYHAND/DEFERRED"""
4 # Copyright 2011 Paul Wise <pabs@debian.org>
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.
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.
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
26 from daklib import utils
27 from daklib.dak_exceptions import *
30 default_names = ["byhand", "new", "deferred"]
32 ################################################################################
34 def usage(exit_code=0):
35 print """Usage: dak queue-graph
36 Graphs the number of packages in queue directories (usually new and byhand).
38 -h, --help show this help and exit.
39 -r, --rrd=key Directory where rrd files to be updated are stored
40 -x, --extra-rrd=key File containing extra options to rrdtool graphing
41 -i, --images=key Directory where image graphs to be updated are stored
42 -n, --names=key A comma seperated list of rrd files to be scanned
47 ################################################################################
49 def graph(rrd_dir, image_dir, name, extra_args, graph, title, start, year_lines=False):
50 image_file = os.path.join(image_dir, "%s-%s.png" % (name, graph))
51 rrd_file = os.path.join(rrd_dir, "%s.rrd" % name)
52 rrd_args = [image_file, "--start", start]
67 """ % title).strip().split("\n")
70 rrd_args += ["--x-grid", "MONTH:1:YEAR:1:YEAR:1:31536000:%Y"]
73 DEF:ds1=%s:ds1:AVERAGE
74 LINE2:ds1#D9382B:Total package count:
76 VDEF:minds1=ds1,MINIMUM
77 VDEF:maxds1=ds1,MAXIMUM
78 VDEF:avgds1=ds1,AVERAGE
80 GPRINT:minds1:\tMin\\: %%3.0lf
81 GPRINT:maxds1:\tMax\\: %%3.0lf
82 GPRINT:avgds1:\tAvg\\: %%3.0lf\\j
83 DEF:ds0=%s:ds0:AVERAGE
85 VDEF:minds0=ds0,MINIMUM
86 VDEF:maxds0=ds0,MAXIMUM
87 VDEF:avgds0=ds0,AVERAGE
88 LINE2:ds0#3069DA:Package count in %s:
90 GPRINT:minds0:\tMin\\: %%3.0lf
91 GPRINT:maxds0:\tMax\\: %%3.0lf
92 GPRINT:avgds0:\tAvg\\: %%3.0lf\\j
93 """ % (rrd_file, rrd_file, name.upper())).strip().split("\n")
95 rrd_args += extra_args
96 rrdtool.graph(*rrd_args)
98 ################################################################################
103 Cnf = utils.get_conf()
104 Arguments = [('h',"help","Graph::Options::Help"),
105 ('x',"extra-rrd","Graph::Options::Extra-Rrd", "HasArg"),
106 ('r',"rrd","Graph::Options::Rrd", "HasArg"),
107 ('i',"images","Graph::Options::Images", "HasArg"),
108 ('n',"names","Graph::Options::Names", "HasArg")]
110 if not Cnf.has_key("Graph::Options::%s" % (i)):
111 Cnf["Graph::Options::%s" % (i)] = ""
113 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
115 Options = Cnf.SubTree("Graph::Options")
121 if Cnf.has_key("Graph::Options::Names"):
122 for i in Cnf["Graph::Options::Names"].split(","):
124 elif Cnf.has_key("Graph::Names"):
125 names = Cnf.ValueList("Graph::Names")
127 names = default_names
129 extra_rrdtool_args = []
131 if Cnf.has_key("Graph::Options::Extra-Rrd"):
132 for i in Cnf["Graph::Options::Extra-Rrd"].split(","):
134 extra_rrdtool_args.extend(f.read().strip().split("\n"))
136 elif Cnf.has_key("Graph::Extra-Rrd"):
137 for i in Cnf.ValueList("Graph::Extra-Rrd"):
139 extra_rrdtool_args.extend(f.read().strip().split("\n"))
142 if Cnf.has_key("Graph::Options::Rrd"):
143 rrd_dir = Cnf["Graph::Options::Rrd"]
144 elif Cnf.has_key("Dir::Rrd"):
145 rrd_dir = Cnf["Dir::Rrd"]
147 print >> sys.stderr, "No directory to read RRD files from\n"
150 if Cnf.has_key("Graph::Options::Images"):
151 image_dir = Cnf["Graph::Options::Images"]
153 print >> sys.stderr, "No directory to write graph images to\n"
157 stdargs = [rrd_dir, image_dir, name, extra_rrdtool_args]
158 graph(*(stdargs+['day', 'day', 'now-1d']))
159 graph(*(stdargs+['week', 'week', 'now-1w']))
160 graph(*(stdargs+['month', 'month', 'now-1m']))
161 graph(*(stdargs+['year', 'year', 'now-1y']))
162 graph(*(stdargs+['5years', '5 years', 'now-5y', True]))
163 graph(*(stdargs+['10years', '10 years', 'now-10y', True]))
165 ################################################################################
167 if __name__ == '__main__':