]> git.decadent.org.uk Git - dak.git/blob - dak/compare_suites.py
0eb458a6c0948d2e74e2d11a1d592a9d0866a251
[dak.git] / dak / compare_suites.py
1 #!/usr/bin/env python
2
3 # Check for fixable discrepancies between stable and unstable
4 # Copyright (C) 2000, 2001, 2002, 2003, 2006  James Troup <james@nocrew.org>
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20
21 ################################################################################
22
23 import pg, sys
24 import dak.lib.utils, dak.lib.database
25 import apt_pkg
26
27 ################################################################################
28
29 Cnf = None
30 projectB = None
31
32 ################################################################################
33
34 def usage(exit_code=0):
35     print """Usage: dak compare-suites
36 Looks for fixable descrepancies between stable and unstable.
37
38   -h, --help                show this help and exit."""
39     sys.exit(exit_code)
40
41 ################################################################################
42
43 def main ():
44     global Cnf, projectB
45
46     Cnf = dak.lib.utils.get_conf()
47     Arguments = [('h',"help","Compare-Suites::Options::Help")]
48     for i in [ "help" ]:
49         if not Cnf.has_key("Compare-Suites::Options::%s" % (i)):
50             Cnf["Compare-Suites::Options::%s" % (i)] = ""
51
52     apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)
53
54     Options = Cnf.SubTree("Compare-Suites::Options")
55     if Options["Help"]:
56         usage()
57
58     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]))
59     dak.lib.database.init(Cnf, projectB)
60
61     src_suite = "stable"
62     dst_suite = "unstable"
63
64     src_suite_id = dak.lib.database.get_suite_id(src_suite)
65     dst_suite_id = dak.lib.database.get_suite_id(dst_suite)
66     arch_all_id = dak.lib.database.get_architecture_id("all")
67     dsc_type_id = dak.lib.database.get_override_type_id("dsc")
68
69     for arch in Cnf.ValueList("Suite::%s::Architectures" % (src_suite)):
70         if arch == "source":
71             continue
72
73         # Arch: all doesn't work; consider packages which go from
74         # arch: all to arch: any, e.g. debconf... needs more checks
75         # and thought later.
76
77         if arch == "all":
78             continue
79         arch_id = dak.lib.database.get_architecture_id(arch)
80         q = projectB.query("""
81 SELECT b_src.package, b_src.version, a.arch_string
82   FROM binaries b_src, bin_associations ba, override o, architecture a
83   WHERE ba.bin = b_src.id AND ba.suite = %s AND b_src.architecture = %s
84         AND a.id = b_src.architecture AND o.package = b_src.package
85         AND o.suite = %s AND o.type != %s AND NOT EXISTS
86     (SELECT 1 FROM bin_associations ba2, binaries b_dst
87        WHERE ba2.bin = b_dst.id AND b_dst.package = b_src.package
88              AND (b_dst.architecture = %s OR b_dst.architecture = %s)
89              AND ba2.suite = %s AND EXISTS
90                (SELECT 1 FROM bin_associations ba3, binaries b2
91                   WHERE ba3.bin = b2.id AND ba3.suite = %s AND b2.package = b_dst.package))
92 ORDER BY b_src.package;"""
93                            % (src_suite_id, arch_id, dst_suite_id, dsc_type_id, arch_id, arch_all_id, dst_suite_id, dst_suite_id))
94         for i in q.getresult():
95             print " ".join(i)
96
97 #######################################################################################
98
99 if __name__ == '__main__':
100     main()
101