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