]> git.decadent.org.uk Git - dak.git/blob - daklib/lists.py
Merge remote-tracking branch 'ansgar/package-set' into merge
[dak.git] / daklib / lists.py
1 #!/usr/bin/python
2
3 """
4 Helper functions for list generating commands (Packages, Sources).
5
6 @contact: Debian FTP Master <ftpmaster@debian.org>
7 @copyright: 2009-2011  Torsten Werner <twerner@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 def fetch(query, args, session):
28     for (id, path, filename) in session.execute(query, args).fetchall():
29         yield (id, path + filename)
30
31 def getSources(suite, component, session, timestamp = None):
32     '''
33     Calculates the sources in suite and component optionally limited by
34     sources newer than timestamp.  Returns a generator that yields a
35     tuple of source id and full pathname to the dsc file. See function
36     writeSourceList() in dak/generate_filelist.py for an example that
37     uses this function.
38     '''
39     extra_cond = ""
40     if timestamp:
41         extra_cond = "AND extract(epoch from sa.created) > %d" % timestamp
42     query = """
43         SELECT s.id, l.path, f.filename
44             FROM source s
45             JOIN src_associations sa
46                 ON s.id = sa.source AND sa.suite = :suite %s
47             JOIN files f
48                 ON s.file = f.id
49             JOIN location l
50                 ON f.location = l.id AND l.component = :component
51             ORDER BY filename
52     """ % extra_cond
53     args = { 'suite': suite.suite_id,
54              'component': component.component_id }
55     return fetch(query, args, session)
56
57 def getBinaries(suite, component, architecture, type, session, timestamp = None):
58     '''
59     Calculates the binaries in suite and component of architecture and
60     type 'deb' or 'udeb' optionally limited to binaries newer than
61     timestamp.  Returns a generator that yields a tuple of binary id and
62     full pathname to the u(deb) file. See function writeBinaryList() in
63     dak/generate_filelist.py for an example that uses this function.
64     '''
65     extra_cond = ""
66     if timestamp:
67         extra_cond = "AND extract(epoch from ba.created) > %d" % timestamp
68     query = """
69 CREATE TEMP TABLE b_candidates (
70     id integer,
71     source integer,
72     file integer,
73     architecture integer);
74
75 INSERT INTO b_candidates (id, source, file, architecture)
76     SELECT b.id, b.source, b.file, b.architecture
77         FROM binaries b
78         JOIN bin_associations ba ON b.id = ba.bin
79         WHERE b.type = :type AND ba.suite = :suite AND
80             b.architecture IN (2, :architecture) %s;
81
82 CREATE TEMP TABLE gf_candidates (
83     id integer,
84     filename text,
85     path text,
86     architecture integer,
87     src integer,
88     source text);
89
90 INSERT INTO gf_candidates (id, filename, path, architecture, src, source)
91     SELECT bc.id, f.filename, l.path, bc.architecture, bc.source as src, s.source
92         FROM b_candidates bc
93         JOIN source s ON bc.source = s.id
94         JOIN files f ON bc.file = f.id
95         JOIN location l ON f.location = l.id
96         WHERE l.component = :component;
97
98 WITH arch_any AS
99
100     (SELECT id, path, filename FROM gf_candidates
101         WHERE architecture > 2),
102
103      arch_all_with_any AS
104     (SELECT id, path, filename FROM gf_candidates
105         WHERE architecture = 2 AND
106               src IN (SELECT src FROM gf_candidates WHERE architecture > 2)),
107
108      arch_all_without_any AS
109     (SELECT id, path, filename FROM gf_candidates
110         WHERE architecture = 2 AND
111               source NOT IN (SELECT DISTINCT source FROM gf_candidates WHERE architecture > 2)),
112
113      filelist AS
114     (SELECT * FROM arch_any
115     UNION
116     SELECT * FROM arch_all_with_any
117     UNION
118     SELECT * FROM arch_all_without_any)
119
120     SELECT * FROM filelist ORDER BY filename
121     """ % extra_cond
122     args = { 'suite': suite.suite_id,
123              'component': component.component_id,
124              'architecture': architecture.arch_id,
125              'type': type }
126     return fetch(query, args, session)
127