]> git.decadent.org.uk Git - dak.git/blobdiff - dak/graph.py
Remove files that are (no longer) generated
[dak.git] / dak / graph.py
index 6691f929757bb22c75d5ce7e785df8d34ac69000..0566130bb29168e4846ca4ed3bf8c89cedcb66c6 100755 (executable)
@@ -22,6 +22,7 @@
 
 import os
 import sys
+import colorsys
 
 import rrdtool
 import apt_pkg
@@ -49,7 +50,65 @@ Graphs the number of packages in queue directories (usually new and byhand).
 
 ################################################################################
 
-def graph(rrd_dir, image_dir, name, extra_args, graph, title, start, year_lines=False):
+def graph(*args):
+    if args[2] == "deferred":
+        graph_deferred(*args)
+    else:
+        graph_normal(*args)
+
+def deferred_colours():
+    colours = [0]*16
+    for i in range(0,16):
+        colours[i] = colorsys.hsv_to_rgb(i/16.0, 1.0, 0.5+i/32.0)
+        colours[i] = ''.join(['%02X' % (c*255) for c in colours[i]])
+    return colours
+
+colours = deferred_colours()
+
+def graph_deferred(rrd_dir, image_dir, name, extra_args, graph, title, start, year_lines=False):
+    image_file = os.path.join(image_dir, "%s-%s.png" % (name, graph))
+    rrd_file = os.path.join(rrd_dir, "%s.rrd" % name)
+    rrd_args = [image_file, "--start", start]
+    rrd_args += ("""
+--end
+now
+--width
+600
+--height
+150
+--vertical-label
+changes
+--title
+%s changes count for the last %s
+--lower-limit
+0
+-E
+""" % (name.upper(), title) ).strip().split("\n")
+
+    if year_lines:
+        rrd_args += ["--x-grid", "MONTH:1:YEAR:1:YEAR:1:31536000:%Y"]
+
+    for i in range(0,16):
+        rrd_args += ("""
+DEF:d%i=%s:day%i:AVERAGE
+AREA:d%i#%s:%i-day changes count:STACK
+VDEF:ld%i=d%i,LAST
+VDEF:mind%i=d%i,MINIMUM
+VDEF:maxd%i=d%i,MAXIMUM
+VDEF:avgd%i=d%i,AVERAGE
+GPRINT:ld%i:cur\\: %%.0lf
+GPRINT:mind%i:min\\: %%.0lf
+GPRINT:maxd%i:max\\: %%.0lf
+GPRINT:avgd%i:avg\\: %%.0lf\\j
+""" % ((i, rrd_file, i, i, colours[i])+(i,)*13)).strip().split("\n")
+
+    rrd_args += extra_args
+    try:
+        ret = rrdtool.graph(*rrd_args)
+    except rrdtool.error as e:
+        print('warning: graph: rrdtool error, skipping %s-%s.png: %s' % (name, graph, e))
+
+def graph_normal(rrd_dir, image_dir, name, extra_args, graph, title, start, year_lines=False):
     image_file = os.path.join(image_dir, "%s-%s.png" % (name, graph))
     rrd_file = os.path.join(rrd_dir, "%s.rrd" % name)
     rrd_args = [image_file, "--start", start]
@@ -74,26 +133,26 @@ packages
 
     rrd_args += ("""
 DEF:ds1=%s:ds1:AVERAGE
-LINE2:ds1#D9382B:Total package count:
+LINE2:ds1#D9382B:changes count
 VDEF:lds1=ds1,LAST
 VDEF:minds1=ds1,MINIMUM
 VDEF:maxds1=ds1,MAXIMUM
 VDEF:avgds1=ds1,AVERAGE
-GPRINT:lds1:%%3.0lf
-GPRINT:minds1:\tMin\\: %%3.0lf
-GPRINT:maxds1:\tMax\\: %%3.0lf
-GPRINT:avgds1:\tAvg\\: %%3.0lf\\j
+GPRINT:lds1:cur\\: %%.0lf
+GPRINT:minds1:min\\: %%.0lf
+GPRINT:maxds1:max\\: %%.0lf
+GPRINT:avgds1:avg\\: %%.0lf\\j
 DEF:ds0=%s:ds0:AVERAGE
 VDEF:lds0=ds0,LAST
 VDEF:minds0=ds0,MINIMUM
 VDEF:maxds0=ds0,MAXIMUM
 VDEF:avgds0=ds0,AVERAGE
-LINE2:ds0#3069DA:Package count in %s:
-GPRINT:lds0:%%3.0lf
-GPRINT:minds0:\tMin\\: %%3.0lf
-GPRINT:maxds0:\tMax\\: %%3.0lf
-GPRINT:avgds0:\tAvg\\: %%3.0lf\\j
-""" % (rrd_file, rrd_file, name.upper())).strip().split("\n")
+LINE2:ds0#3069DA:src pkg count
+GPRINT:lds0:cur\\: %%.0lf
+GPRINT:minds0:min\\: %%.0lf
+GPRINT:maxds0:max\\: %%.0lf
+GPRINT:avgds0:avg\\: %%.0lf\\j
+""" % (rrd_file, rrd_file)).strip().split("\n")
 
     rrd_args += extra_args
     try:
@@ -116,9 +175,9 @@ def main():
         if not Cnf.has_key("Graph::Options::%s" % (i)):
             Cnf["Graph::Options::%s" % (i)] = ""
 
-    apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
+    apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
 
-    Options = Cnf.SubTree("Graph::Options")
+    Options = Cnf.subtree("Graph::Options")
     if Options["Help"]:
         usage()
 
@@ -128,7 +187,7 @@ def main():
         for i in Cnf["Graph::Options::Names"].split(","):
             names.append(i)
     elif Cnf.has_key("Graph::Names"):
-        names = Cnf.ValueList("Graph::Names")
+        names = Cnf.value_list("Graph::Names")
     else:
         names = default_names
 
@@ -140,7 +199,7 @@ def main():
             extra_rrdtool_args.extend(f.read().strip().split("\n"))
             f.close()
     elif Cnf.has_key("Graph::Extra-Rrd"):
-        for i in Cnf.ValueList("Graph::Extra-Rrd"):
+        for i in Cnf.value_list("Graph::Extra-Rrd"):
             f = open(i)
             extra_rrdtool_args.extend(f.read().strip().split("\n"))
             f.close()