]> git.decadent.org.uk Git - dak.git/blobdiff - dak/stats.py
Merge remote-tracking branch 'ansgar/pu/wheezy' into merge
[dak.git] / dak / stats.py
index 50524641c9255e2fd0088221161e5e0fa5237924..f33873475029ff701fdd2509ee57275fbf28b6f6 100755 (executable)
 
 ################################################################################
 
-import pg, sys
+import sys
 import apt_pkg
+
 from daklib import utils
-from daklib.dbconn import DBConn, get_suite_architectures, Suite, Architecture, \
-                          BinAssociation
+from daklib.dbconn import DBConn, get_suite_architectures, Suite, Architecture
 
 ################################################################################
 
@@ -111,29 +111,12 @@ def longest(list):
             longest = l
     return longest
 
-def suite_sort(a, b):
-    if Cnf.has_key("Suite::%s::Priority" % (a)):
-        a_priority = int(Cnf["Suite::%s::Priority" % (a)])
-    else:
-        a_priority = 0
-    if Cnf.has_key("Suite::%s::Priority" % (b)):
-        b_priority = int(Cnf["Suite::%s::Priority" % (b)])
-    else:
-        b_priority = 0
-    return cmp(a_priority, b_priority)
-
 def output_format(suite):
     output_suite = []
     for word in suite.split("-"):
         output_suite.append(word[0])
     return "-".join(output_suite)
 
-# Obvious query with GROUP BY and mapped names                  -> 50 seconds
-# GROUP BY but ids instead of suite/architecture names          -> 28 seconds
-# Simple query                                                  -> 14 seconds
-# Simple query into large dictionary + processing               -> 21 seconds
-# Simple query into large pre-created dictionary + processing   -> 18 seconds
-
 def number_of_packages():
     arches = {}
     arch_ids = {}
@@ -157,19 +140,19 @@ def number_of_packages():
     # Get the raw data for binaries
     # Simultate 'GROUP by suite, architecture' with a dictionary
     # XXX: Why don't we just get the DB to do this?
-    for i in session.query(BinAssociation):
-        suite_id = i.suite_id
-        arch_id = i.binary.arch_id
-        d[suite_id][arch_id] = d[suite_id][arch_id] + 1
+    for i in session.execute("""SELECT suite, architecture, COUNT(suite)
+                                FROM bin_associations
+                           LEFT JOIN binaries ON bin = binaries.id
+                            GROUP BY suite, architecture""").fetchall():
+        d[ i[0] ][ i[1] ] = i[2]
     # Get the raw data for source
     arch_id = arch_ids["source"]
-    for i in session.execute('SELECT suite, COUNT(suite) FROM src_associations GROUP BY suite').all():
+    for i in session.execute('SELECT suite, COUNT(suite) FROM src_associations GROUP BY suite').fetchall():
         (suite_id, count) = i
         d[suite_id][arch_id] = d[suite_id][arch_id] + count
     ## Print the results
     # Setup
     suite_list = suites.values()
-    suite_list.sort(suite_sort)
     suite_id_list = []
     suite_arches = {}
     for suite in suite_list:
@@ -197,7 +180,7 @@ def number_of_packages():
         output = output + arch.center(longest_arch)+" |"
         for suite_id in suite_id_list:
             if suite_arches[suite_id].has_key(arch):
-                count = repr(d[suite_id][arch_id])
+                count = "%d" % d[suite_id][arch_id]
             else:
                 count = "-"
             output = output + count.rjust(longest_suite)+" |"
@@ -215,9 +198,9 @@ def main ():
         if not Cnf.has_key("Stats::Options::%s" % (i)):
             Cnf["Stats::Options::%s" % (i)] = ""
 
-    args = apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
+    args = apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
 
-    Options = Cnf.SubTree("Stats::Options")
+    Options = Cnf.subtree("Stats::Options")
     if Options["Help"]:
         usage()