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]
70 """ % 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:Total package count:
79 VDEF:minds1=ds1,MINIMUM
80 VDEF:maxds1=ds1,MAXIMUM
81 VDEF:avgds1=ds1,AVERAGE
83 GPRINT:minds1:\tMin\\: %%3.0lf
84 GPRINT:maxds1:\tMax\\: %%3.0lf
85 GPRINT:avgds1:\tAvg\\: %%3.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:Package count in %s:
93 GPRINT:minds0:\tMin\\: %%3.0lf
94 GPRINT:maxds0:\tMax\\: %%3.0lf
95 GPRINT:avgds0:\tAvg\\: %%3.0lf\\j
96 """ % (rrd_file, rrd_file, name.upper())).strip().split("\n")
98 rrd_args += extra_args
99 rrdtool.graph(*rrd_args)
101 ################################################################################
106 Cnf = utils.get_conf()
107 Arguments = [('h',"help","Graph::Options::Help"),
108 ('x',"extra-rrd","Graph::Options::Extra-Rrd", "HasArg"),
109 ('r',"rrd","Graph::Options::Rrd", "HasArg"),
110 ('i',"images","Graph::Options::Images", "HasArg"),
111 ('n',"names","Graph::Options::Names", "HasArg")]
113 if not Cnf.has_key("Graph::Options::%s" % (i)):
114 Cnf["Graph::Options::%s" % (i)] = ""
116 apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
118 Options = Cnf.SubTree("Graph::Options")
124 if Cnf.has_key("Graph::Options::Names"):
125 for i in Cnf["Graph::Options::Names"].split(","):
127 elif Cnf.has_key("Graph::Names"):
128 names = Cnf.ValueList("Graph::Names")
130 names = default_names
132 extra_rrdtool_args = []
134 if Cnf.has_key("Graph::Options::Extra-Rrd"):
135 for i in Cnf["Graph::Options::Extra-Rrd"].split(","):
137 extra_rrdtool_args.extend(f.read().strip().split("\n"))
139 elif Cnf.has_key("Graph::Extra-Rrd"):
140 for i in Cnf.ValueList("Graph::Extra-Rrd"):
142 extra_rrdtool_args.extend(f.read().strip().split("\n"))
145 if Cnf.has_key("Graph::Options::Rrd"):
146 rrd_dir = Cnf["Graph::Options::Rrd"]
147 elif Cnf.has_key("Dir::Rrd"):
148 rrd_dir = Cnf["Dir::Rrd"]
150 print >> sys.stderr, "No directory to read RRD files from\n"
153 if Cnf.has_key("Graph::Options::Images"):
154 image_dir = Cnf["Graph::Options::Images"]
156 print >> sys.stderr, "No directory to write graph images to\n"
160 stdargs = [rrd_dir, image_dir, name, extra_rrdtool_args]
161 graph(*(stdargs+['day', 'day', 'now-1d']))
162 graph(*(stdargs+['week', 'week', 'now-1w']))
163 graph(*(stdargs+['month', 'month', 'now-1m']))
164 graph(*(stdargs+['year', 'year', 'now-1y']))
165 graph(*(stdargs+['5years', '5 years', 'now-5y', True]))
166 graph(*(stdargs+['10years', '10 years', 'now-10y', True]))
168 ################################################################################
170 if __name__ == '__main__':