X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=dak%2Fstats.py;h=849c36b27cb6081265a23db0a9d751f757b11dca;hb=56477fb20a2e3b97a4f47d2c18d137b36f083584;hp=f7414eddc85ca4cfbd6b932af5ff74dda24283c3;hpb=1bcac7a38c0b55aa9a8ec984c44661f92e7bc536;p=dak.git diff --git a/dak/stats.py b/dak/stats.py index f7414edd..849c36b2 100755 --- a/dak/stats.py +++ b/dak/stats.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -# Various statistical pr0nography fun and games +""" Various statistical pr0nography fun and games """ # Copyright (C) 2000, 2001, 2002, 2003, 2006 James Troup # This program is free software; you can redistribute it and/or modify @@ -32,7 +32,8 @@ import pg, sys import apt_pkg -import daklib.utils +from daklib import utils +from daklib import database ################################################################################ @@ -71,8 +72,8 @@ SELECT a.arch_string as Architecture, sum(f.size) def daily_install_stats(): stats = {} - file = daklib.utils.open_file("2001-11") - for line in file.readlines(): + f = utils.open_file("2001-11") + for line in f.readlines(): split = line.strip().split('|') program = split[1] if program != "katie" and program != "process-accepted": @@ -140,15 +141,15 @@ def number_of_packages(): q = projectB.query("SELECT id, suite_name FROM suite") suite_ql = q.getresult() for i in suite_ql: - (id, name) = i - suites[id] = name - suite_ids[name] = id + (sid, name) = i + suites[sid] = name + suite_ids[name] = sid # Build up architecture mapping q = projectB.query("SELECT id, arch_string FROM architecture") for i in q.getresult(): - (id, name) = i - arches[id] = name - arch_ids[name] = id + (aid, name) = i + arches[aid] = name + arch_ids[name] = aid # Pre-create the dictionary for suite_id in suites.keys(): d[suite_id] = {} @@ -179,7 +180,7 @@ SELECT suite, count(suite) FROM src_associations GROUP BY suite;""") for suite in suite_list: suite_id = suite_ids[suite] suite_arches[suite_id] = {} - for arch in Cnf.ValueList("Suite::%s::Architectures" % (suite)): + for arch in database.get_suite_architectures(suite_id): suite_arches[suite_id][arch] = "" suite_id_list.append(suite_id) output_list = [ output_format(i) for i in suite_list ] @@ -213,27 +214,28 @@ SELECT suite, count(suite) FROM src_associations GROUP BY suite;""") def main (): global Cnf, projectB - Cnf = daklib.utils.get_conf() + Cnf = utils.get_conf() Arguments = [('h',"help","Stats::Options::Help")] for i in [ "help" ]: - if not Cnf.has_key("Stats::Options::%s" % (i)): - Cnf["Stats::Options::%s" % (i)] = "" + if not Cnf.has_key("Stats::Options::%s" % (i)): + Cnf["Stats::Options::%s" % (i)] = "" args = apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv) Options = Cnf.SubTree("Stats::Options") if Options["Help"]: - usage() + usage() if len(args) < 1: - daklib.utils.warn("dak stats requires a MODE argument") + utils.warn("dak stats requires a MODE argument") usage(1) elif len(args) > 1: - daklib.utils.warn("dak stats accepts only one MODE argument") + utils.warn("dak stats accepts only one MODE argument") usage(1) mode = args[0].lower() projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])) + database.init(Cnf, projectB) if mode == "arch-space": per_arch_space_use() @@ -242,11 +244,10 @@ def main (): elif mode == "daily-install": daily_install_stats() else: - daklib.utils.warn("unknown mode '%s'" % (mode)) + utils.warn("unknown mode '%s'" % (mode)) usage(1) ################################################################################ if __name__ == '__main__': main() -