2 helper functions for cruft-report
4 @contact: Debian FTPMaster <ftpmaster@debian.org>
5 @copyright 2011 Torsten Werner <twerner@debian.org>
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.
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.
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
22 ################################################################################
24 from daklib.dbconn import *
26 from sqlalchemy import func
27 from sqlalchemy.orm import object_session
29 def newer_version(lowersuite_name, highersuite_name, session):
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.
37 lowersuite = get_suite(lowersuite_name, session)
38 highersuite = get_suite(highersuite_name, session)
40 query = session.query(DBSource.source, func.max(DBSource.version)). \
41 with_parent(highersuite).group_by(DBSource.source)
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))
54 def get_package_names(suite):
56 Returns a query that selects all distinct package names from suite ordered
60 session = object_session(suite)
61 return session.query(DBBinary.package).with_parent(suite). \
62 group_by(DBBinary.package).order_by(DBBinary.package)
64 class NamedSource(object):
66 A source package identified by its name with all of its versions in a
69 def __init__(self, suite, source):
71 query = suite.sources.filter_by(source = source). \
72 order_by(DBSource.version)
73 self.versions = [src.version for src in query]
76 return "%s(%s)" % (self.source, ", ".join(self.versions))
78 class DejavuBinary(object):
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.:
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.
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)
99 if src_query.count() > 1:
100 for source, in src_query:
101 self.sources.append(str(NamedSource(suite, source)))
103 def has_multiple_sources(self):
104 'Has the package been built by multiple sources?'
105 return len(self.sources) > 1
108 return "%s built by: %s" % (self.package, ", ".join(self.sources))
110 def report_multiple_source(suite):
112 Reports binary packages built from multiple source package with different
116 print "Built from multiple source packages"
117 print "-----------------------------------"
119 for package, in get_package_names(suite):
120 binary = DejavuBinary(suite, package)
121 if binary.has_multiple_sources():