]> git.decadent.org.uk Git - dak.git/blob - neve
Suite::%s::{Architectures,Components}, OverrideType, Section, Location::%s::Suites...
[dak.git] / neve
1 #!/usr/bin/env python
2
3 # Populate the DB
4 # Copyright (C) 2000, 2001, 2002  James Troup <james@nocrew.org>
5 # $Id: neve,v 1.10 2002-05-14 15:28:53 troup Exp $
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 ###############################################################################
22
23 # 04:36|<aj> elmo: you're making me waste 5 seconds per architecture!!!!!! YOU BASTARD!!!!!
24
25 ###############################################################################
26
27 # This code is a horrible mess for two reasons:
28
29 #   (o) For Debian's usage, it's doing something like 160k INSERTs,
30 #   even on auric, that makes the program unusable unless we get
31 #   involed in sorts of silly optimization games (local dicts to avoid
32 #   redundant SELECTS, using COPY FROM rather than INSERTS etc.)
33
34 #   (o) It's very site specific, because I don't expect to use this
35 #   script again in a hurry, and I don't want to spend any more time
36 #   on it than absolutely necessary.
37
38 ###############################################################################
39
40 import commands, os, pg, re, select, string, sys, tempfile, time;
41 import apt_pkg;
42 import db_access, utils;
43
44 ###############################################################################
45
46 re_arch_from_filename = re.compile(r"binary-[^/]+")
47
48 ###############################################################################
49
50 Cnf = None;
51 projectB = None;
52 files_id_cache = {};
53 source_cache = {};
54 arch_all_cache = {};
55 binary_cache = {};
56 #
57 files_id_serial = 0;
58 source_id_serial = 0;
59 src_associations_id_serial = 0;
60 dsc_files_id_serial = 0;
61 files_query_cache = None;
62 source_query_cache = None;
63 src_associations_query_cache = None;
64 dsc_files_query_cache = None;
65 orig_tar_gz_cache = {};
66 #
67 binaries_id_serial = 0;
68 binaries_query_cache = None;
69 bin_associations_id_serial = 0;
70 bin_associations_query_cache = None;
71 #
72 source_cache_for_binaries = {};
73 reject_message = "";
74
75 ###############################################################################
76
77 # Our very own version of commands.getouputstatus(), hacked to support
78 # gpgv's status fd.
79 def get_status_output(cmd, status_read, status_write):
80     cmd = ['/bin/sh', '-c', cmd];
81     p2cread, p2cwrite = os.pipe();
82     c2pread, c2pwrite = os.pipe();
83     errout, errin = os.pipe();
84     pid = os.fork();
85     if pid == 0:
86         # Child
87         os.close(0);
88         os.close(1);
89         os.dup(p2cread);
90         os.dup(c2pwrite);
91         os.close(2);
92         os.dup(errin);
93         for i in range(3, 256):
94             if i != status_write:
95                 try:
96                     os.close(i);
97                 except:
98                     pass;
99         try:
100             os.execvp(cmd[0], cmd);
101         finally:
102             os._exit(1);
103
104     # parent
105     os.close(p2cread)
106     os.dup2(c2pread, c2pwrite);
107     os.dup2(errout, errin);
108
109     output = status = "";
110     while 1:
111         i, o, e = select.select([c2pwrite, errin, status_read], [], []);
112         more_data = [];
113         for fd in i:
114             r = os.read(fd, 8196);
115             if len(r) > 0:
116                 more_data.append(fd);
117                 if fd == c2pwrite or fd == errin:
118                     output = output + r;
119                 elif fd == status_read:
120                     status = status + r;
121                 else:
122                     utils.fubar("Unexpected file descriptor [%s] returned from select\n" % (fd));
123         if not more_data:
124             pid, exit_status = os.waitpid(pid, 0)
125             try:
126                 os.close(status_write);
127                 os.close(status_read);
128                 os.close(c2pwrite);
129                 os.close(p2cwrite);
130                 os.close(errin);
131             except:
132                 pass;
133             break;
134
135     return output, status, exit_status;
136
137 ###############################################################################
138
139 def Dict(**dict): return dict
140
141 def reject (str, prefix="Rejected: "):
142     global reject_message;
143     if str:
144         reject_message = reject_message + prefix + str + "\n";
145
146 ###############################################################################
147
148 def check_signature (filename):
149     if not utils.re_taint_free.match(os.path.basename(filename)):
150         reject("!!WARNING!! tainted filename: '%s'." % (filename));
151         return 0;
152
153     status_read, status_write = os.pipe();
154     cmd = "gpgv --status-fd %s --keyring %s --keyring %s %s" \
155           % (status_write, Cnf["Dinstall::PGPKeyring"], Cnf["Dinstall::GPGKeyring"], filename);
156     (output, status, exit_status) = get_status_output(cmd, status_read, status_write);
157
158     # Process the status-fd output
159     keywords = {};
160     bad = internal_error = "";
161     for line in string.split(status, '\n'):
162         line = string.strip(line);
163         if line == "":
164             continue;
165         split = string.split(line);
166         if len(split) < 2:
167             internal_error = internal_error + "gpgv status line is malformed (< 2 atoms) ['%s'].\n" % (line);
168             continue;
169         (gnupg, keyword) = split[:2];
170         if gnupg != "[GNUPG:]":
171             internal_error = internal_error + "gpgv status line is malformed (incorrect prefix '%s').\n" % (gnupg);
172             continue;
173         args = split[2:];
174         if keywords.has_key(keyword) and keyword != "NODATA":
175             internal_error = internal_error + "found duplicate status token ('%s')." % (keyword);
176             continue;
177         else:
178             keywords[keyword] = args;
179
180     # If we failed to parse the status-fd output, let's just whine and bail now
181     if internal_error:
182         reject("internal error while performing signature check on %s." % (filename));
183         reject(internal_error, "");
184         reject("Please report the above errors to the Archive maintainers by replying to this mail.", "");
185         return None;
186
187     # Now check for obviously bad things in the processed output
188     if keywords.has_key("SIGEXPIRED"):
189         reject("key used to sign %s has expired." % (filename));
190         bad = 1;
191     if keywords.has_key("KEYREVOKED"):
192         reject("key used to sign %s has been revoked." % (filename));
193         bad = 1;
194     if keywords.has_key("BADSIG"):
195         reject("bad signature on %s." % (filename));
196         bad = 1;
197     if keywords.has_key("ERRSIG") and not keywords.has_key("NO_PUBKEY"):
198         reject("failed to check signature on %s." % (filename));
199         bad = 1;
200     if keywords.has_key("NO_PUBKEY"):
201         args = keywords["NO_PUBKEY"];
202         if len(args) < 1:
203             reject("internal error while checking signature on %s." % (filename));
204             bad = 1;
205         else:
206             fingerprint = args[0];
207     if keywords.has_key("BADARMOR"):
208         reject("ascii armour of signature was corrupt in %s." % (filename));
209         bad = 1;
210     if keywords.has_key("NODATA"):
211         utils.warn("no signature found for %s." % (filename));
212         return "NOSIG";
213         #reject("no signature found in %s." % (filename));
214         #bad = 1;
215
216     if bad:
217         return None;
218
219     # Next check gpgv exited with a zero return code
220     if exit_status and not keywords.has_key("NO_PUBKEY"):
221         reject("gpgv failed while checking %s." % (filename));
222         if string.strip(status):
223             reject(utils.prefix_multi_line_string(status, " [GPG status-fd output:] "), "");
224         else:
225             reject(utils.prefix_multi_line_string(output, " [GPG output:] "), "");
226         return None;
227
228     # Sanity check the good stuff we expect
229     if not keywords.has_key("VALIDSIG"):
230         if not keywords.has_key("NO_PUBKEY"):
231             reject("signature on %s does not appear to be valid [No VALIDSIG]." % (filename));
232             bad = 1;
233     else:
234         args = keywords["VALIDSIG"];
235         if len(args) < 1:
236             reject("internal error while checking signature on %s." % (filename));
237             bad = 1;
238         else:
239             fingerprint = args[0];
240     if not keywords.has_key("GOODSIG") and not keywords.has_key("NO_PUBKEY"):
241         reject("signature on %s does not appear to be valid [No GOODSIG]." % (filename));
242         bad = 1;
243     if not keywords.has_key("SIG_ID") and not keywords.has_key("NO_PUBKEY"):
244         reject("signature on %s does not appear to be valid [No SIG_ID]." % (filename));
245         bad = 1;
246
247     # Finally ensure there's not something we don't recognise
248     known_keywords = Dict(VALIDSIG="",SIG_ID="",GOODSIG="",BADSIG="",ERRSIG="",
249                           SIGEXPIRED="",KEYREVOKED="",NO_PUBKEY="",BADARMOR="",
250                           NODATA="");
251
252     for keyword in keywords.keys():
253         if not known_keywords.has_key(keyword):
254             reject("found unknown status token '%s' from gpgv with args '%s' in %s." % (keyword, repr(keywords[keyword]), filename));
255             bad = 1;
256
257     if bad:
258         return None;
259     else:
260         return fingerprint;
261
262 #########################################################################################
263
264 # Prepares a filename or directory (s) to be file.filename by stripping any part of the location (sub) from it.
265 def poolify (s, sub):
266     for i in xrange(len(sub)):
267         if sub[i:] == s[0:len(sub)-i]:
268             return s[len(sub)-i:];
269     return s;
270
271 def update_archives ():
272     projectB.query("DELETE FROM archive")
273     for archive in Cnf.SubTree("Archive").List():
274         SubSec = Cnf.SubTree("Archive::%s" % (archive));
275         projectB.query("INSERT INTO archive (name, origin_server, description) VALUES ('%s', '%s', '%s')"
276                        % (archive, SubSec["OriginServer"], SubSec["Description"]));
277
278 def update_components ():
279     projectB.query("DELETE FROM component")
280     for component in Cnf.SubTree("Component").List():
281         SubSec = Cnf.SubTree("Component::%s" % (component));
282         projectB.query("INSERT INTO component (name, description, meets_dfsg) VALUES ('%s', '%s', '%s')" %
283                        (component, SubSec["Description"], SubSec["MeetsDFSG"]));
284
285 def update_locations ():
286     projectB.query("DELETE FROM location")
287     for location in Cnf.SubTree("Location").List():
288         SubSec = Cnf.SubTree("Location::%s" % (location));
289         archive_id = db_access.get_archive_id(SubSec["archive"]);
290         type = SubSec.Find("type");
291         if type == "legacy-mixed":
292             projectB.query("INSERT INTO location (path, archive, type) VALUES ('%s', %d, '%s')" % (location, archive_id, SubSec["type"]));
293         else:
294             for component in Cnf.SubTree("Component").List():
295                 component_id = db_access.get_component_id(component);
296                 projectB.query("INSERT INTO location (path, component, archive, type) VALUES ('%s', %d, %d, '%s')" %
297                                (location, component_id, archive_id, SubSec["type"]));
298
299 def update_architectures ():
300     projectB.query("DELETE FROM architecture")
301     for arch in Cnf.SubTree("Architectures").List():
302         projectB.query("INSERT INTO architecture (arch_string, description) VALUES ('%s', '%s')" % (arch, Cnf["Architectures::%s" % (arch)]))
303
304 def update_suites ():
305     projectB.query("DELETE FROM suite")
306     for suite in Cnf.SubTree("Suite").List():
307         SubSec = Cnf.SubTree("Suite::%s" %(suite))
308         projectB.query("INSERT INTO suite (suite_name) VALUES ('%s')" % string.lower(suite));
309         for i in ("Version", "Origin", "Description"):
310             if SubSec.has_key(i):
311                 projectB.query("UPDATE suite SET %s = '%s' WHERE suite_name = '%s'" % (string.lower(i), SubSec[i], string.lower(suite)))
312         for architecture in Cnf.ValueList("Suite::%s::Architectures" % (suite)):
313             architecture_id = db_access.get_architecture_id (architecture);
314             projectB.query("INSERT INTO suite_architectures (suite, architecture) VALUES (currval('suite_id_seq'), %d)" % (architecture_id));
315
316 ###############################################################################
317
318 def get_or_set_files_id (filename, size, md5sum, location_id):
319     global files_id_cache, files_id_serial, files_query_cache;
320
321     cache_key = string.join((filename, size, md5sum, repr(location_id)), '~')
322     if not files_id_cache.has_key(cache_key):
323         files_id_serial = files_id_serial + 1
324         files_query_cache.write("%d\t%s\t%s\t%s\t%d\n" % (files_id_serial, filename, size, md5sum, location_id));
325         files_id_cache[cache_key] = files_id_serial
326
327     return files_id_cache[cache_key]
328
329 ###############################################################################
330
331 def process_sources (location, filename, suite, component, archive, dsc_dir):
332     global source_cache, source_query_cache, src_associations_query_cache, dsc_files_query_cache, source_id_serial, src_associations_id_serial, dsc_files_id_serial, source_cache_for_binaries, orig_tar_gz_cache, reject_message;
333
334     suite = string.lower(suite);
335     suite_id = db_access.get_suite_id(suite);
336     if suite == 'stable':
337         testing_id = db_access.get_suite_id("testing");
338     try:
339         file = utils.open_file (filename);
340     except utils.cant_open_exc:
341         print "WARNING: can't open '%s'" % (filename);
342         return;
343     Scanner = apt_pkg.ParseTagFile(file);
344     while Scanner.Step() != 0:
345         package = Scanner.Section["package"];
346         version = Scanner.Section["version"];
347         dsc_file = os.path.join(dsc_dir, "%s_%s.dsc" % (package, utils.re_no_epoch.sub('', version)));
348         install_date = time.strftime("%Y-%m-%d", time.localtime(os.path.getmtime(dsc_file)));
349         fingerprint = check_signature(dsc_file);
350         fingerprint_id = db_access.get_or_set_fingerprint_id(fingerprint);
351         if reject_message:
352             utils.fubar("%s: %s" % (dsc_file, reject_message));
353         maintainer = Scanner.Section["maintainer"]
354         maintainer = string.replace(maintainer, "'", "\\'");
355         maintainer_id = db_access.get_or_set_maintainer_id(maintainer);
356         directory = Scanner.Section["directory"];
357         location_id = db_access.get_location_id (location, component, archive);
358         if directory[-1:] != "/":
359             directory = directory + '/';
360         directory = poolify (directory, location);
361         if directory != "" and directory[-1:] != "/":
362             directory = directory + '/';
363         no_epoch_version = utils.re_no_epoch.sub('', version);
364         # Add all files referenced by the .dsc to the files table
365         ids = [];
366         for line in string.split(Scanner.Section["files"],'\n'):
367             id = None;
368             (md5sum, size, filename) = string.split(string.strip(line));
369             # Don't duplicate .orig.tar.gz's
370             if filename[-12:] == ".orig.tar.gz":
371                 cache_key = "%s~%s~%s" % (filename, size, md5sum);
372                 if orig_tar_gz_cache.has_key(cache_key):
373                     id = orig_tar_gz_cache[cache_key];
374                 else:
375                     id = get_or_set_files_id (directory + filename, size, md5sum, location_id);
376                     orig_tar_gz_cache[cache_key] = id;
377             else:
378                 id = get_or_set_files_id (directory + filename, size, md5sum, location_id);
379             ids.append(id);
380             # If this is the .dsc itself; save the ID for later.
381             if filename[-4:] == ".dsc":
382                 files_id = id;
383         filename = directory + package + '_' + no_epoch_version + '.dsc'
384         cache_key = "%s~%s" % (package, version);
385         if not source_cache.has_key(cache_key):
386             nasty_key = "%s~%s" % (package, version)
387             source_id_serial = source_id_serial + 1;
388             if not source_cache_for_binaries.has_key(nasty_key):
389                 source_cache_for_binaries[nasty_key] = source_id_serial;
390             tmp_source_id = source_id_serial;
391             source_cache[cache_key] = source_id_serial;
392             source_query_cache.write("%d\t%s\t%s\t%d\t%d\t%s\t%s\n" % (source_id_serial, package, version, maintainer_id, files_id, install_date, fingerprint_id))
393             for id in ids:
394                 dsc_files_id_serial = dsc_files_id_serial + 1;
395                 dsc_files_query_cache.write("%d\t%d\t%d\n" % (dsc_files_id_serial, tmp_source_id,id));
396         else:
397             tmp_source_id = source_cache[cache_key];
398
399         src_associations_id_serial = src_associations_id_serial + 1;
400         src_associations_query_cache.write("%d\t%d\t%d\n" % (src_associations_id_serial, suite_id, tmp_source_id))
401         # populate 'testing' with a mirror of 'stable'
402         if suite == "stable":
403             src_associations_id_serial = src_associations_id_serial + 1;
404             src_associations_query_cache.write("%d\t%d\t%d\n" % (src_associations_id_serial, testing_id, tmp_source_id))
405
406     file.close();
407
408 ###############################################################################
409
410 def process_packages (location, filename, suite, component, archive):
411     global arch_all_cache, binary_cache, binaries_id_serial, binaries_query_cache, bin_associations_id_serial, bin_associations_query_cache, reject_message;
412
413     count_total = 0;
414     count_bad = 0;
415     suite = string.lower(suite);
416     suite_id = db_access.get_suite_id(suite);
417     if suite == "stable":
418         testing_id = db_access.get_suite_id("testing");
419     try:
420         file = utils.open_file (filename);
421     except utils.cant_open_exc:
422         print "WARNING: can't open '%s'" % (filename);
423         return;
424     Scanner = apt_pkg.ParseTagFile(file);
425     while Scanner.Step() != 0:
426         package = Scanner.Section["package"]
427         version = Scanner.Section["version"]
428         maintainer = Scanner.Section["maintainer"]
429         maintainer = string.replace(maintainer, "'", "\\'")
430         maintainer_id = db_access.get_or_set_maintainer_id(maintainer);
431         architecture = Scanner.Section["architecture"]
432         architecture_id = db_access.get_architecture_id (architecture);
433         fingerprint = "NOSIG";
434         fingerprint_id = db_access.get_or_set_fingerprint_id(fingerprint);
435         if not Scanner.Section.has_key("source"):
436             source = package
437         else:
438             source = Scanner.Section["source"]
439         source_version = ""
440         if string.find(source, "(") != -1:
441             m = utils.re_extract_src_version.match(source)
442             source = m.group(1)
443             source_version = m.group(2)
444         if not source_version:
445             source_version = version
446         filename = Scanner.Section["filename"]
447         location_id = db_access.get_location_id (location, component, archive)
448         filename = poolify (filename, location)
449         if architecture == "all":
450             filename = re_arch_from_filename.sub("binary-all", filename);
451         cache_key = "%s~%s" % (source, source_version);
452         source_id = source_cache_for_binaries.get(cache_key, None);
453         size = Scanner.Section["size"];
454         md5sum = Scanner.Section["md5sum"];
455         files_id = get_or_set_files_id (filename, size, md5sum, location_id);
456         type = "deb"; # FIXME
457         cache_key = "%s~%s~%s~%d~%d~%d" % (package, version, repr(source_id), architecture_id, location_id, files_id);
458         if not arch_all_cache.has_key(cache_key):
459             arch_all_cache[cache_key] = 1;
460             cache_key = "%s~%s~%s~%d" % (package, version, repr(source_id), architecture_id);
461             if not binary_cache.has_key(cache_key):
462                 if not source_id:
463                     source_id = "\N";
464                     count_bad = count_bad + 1;
465                 else:
466                     source_id = repr(source_id);
467                 binaries_id_serial = binaries_id_serial + 1;
468                 binaries_query_cache.write("%d\t%s\t%s\t%d\t%s\t%d\t%d\t%s\t%s\n" % (binaries_id_serial, package, version, maintainer_id, source_id, architecture_id, files_id, type, fingerprint_id));
469                 binary_cache[cache_key] = binaries_id_serial;
470                 tmp_binaries_id = binaries_id_serial;
471             else:
472                 tmp_binaries_id = binary_cache[cache_key];
473
474             bin_associations_id_serial = bin_associations_id_serial + 1;
475             bin_associations_query_cache.write("%d\t%d\t%d\n" % (bin_associations_id_serial, suite_id, tmp_binaries_id));
476             if suite == "stable":
477                 bin_associations_id_serial = bin_associations_id_serial + 1;
478                 bin_associations_query_cache.write("%d\t%d\t%d\n" % (bin_associations_id_serial, testing_id, tmp_binaries_id));
479             count_total = count_total +1;
480
481     file.close();
482     if count_bad != 0:
483         print "%d binary packages processed; %d with no source match which is %.2f%%" % (count_total, count_bad, (float(count_bad)/count_total)*100);
484     else:
485         print "%d binary packages processed; 0 with no source match which is 0%%" % (count_total);
486
487 ###############################################################################
488
489 def do_sources(location, prefix, suite, component, server):
490     temp_filename = tempfile.mktemp();
491     fd = os.open(temp_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700);
492     os.close(fd);
493     sources = location + prefix + 'Sources.gz';
494     (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (sources, temp_filename));
495     if (result != 0):
496         utils.fubar("Gunzip invocation failed!\n%s" % (output), result);
497     print 'Processing '+sources+'...';
498     process_sources (location, temp_filename, suite, component, server, os.path.dirname(sources));
499     os.unlink(temp_filename);
500
501 ###############################################################################
502
503 def main ():
504     global Cnf, projectB, query_cache, files_query_cache, source_query_cache, src_associations_query_cache, dsc_files_query_cache, bin_associations_query_cache, binaries_query_cache;
505
506     Cnf = utils.get_conf();
507
508     print "Re-Creating DB..."
509     (result, output) = commands.getstatusoutput("psql -f init_pool.sql template1");
510     if (result != 0):
511         utils.fubar("psql invocation failed!\n", result);
512     print output;
513
514     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
515
516     db_access.init (Cnf, projectB);
517
518     print "Adding static tables from conf file..."
519     projectB.query("BEGIN WORK");
520     update_architectures();
521     update_components();
522     update_archives();
523     update_locations();
524     update_suites();
525     projectB.query("COMMIT WORK");
526
527     files_query_cache = utils.open_file(Cnf["Neve::ExportDir"]+"files","w");
528     source_query_cache = utils.open_file(Cnf["Neve::ExportDir"]+"source","w");
529     src_associations_query_cache = utils.open_file(Cnf["Neve::ExportDir"]+"src_associations","w");
530     dsc_files_query_cache = utils.open_file(Cnf["Neve::ExportDir"]+"dsc_files","w");
531     binaries_query_cache = utils.open_file(Cnf["Neve::ExportDir"]+"binaries","w");
532     bin_associations_query_cache = utils.open_file(Cnf["Neve::ExportDir"]+"bin_associations","w");
533
534     projectB.query("BEGIN WORK");
535     # Process Sources files to popoulate `source' and friends
536     for location in Cnf.SubTree("Location").List():
537         SubSec = Cnf.SubTree("Location::%s" % (location));
538         server = SubSec["Archive"];
539         type = Cnf.Find("Location::%s::Type" % (location));
540         if type == "legacy-mixed":
541             prefix = ''
542             suite = Cnf.Find("Location::%s::Suite" % (location));
543             do_sources(location, prefix, suite, "",  server);
544         elif type == "legacy":
545             for suite in Cnf.SubTree("Location::%s::Suites" % (location)).List():
546                 for component in Cnf.SubTree("Component").List():
547                     prefix = Cnf.Find("Suite::%s::CodeName" % (suite)) + '/' + component + '/source/'
548                     do_sources(location, prefix, suite, component, server);
549         elif type == "pool":
550             continue;
551 #            for component in Cnf.SubTree("Component").List():
552 #                prefix = component + '/'
553 #                do_sources(location, prefix);
554         else:
555             utils.fubar("Unknown location type ('%s')." % (type));
556
557     # Process Packages files to populate `binaries' and friends
558
559     for location in Cnf.SubTree("Location").List():
560         SubSec = Cnf.SubTree("Location::%s" % (location));
561         server = SubSec["Archive"];
562         type = Cnf.Find("Location::%s::Type" % (location));
563         if type == "legacy-mixed":
564             packages = location + 'Packages';
565             suite = Cnf.Find("Location::%s::Suite" % (location));
566             print 'Processing '+location+'...';
567             process_packages (location, packages, suite, "", server);
568         elif type == "legacy":
569             for suite in Cnf.ValueList("Location::%s::Suites" % (location)):
570                 for component in Cnf.SubTree("Component").List():
571                     for architecture in Cnf.ValueList("Suite::%s::Architectures" % (suite)):
572                         if architecture == "source" or architecture == "all":
573                             continue;
574                         packages = location + Cnf.Find("Suite::%s::CodeName" % (suite)) + '/' + component + '/binary-' + architecture + '/Packages'
575                         print 'Processing '+packages+'...';
576                         process_packages (location, packages, suite, component, server);
577         elif type == "pool":
578             continue;
579
580     files_query_cache.close();
581     source_query_cache.close();
582     src_associations_query_cache.close();
583     dsc_files_query_cache.close();
584     binaries_query_cache.close();
585     bin_associations_query_cache.close();
586     print "Writing data to `files' table...";
587     projectB.query("COPY files FROM '%s'" % (Cnf["Neve::ExportDir"]+"files"));
588     print "Writing data to `source' table...";
589     projectB.query("COPY source FROM '%s'" % (Cnf["Neve::ExportDir"]+"source"));
590     print "Writing data to `src_associations' table...";
591     projectB.query("COPY src_associations FROM '%s'" % (Cnf["Neve::ExportDir"]+"src_associations"));
592     print "Writing data to `dsc_files' table...";
593     projectB.query("COPY dsc_files FROM '%s'" % (Cnf["Neve::ExportDir"]+"dsc_files"));
594     print "Writing data to `binaries' table...";
595     projectB.query("COPY binaries FROM '%s'" % (Cnf["Neve::ExportDir"]+"binaries"));
596     print "Writing data to `bin_associations' table...";
597     projectB.query("COPY bin_associations FROM '%s'" % (Cnf["Neve::ExportDir"]+"bin_associations"));
598     print "Committing...";
599     projectB.query("COMMIT WORK");
600
601     # Add the constraints and otherwise generally clean up the database.
602     # See add_constraints.sql for more details...
603
604     print "Running add_constraints.sql...";
605     (result, output) = commands.getstatusoutput("psql %s < add_constraints.sql" % (Cnf["DB::Name"]));
606     print output
607     if (result != 0):
608         utils.fubar("psql invocation failed!\n%s" % (output), result);
609
610     return;
611
612 if __name__ == '__main__':
613     main();