5 Adding a trainee field to the process-new notes
7 @contact: Debian FTP Master <ftpmaster@debian.org>
8 @copyright: 2009 Mike O'Connor <stew@debian.org>
9 @license: GNU General Public License version 2 or later
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ################################################################################
29 ################################################################################
33 from daklib.dak_exceptions import DBUpdateError
35 ################################################################################
39 return a list of suites to operate on
41 if Config().has_key( "%s::%s" %(options_prefix,"Suite")):
42 suites = utils.split_args(Config()[ "%s::%s" %(options_prefix,"Suite")])
44 suites = [ 'unstable', 'testing' ]
45 # suites = Config().SubTree("Suite").List()
49 def arches(cursor, suite):
51 return a list of archs to operate on
54 cursor.execute("""SELECT s.architecture, a.arch_string
55 FROM suite_architectures s
56 JOIN architecture a ON (s.architecture=a.id)
57 WHERE suite = :suite""", {'suite' : suite })
64 if r[1] != "source" and r[1] != "all":
65 arch_list.append((r[0], r[1]))
71 Adding contents table as first step to maybe, finally getting rid
80 c.execute("""CREATE TABLE pending_bin_contents (
82 package text NOT NULL,
83 version debversion NOT NULL,
85 filename text NOT NULL,
87 PRIMARY KEY(id))""" );
89 c.execute("""CREATE TABLE deb_contents (
98 c.execute("""CREATE TABLE udeb_contents (
105 component text )""" )
107 c.execute("""ALTER TABLE ONLY deb_contents
108 ADD CONSTRAINT deb_contents_arch_fkey
109 FOREIGN KEY (arch) REFERENCES architecture(id)
110 ON DELETE CASCADE;""")
112 c.execute("""ALTER TABLE ONLY udeb_contents
113 ADD CONSTRAINT udeb_contents_arch_fkey
114 FOREIGN KEY (arch) REFERENCES architecture(id)
115 ON DELETE CASCADE;""")
117 c.execute("""ALTER TABLE ONLY deb_contents
118 ADD CONSTRAINT deb_contents_pkey
119 PRIMARY KEY (filename,package,arch,suite);""")
121 c.execute("""ALTER TABLE ONLY udeb_contents
122 ADD CONSTRAINT udeb_contents_pkey
123 PRIMARY KEY (filename,package,arch,suite);""")
125 c.execute("""ALTER TABLE ONLY deb_contents
126 ADD CONSTRAINT deb_contents_suite_fkey
127 FOREIGN KEY (suite) REFERENCES suite(id)
128 ON DELETE CASCADE;""")
130 c.execute("""ALTER TABLE ONLY udeb_contents
131 ADD CONSTRAINT udeb_contents_suite_fkey
132 FOREIGN KEY (suite) REFERENCES suite(id)
133 ON DELETE CASCADE;""")
135 c.execute("""ALTER TABLE ONLY deb_contents
136 ADD CONSTRAINT deb_contents_binary_fkey
137 FOREIGN KEY (binary_id) REFERENCES binaries(id)
138 ON DELETE CASCADE;""")
140 c.execute("""ALTER TABLE ONLY udeb_contents
141 ADD CONSTRAINT udeb_contents_binary_fkey
142 FOREIGN KEY (binary_id) REFERENCES binaries(id)
143 ON DELETE CASCADE;""")
145 c.execute("""CREATE INDEX ind_deb_contents_binary ON deb_contents(binary_id);""" )
148 suites = self.suites()
150 for suite in [i.lower() for i in suites]:
151 suite_id = DBConn().get_suite_id(suite)
152 arch_list = arches(c, suite_id)
153 arch_list = arches(c, suite_id)
155 for (arch_id,arch_str) in arch_list:
156 c.execute( "CREATE INDEX ind_deb_contents_%s_%s ON deb_contents (arch,suite) WHERE (arch=2 OR arch=%d) AND suite=$d"%(arch_str,suite,arch_id,suite_id) )
158 for section, sname in [("debian-installer","main"),
159 ("non-free/debian-installer", "nonfree")]:
160 c.execute( "CREATE INDEX ind_udeb_contents_%s_%s ON udeb_contents (section,suite) WHERE section=%s AND suite=$d"%(sname,suite,section,suite_id) )
163 c.execute( """CREATE OR REPLACE FUNCTION update_contents_for_bin_a() RETURNS trigger AS $$
165 if event == "DELETE" or event == "UPDATE":
167 plpy.execute(plpy.prepare("DELETE FROM deb_contents WHERE binary_id=$1 and suite=$2",
169 [TD["old"]["bin"], TD["old"]["suite"]])
171 if event == "INSERT" or event == "UPDATE":
173 content_data = plpy.execute(plpy.prepare(
174 """SELECT s.section, b.package, b.architecture, c.name, ot.type
176 JOIN override_type ot on o.type=ot.id
177 JOIN binaries b on b.package=o.package
178 JOIN files f on b.file=f.id
179 JOIN location l on l.id=f.location
180 JOIN section s on s.id=o.section
181 JOIN component c on c.id=l.component
186 [TD["new"]["bin"], TD["new"]["suite"]])[0]
189 if not content_data["name"] === "main":
190 component_str=content_data["name"]+"/"
192 filenames = plpy.execute(plpy.prepare(
193 "SELECT bc.file FROM bin_contents bc where bc.binary_id=$1",
197 for filename in filenames:
198 plpy.execute(plpy.prepare(
199 """INSERT INTO deb_contents
200 (file,section,package,binary_id,arch,suite,component)
201 VALUES($1,$2,$3,$4,$5,$6,$7)""",
202 ["text","text","text","int","int","int","text"]),
203 [filename["filename"],
204 content_data["section"],
205 content_data["package"],
207 content_data["architecture"],
210 $$ LANGUAGE plpythonu VOLATILE SECURITY DEFINER;
214 c.execute( """CREATE OR REPLACE FUNCTION update_contents_for_override() RETURNS trigger AS $$
216 if event == "UPDATE":
218 otype = plpy.execute(plpy.prepare("SELECT type from override_type where id=$1",["int"]),TD["new"]["type"] )[0];
219 if otype["type"].endswith("deb"):
220 table_name = "%s_contents" % otype["type"]
221 plpy.execute(plpy.prepare("UPDATE %s set sections=$1" % table_name
223 [TD["new"]["section"]])
225 $$ LANGUAGE plpythonu VOLATILE SECURITY DEFINER;
227 c.execute( """CREATE TRIGGER bin_associations_contents_trigger
228 AFTER INSERT OR UPDATE OR DELETE ON bin_associations
229 FOR EACH ROW EXECUTE PROCEDURE update_contents_for_bin_a();""")
230 c.execute("""CREATE TRIGGER override_contents_trigger
231 AFTER UPDATE ON override
232 FOR EACH ROW EXECUTE PROCEDURE update_contents_for_override();""")
236 except psycopg2.ProgrammingError, msg:
238 raise DBUpdateError, "Unable to apply process-new update 14, rollback issued. Error message : %s" % (str(msg))