]> git.decadent.org.uk Git - dak.git/blob - dak/override_disparity.py
Move common code to the new get_packages_from_ftp()
[dak.git] / dak / override_disparity.py
1 #!/usr/bin/env python
2
3 """
4 Generate a list of override disparities
5
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2010 Luca Falavigna <dktrkranz@debian.org>
8 @license: GNU General Public License version 2 or later
9 """
10
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
25 ################################################################################
26
27 # <adsb> Yay bugzilla *sigh*
28 # <phil> :)
29 # <Ganneff> quick, replace the bts with it
30 # * jcristau replaces dak with soyuz
31 # <adsb> and expects Ganneff to look after it?
32 # <jcristau> nah, elmo can do that
33 # * jcristau hides
34
35 ################################################################################
36
37 import os
38 import sys
39 import apt_pkg
40
41 from daklib.config import Config
42 from daklib.dbconn import *
43 from daklib import utils
44
45 ################################################################################
46
47 def usage (exit_code=0):
48     print """Generate a list of override disparities
49
50        Usage:
51        dak override-disparity [ -p <package> ] [ -s <suite> ]
52
53 Options:
54
55   -h, --help                show this help and exit
56   -p, --package             limit check on given package only
57   -s, --suite               choose suite to look for (default: unstable)"""
58
59     sys.exit(exit_code)
60
61 def main():
62     cnf = Config()
63     Arguments = [('h','help','Override-Disparity::Options::Help'),
64                  ('s','suite','Override-Disparity::Options::Suite','HasArg'),
65                  ('p','package','Override-Disparity::Options::Package','HasArg')]
66
67     for i in ['help', 'package']:
68         if not cnf.has_key('Override-Disparity::Options::%s' % (i)):
69             cnf['Override-Disparity::Options::%s' % (i)] = ''
70     if not cnf.has_key('Override-Disparity::Options::Suite'):
71         cnf['Override-Disparity::Options::Suite'] = 'unstable'
72
73     apt_pkg.ParseCommandLine(cnf.Cnf, Arguments, sys.argv)
74     Options = cnf.SubTree('Override-Disparity::Options')
75
76     if Options['help']:
77         usage()
78
79     depends = {}
80     session = DBConn().session()
81     suite = Options['suite']
82     components = cnf.ValueList('Suite::%s::Components' % suite)
83     arches = set([x.arch_string for x in get_suite_architectures(suite)])
84     arches -= set(['source', 'all'])
85     for arch in arches:
86         for component in components:
87             temp_filename = utils.get_packages_from_ftp(cnf['Dir::Root'], suite, component, arch)
88             packages_file = utils.open_file(temp_filename)
89             Packages = apt_pkg.ParseTagFile(packages_file)
90             while Packages.Step():
91                 package = Packages.Section.Find('Package')
92                 dep_list = Packages.Section.Find('Depends')
93                 if Options['package'] and package != Options['package']:
94                     continue
95                 if dep_list:
96                     for d in apt_pkg.ParseDepends(dep_list):
97                         for i in d:
98                             if not depends.has_key(package):
99                                 depends[package] = set()
100                             depends[package].add(i[0])
101             os.unlink(temp_filename)
102
103     priorities = {}
104     query = """SELECT DISTINCT o.package, p.level, p.priority, m.name
105                FROM override o
106                JOIN suite s ON s.id = o.suite
107                JOIN priority p ON p.id = o.priority
108                JOIN binaries b ON b.package = o.package
109                JOIN maintainer m ON m.id = b.maintainer
110                JOIN bin_associations ba ON ba.bin = b.id
111                WHERE s.suite_name = '%s'
112                AND ba.suite = s.id
113                AND p.level <> 0""" % suite
114     packages = session.execute(query)
115     session.commit()
116
117     for p in packages:
118         priorities[p[0]] = [p[1], p[2], p[3], True]
119     for d in sorted(depends.keys()):
120         for p in depends[d]:
121             if priorities.has_key(d) and priorities.has_key(p):
122                 if priorities[d][0] < priorities[p][0]:
123                      if priorities[d][3]:
124                          print 'Package: ' + d
125                          print ' Priority: ' + priorities[d][1]
126                          print ' Maintainer: ' + priorities[d][2]
127                          priorities[d][3] = False
128                      print ' Dependency: ' + p
129                      print '  Priority: ' + priorities[p][1]
130                      print '  Maintainer: ' + priorities[p][2]
131
132 if __name__ == '__main__':
133     main()