]> git.donarmstrong.com Git - dak.git/blob - daklib/cruft.py
Remove old (and slow) code
[dak.git] / daklib / cruft.py
1 """
2 helper functions for cruft-report
3
4 @contact: Debian FTPMaster <ftpmaster@debian.org>
5 @copyright 2011 Torsten Werner <twerner@debian.org>
6 """
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21
22 ################################################################################
23
24 from daklib.dbconn import *
25
26 from sqlalchemy import func
27 from sqlalchemy.orm import object_session
28
29 def newer_version(lowersuite_name, highersuite_name, session):
30     '''
31     Finds newer versions in lowersuite_name than in highersuite_name. Returns a
32     list of tuples (source, higherversion, lowerversion) where higherversion is
33     the newest version from highersuite_name and lowerversion is the newest
34     version from lowersuite_name.
35     '''
36
37     lowersuite = get_suite(lowersuite_name, session)
38     highersuite = get_suite(highersuite_name, session)
39
40     query = session.query(DBSource.source, func.max(DBSource.version)). \
41         with_parent(highersuite).group_by(DBSource.source)
42
43     list = []
44     for (source, higherversion) in query:
45         lowerversion = session.query(func.max(DBSource.version)). \
46             filter_by(source = source).filter(DBSource.version > higherversion). \
47             with_parent(lowersuite).group_by(DBSource.source).scalar()
48         if lowerversion is not None:
49             list.append((source, higherversion, lowerversion))
50
51     list.sort()
52     return list
53
54 def get_package_names(suite):
55     '''
56     Returns a query that selects all distinct package names from suite ordered
57     by package name.
58     '''
59
60     session = object_session(suite)
61     return session.query(DBBinary.package).with_parent(suite). \
62         group_by(DBBinary.package).order_by(DBBinary.package)
63
64 class NamedSource(object):
65     '''
66     A source package identified by its name with all of its versions in a
67     suite.
68     '''
69     def __init__(self, suite, source):
70         self.source = source
71         query = suite.sources.filter_by(source = source). \
72             order_by(DBSource.version)
73         self.versions = [src.version for src in query]
74
75     def __str__(self):
76         return "%s(%s)" % (self.source, ", ".join(self.versions))
77
78 class DejavuBinary(object):
79     '''
80     A binary package identified by its name which gets built by multiple source
81     packages in a suite. The architecture is ignored which leads to the
82     following corner case, e.g.:
83
84     If a source package 'foo-mips' that builds a binary package 'foo' on mips
85     and another source package 'foo-mipsel' builds a binary package with the
86     same name 'foo' on mipsel then the binary package 'foo' will be reported as
87     built from multiple source packages.
88     '''
89
90     def __init__(self, suite, package):
91         self.package = package
92         session = object_session(suite)
93         # We need a subquery to make sure that both binary and source packages
94         # are in the right suite.
95         bin_query = suite.binaries.filter_by(package = package).subquery()
96         src_query = session.query(DBSource.source).with_parent(suite). \
97             join(bin_query).order_by(DBSource.source).group_by(DBSource.source)
98         self.sources = []
99         if src_query.count() > 1:
100             for source, in src_query:
101                 self.sources.append(str(NamedSource(suite, source)))
102
103     def has_multiple_sources(self):
104         'Has the package been built by multiple sources?'
105         return len(self.sources) > 1
106
107     def __str__(self):
108         return "%s built by: %s" % (self.package, ", ".join(self.sources))
109
110 def report_multiple_source(suite):
111     '''
112     Reports binary packages built from multiple source package with different
113     names.
114     '''
115
116     print "Built from multiple source packages"
117     print "-----------------------------------"
118     print
119     for package, in get_package_names(suite):
120         binary = DejavuBinary(suite, package)
121         if binary.has_multiple_sources():
122             print binary
123     print