]> git.decadent.org.uk Git - dak.git/blob - daklib/cruft.py
Merge branch 'dbtests' into merge
[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
28 def newer_version(lowersuite_name, highersuite_name, session):
29     '''
30     Finds newer versions in lowersuite_name than in highersuite_name. Returns a
31     list of tuples (source, higherversion, lowerversion) where higherversion is
32     the newest version from highersuite_name and lowerversion is the newest
33     version from lowersuite_name.
34     '''
35
36     lowersuite = get_suite(lowersuite_name, session)
37     highersuite = get_suite(highersuite_name, session)
38
39     query = session.query(DBSource.source, func.max(DBSource.version)). \
40         with_parent(highersuite).group_by(DBSource.source)
41
42     list = []
43     for (source, higherversion) in query:
44         lowerversion = session.query(func.max(DBSource.version)). \
45             filter_by(source = source).filter(DBSource.version > higherversion). \
46             with_parent(lowersuite).group_by(DBSource.source).scalar()
47         if lowerversion is not None:
48             list.append((source, higherversion, lowerversion))
49     return list
50