3 """ Produces a set of graphs of NEW/BYHAND/DEFERRED
5 @contact: Debian FTPMaster <ftpmaster@debian.org>
6 @copyright: 2011 Paul Wise <pabs@debian.org>
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 from daklib import utils
30 from daklib.dak_exceptions import *
33 default_names = ["byhand", "new", "deferred"]
35 ################################################################################
37 def usage(exit_code=0):
38 print """Usage: dak graph
39 Graphs the number of packages in queue directories (usually new and byhand).
41 -h, --help show this help and exit.
42 -r, --rrd=key Directory where rrd files to be updated are stored
43 -x, --extra-rrd=key File containing extra options to rrdtool graphing
44 -i, --images=key Directory where image graphs to be updated are stored
45 -n, --names=key A comma seperated list of rrd files to be scanned
50 ################################################################################
52 def graph(rrd_dir, image_dir, name, extra_args, graph, title, start, year_lines=False):
53 image_file = os.path.join(image_dir, "%s-%s.png" % (name, graph))
54 rrd_file = os.path.join(rrd_dir, "%s.rrd" % name)
55 rrd_args = [image_file, "--start", start]
66 %s package count for the last %s
70 """ % (name.upper(), title) ).strip().split("\n")
73 rrd_args += ["--x-grid", "MONTH:1:YEAR:1:YEAR:1:31536000:%Y"]
76 DEF:ds1=%s:ds1:AVERAGE
77 LINE2:ds1#D9382B:changes count
79 VDEF:minds1=ds1,MINIMUM
80 VDEF:maxds1=ds1,MAXIMUM
81 VDEF:avgds1=ds1,AVERAGE
82 GPRINT:lds1:cur\\: %%.0lf
83 GPRINT:minds1:min\\: %%.0lf
84 GPRINT:maxds1:max\\: %%.0lf
85 GPRINT:avgds1:avg\\: %%.0lf\\j
86 DEF:ds0=%s:ds0:AVERAGE
88 VDEF:minds0=ds0,MINIMUM
89 VDEF:maxds0=ds0,MAXIMUM
90 VDEF:avgds0=ds0,AVERAGE
91 LINE2:ds0#3069DA:src pkg count
92 GPRINT:lds0:cur\\: %%.0lf
93 GPRINT:minds0:min\\: %%.0lf
94 GPRINT:maxds0:max\\: %%.0lf
95 GPRINT:avgds0:avg\\: %%.0lf\\j
96 """ % (rrd_file, rrd_file)).strip().split("\n")
98 rrd_args += extra_args
100 ret = rrdtool.graph(*rrd_args)
101 except rrdtool.error, e:
102 print('warning: graph: rrdtool error, skipping %s-%s.png: %s' % (name, graph, e))
104 ################################################################################
109 Cnf = utils.get_conf()
110 Arguments = [('h',"help","Graph::Options::Help"),
111 ('x',"extra-rrd","Graph::Options::Extra-Rrd", "HasArg"),
112 ('r',"rrd","Graph::Options::Rrd", "HasArg"),
113 ('i',"images","Graph::Options::Images", "HasArg"),
114 ('n',"names","Graph::Options::Names", "HasArg")]
116 if not Cnf.has_key("Graph::Options::%s" % (i)):
117 Cnf["Graph::Options::%s" % (i)] = ""
119 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
121 Options = Cnf.SubTree("Graph::Options")
127 if Cnf.has_key("Graph::Options::Names"):
128 for i in Cnf["Graph::Options::Names"].split(","):
130 elif Cnf.has_key("Graph::Names"):
131 names = Cnf.ValueList("Graph::Names")
133 names = default_names
135 extra_rrdtool_args = []
137 if Cnf.has_key("Graph::Options::Extra-Rrd"):
138 for i in Cnf["Graph::Options::Extra-Rrd"].split(","):
140 extra_rrdtool_args.extend(f.read().strip().split("\n"))
142 elif Cnf.has_key("Graph::Extra-Rrd"):
143 for i in Cnf.ValueList("Graph::Extra-Rrd"):
145 extra_rrdtool_args.extend(f.read().strip().split("\n"))
148 if Cnf.has_key("Graph::Options::Rrd"):
149 rrd_dir = Cnf["Graph::Options::Rrd"]
150 elif Cnf.has_key("Dir::Rrd"):
151 rrd_dir = Cnf["Dir::Rrd"]
153 print >> sys.stderr, "No directory to read RRD files from\n"
156 if Cnf.has_key("Graph::Options::Images"):
157 image_dir = Cnf["Graph::Options::Images"]
159 print >> sys.stderr, "No directory to write graph images to\n"
163 stdargs = [rrd_dir, image_dir, name, extra_rrdtool_args]
164 graph(*(stdargs+['day', 'day', 'now-1d']))
165 graph(*(stdargs+['week', 'week', 'now-1w']))
166 graph(*(stdargs+['month', 'month', 'now-1m']))
167 graph(*(stdargs+['year', 'year', 'now-1y']))
168 graph(*(stdargs+['5years', '5 years', 'now-5y', True]))
169 graph(*(stdargs+['10years', '10 years', 'now-10y', True]))
171 ################################################################################
173 if __name__ == '__main__':