]> git.decadent.org.uk Git - dak.git/blob - daklib/lists.py
e7f8bf968c442f3f094285d00a23566d310bb031
[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 from dbconn import get_architecture
28
29 def fetch(query, args, session):
30     for (id, path, filename) in session.execute(query, args).fetchall():
31         yield (id, path + filename)
32
33 def getSources(suite, component, session, timestamp = None):
34     '''
35     Calculates the sources in suite and component optionally limited by
36     sources newer than timestamp.  Returns a generator that yields a
37     tuple of source id and full pathname to the dsc file. See function
38     writeSourceList() in dak/generate_filelist.py for an example that
39     uses this function.
40     '''
41     extra_cond = ""
42     if timestamp:
43         extra_cond = "AND extract(epoch from sa.created) > %d" % timestamp
44     query = """
45         SELECT s.id, l.path, f.filename
46             FROM source s
47             JOIN src_associations sa
48                 ON s.id = sa.source AND sa.suite = :suite %s
49             JOIN files f
50                 ON s.file = f.id
51             JOIN location l
52                 ON f.location = l.id AND l.component = :component
53             ORDER BY filename
54     """ % extra_cond
55     args = { 'suite': suite.suite_id,
56              'component': component.component_id }
57     return fetch(query, args, session)
58
59 def getArchAll(suite, component, architecture, type, session, timestamp = None):
60     '''
61     Calculates all binaries in suite and component of architecture 'all' (and
62     only 'all') and type 'deb' or 'udeb' optionally limited to binaries newer
63     than timestamp.  Returns a generator that yields a tuple of binary id and
64     full pathname to the u(deb) file. See function writeAllList() in
65     dak/generate_filelist.py for an example that uses this function.
66     '''
67     query = suite.binaries.filter_by(architecture = architecture, binarytype = type)
68     if timestamp is not None:
69         extra_cond = 'extract(epoch from bin_associations.created) > %d' % timestamp
70         query = query.filter(extra_cond)
71     for binary in query:
72         yield (binary.binary_id, binary.poolfile.fullpath)
73
74 def getBinaries(suite, component, architecture, type, session, timestamp = None):
75     '''
76     Calculates the binaries in suite and component of architecture and
77     type 'deb' or 'udeb' optionally limited to binaries newer than
78     timestamp.  Returns a generator that yields a tuple of binary id and
79     full pathname to the u(deb) file. See function writeBinaryList() in
80     dak/generate_filelist.py for an example that uses this function.
81     '''
82     extra_cond = ""
83     if timestamp:
84         extra_cond = "AND extract(epoch from ba.created) > %d" % timestamp
85     query = """
86 CREATE TEMP TABLE b_candidates (
87     id integer,
88     source integer,
89     file integer,
90     architecture integer);
91
92 INSERT INTO b_candidates (id, source, file, architecture)
93     SELECT b.id, b.source, b.file, b.architecture
94         FROM binaries b
95         JOIN bin_associations ba ON b.id = ba.bin
96         WHERE b.type = :type AND ba.suite = :suite AND
97             b.architecture IN (:arch_all, :architecture) %s;
98
99 CREATE TEMP TABLE gf_candidates (
100     id integer,
101     filename text,
102     path text,
103     architecture integer,
104     src integer,
105     source text);
106
107 INSERT INTO gf_candidates (id, filename, path, architecture, src, source)
108     SELECT bc.id, f.filename, l.path, bc.architecture, bc.source as src, s.source
109         FROM b_candidates bc
110         JOIN source s ON bc.source = s.id
111         JOIN files f ON bc.file = f.id
112         JOIN location l ON f.location = l.id
113         WHERE l.component = :component;
114
115 WITH arch_any AS
116
117     (SELECT id, path, filename FROM gf_candidates
118         WHERE architecture <> :arch_all),
119
120      arch_all_with_any AS
121     (SELECT id, path, filename FROM gf_candidates
122         WHERE architecture = :arch_all AND
123               src IN (SELECT src FROM gf_candidates WHERE architecture <> :arch_all)),
124
125      arch_all_without_any AS
126     (SELECT id, path, filename FROM gf_candidates
127         WHERE architecture = :arch_all AND
128               source NOT IN (SELECT DISTINCT source FROM gf_candidates WHERE architecture <> :arch_all)),
129
130      filelist AS
131     (SELECT * FROM arch_any
132     UNION
133     SELECT * FROM arch_all_with_any
134     UNION
135     SELECT * FROM arch_all_without_any)
136
137     SELECT * FROM filelist ORDER BY filename
138     """ % extra_cond
139     args = { 'suite': suite.suite_id,
140              'component': component.component_id,
141              'architecture': architecture.arch_id,
142              'arch_all': get_architecture('all', session).arch_id,
143              'type': type }
144     return fetch(query, args, session)
145