]> git.decadent.org.uk Git - dak.git/blob - neve
sync
[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.16 2002-11-26 15:49:50 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, 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 location_path_cache = {};
57 #
58 files_id_serial = 0;
59 source_id_serial = 0;
60 src_associations_id_serial = 0;
61 dsc_files_id_serial = 0;
62 files_query_cache = None;
63 source_query_cache = None;
64 src_associations_query_cache = None;
65 dsc_files_query_cache = None;
66 orig_tar_gz_cache = {};
67 #
68 binaries_id_serial = 0;
69 binaries_query_cache = None;
70 bin_associations_id_serial = 0;
71 bin_associations_query_cache = None;
72 #
73 source_cache_for_binaries = {};
74 reject_message = "";
75
76 ###############################################################################
77
78 # Our very own version of commands.getouputstatus(), hacked to support
79 # gpgv's status fd.
80 def get_status_output(cmd, status_read, status_write):
81     cmd = ['/bin/sh', '-c', cmd];
82     p2cread, p2cwrite = os.pipe();
83     c2pread, c2pwrite = os.pipe();
84     errout, errin = os.pipe();
85     pid = os.fork();
86     if pid == 0:
87         # Child
88         os.close(0);
89         os.close(1);
90         os.dup(p2cread);
91         os.dup(c2pwrite);
92         os.close(2);
93         os.dup(errin);
94         for i in range(3, 256):
95             if i != status_write:
96                 try:
97                     os.close(i);
98                 except:
99                     pass;
100         try:
101             os.execvp(cmd[0], cmd);
102         finally:
103             os._exit(1);
104
105     # parent
106     os.close(p2cread)
107     os.dup2(c2pread, c2pwrite);
108     os.dup2(errout, errin);
109
110     output = status = "";
111     while 1:
112         i, o, e = select.select([c2pwrite, errin, status_read], [], []);
113         more_data = [];
114         for fd in i:
115             r = os.read(fd, 8196);
116             if len(r) > 0:
117                 more_data.append(fd);
118                 if fd == c2pwrite or fd == errin:
119                     output += r;
120                 elif fd == status_read:
121                     status += r;
122                 else:
123                     utils.fubar("Unexpected file descriptor [%s] returned from select\n" % (fd));
124         if not more_data:
125             pid, exit_status = os.waitpid(pid, 0)
126             try:
127                 os.close(status_write);
128                 os.close(status_read);
129                 os.close(c2pwrite);
130                 os.close(p2cwrite);
131                 os.close(errin);
132             except:
133                 pass;
134             break;
135
136     return output, status, exit_status;
137
138 ###############################################################################
139
140 def Dict(**dict): return dict
141
142 def reject (str, prefix="Rejected: "):
143     global reject_message;
144     if str:
145         reject_message += prefix + str + "\n";
146
147 ###############################################################################
148
149 def check_signature (filename):
150     if not utils.re_taint_free.match(os.path.basename(filename)):
151         reject("!!WARNING!! tainted filename: '%s'." % (filename));
152         return None;
153
154     status_read, status_write = os.pipe();
155     cmd = "gpgv --status-fd %s --keyring %s --keyring %s %s" \
156           % (status_write, Cnf["Dinstall::PGPKeyring"], Cnf["Dinstall::GPGKeyring"], filename);
157     (output, status, exit_status) = get_status_output(cmd, status_read, status_write);
158
159     # Process the status-fd output
160     keywords = {};
161     bad = internal_error = "";
162     for line in status.split('\n'):
163         line = line.strip();
164         if line == "":
165             continue;
166         split = line.split();
167         if len(split) < 2:
168             internal_error += "gpgv status line is malformed (< 2 atoms) ['%s'].\n" % (line);
169             continue;
170         (gnupg, keyword) = split[:2];
171         if gnupg != "[GNUPG:]":
172             internal_error += "gpgv status line is malformed (incorrect prefix '%s').\n" % (gnupg);
173             continue;
174         args = split[2:];
175         if keywords.has_key(keyword) and keyword != "NODATA" and keyword != "SIGEXPIRED":
176             internal_error += "found duplicate status token ('%s')." % (keyword);
177             continue;
178         else:
179             keywords[keyword] = args;
180
181     # If we failed to parse the status-fd output, let's just whine and bail now
182     if internal_error:
183         reject("internal error while performing signature check on %s." % (filename));
184         reject(internal_error, "");
185         reject("Please report the above errors to the Archive maintainers by replying to this mail.", "");
186         return None;
187
188     # Now check for obviously bad things in the processed output
189     if keywords.has_key("SIGEXPIRED"):
190         utils.warn("%s: signing key has expired." % (filename));
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 status.strip():
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 '%r' in %s." % (keyword, 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')" % suite.lower());
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'" % (i.lower(), SubSec[i], suite.lower()))
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 def update_override_type():
317     projectB.query("DELETE FROM override_type");
318     for type in Cnf.ValueList("OverrideType"):
319         projectB.query("INSERT INTO override_type (type) VALUES ('%s')" % (type));
320
321 def update_priority():
322     projectB.query("DELETE FROM priority");
323     for priority in Cnf.SubTree("Priority").List():
324         projectB.query("INSERT INTO priority (priority, level) VALUES ('%s', %s)" % (priority, Cnf["Priority::%s" % (priority)]));
325
326 def update_section():
327     projectB.query("DELETE FROM section");
328     for component in Cnf.SubTree("Component").List():
329         if Cnf["Natalie::ComponentPosition"] == "prefix":
330             suffix = "";
331             if component != 'main':
332                 prefix = component + '/';
333             else:
334                 prefix = "";
335         else:
336             prefix = "";
337             component = component.replace("non-US/", "");
338             if component != 'main':
339                 suffix = '/' + component;
340             else:
341                 suffix = "";
342         for section in Cnf.ValueList("Section"):
343             projectB.query("INSERT INTO section (section) VALUES ('%s%s%s')" % (prefix, section, suffix));
344
345 def get_location_path(directory):
346     global location_path_cache;
347
348     if location_path_cache.has_key(directory):
349         return location_path_cache[directory];
350
351     q = projectB.query("SELECT DISTINCT path FROM location WHERE path ~ '%s'" % (directory));
352     try:
353         path = q.getresult()[0][0];
354     except:
355         utils.fubar("[neve] get_location_path(): Couldn't get path for %s" % (directory));
356     location_path_cache[directory] = path;
357     return path;
358
359 ###############################################################################
360
361 def get_or_set_files_id (filename, size, md5sum, location_id):
362     global files_id_cache, files_id_serial, files_query_cache;
363
364     cache_key = "~".join((filename, size, md5sum, repr(location_id)));
365     if not files_id_cache.has_key(cache_key):
366         files_id_serial += 1
367         files_query_cache.write("%d\t%s\t%s\t%s\t%d\n" % (files_id_serial, filename, size, md5sum, location_id));
368         files_id_cache[cache_key] = files_id_serial
369
370     return files_id_cache[cache_key]
371
372 ###############################################################################
373
374 def process_sources (filename, suite, component, archive):
375     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;
376
377     suite = suite.lower();
378     suite_id = db_access.get_suite_id(suite);
379     try:
380         file = utils.open_file (filename);
381     except utils.cant_open_exc:
382         utils.warn("can't open '%s'" % (filename));
383         return;
384     Scanner = apt_pkg.ParseTagFile(file);
385     while Scanner.Step() != 0:
386         package = Scanner.Section["package"];
387         version = Scanner.Section["version"];
388         directory = Scanner.Section["directory"];
389         dsc_file = os.path.join(Cnf["Dir::Root"], directory, "%s_%s.dsc" % (package, utils.re_no_epoch.sub('', version)));
390         # Sometimes the Directory path is a lie; check in the pool
391         if not os.path.exists(dsc_file):
392             if directory.split('/')[0] == "dists":
393                 directory = Cnf["Dir::PoolRoot"] + utils.poolify(package, component);
394                 dsc_file = os.path.join(Cnf["Dir::Root"], directory, "%s_%s.dsc" % (package, utils.re_no_epoch.sub('', version)));
395         if not os.path.exists(dsc_file):
396             utils.fubar("%s not found." % (dsc_file));
397         install_date = time.strftime("%Y-%m-%d", time.localtime(os.path.getmtime(dsc_file)));
398         fingerprint = check_signature(dsc_file);
399         fingerprint_id = db_access.get_or_set_fingerprint_id(fingerprint);
400         if reject_message:
401             utils.fubar("%s: %s" % (dsc_file, reject_message));
402         maintainer = Scanner.Section["maintainer"]
403         maintainer = maintainer.replace("'", "\\'");
404         maintainer_id = db_access.get_or_set_maintainer_id(maintainer);
405         location = get_location_path(directory.split('/')[0]);
406         location_id = db_access.get_location_id (location, component, archive);
407         if not directory.endswith("/"):
408             directory += '/';
409         directory = poolify (directory, location);
410         if directory != "" and not directory.endswith("/"):
411             directory += '/';
412         no_epoch_version = utils.re_no_epoch.sub('', version);
413         # Add all files referenced by the .dsc to the files table
414         ids = [];
415         for line in Scanner.Section["files"].split('\n'):
416             id = None;
417             (md5sum, size, filename) = line.strip().split();
418             # Don't duplicate .orig.tar.gz's
419             if filename.endswith(".orig.tar.gz"):
420                 cache_key = "%s~%s~%s" % (filename, size, md5sum);
421                 if orig_tar_gz_cache.has_key(cache_key):
422                     id = orig_tar_gz_cache[cache_key];
423                 else:
424                     id = get_or_set_files_id (directory + filename, size, md5sum, location_id);
425                     orig_tar_gz_cache[cache_key] = id;
426             else:
427                 id = get_or_set_files_id (directory + filename, size, md5sum, location_id);
428             ids.append(id);
429             # If this is the .dsc itself; save the ID for later.
430             if filename.endswith(".dsc"):
431                 files_id = id;
432         filename = directory + package + '_' + no_epoch_version + '.dsc'
433         cache_key = "%s~%s" % (package, version);
434         if not source_cache.has_key(cache_key):
435             nasty_key = "%s~%s" % (package, version)
436             source_id_serial += 1;
437             if not source_cache_for_binaries.has_key(nasty_key):
438                 source_cache_for_binaries[nasty_key] = source_id_serial;
439             tmp_source_id = source_id_serial;
440             source_cache[cache_key] = source_id_serial;
441             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))
442             for id in ids:
443                 dsc_files_id_serial += 1;
444                 dsc_files_query_cache.write("%d\t%d\t%d\n" % (dsc_files_id_serial, tmp_source_id,id));
445         else:
446             tmp_source_id = source_cache[cache_key];
447
448         src_associations_id_serial += 1;
449         src_associations_query_cache.write("%d\t%d\t%d\n" % (src_associations_id_serial, suite_id, tmp_source_id))
450
451     file.close();
452
453 ###############################################################################
454
455 def process_packages (filename, suite, component, archive):
456     global arch_all_cache, binary_cache, binaries_id_serial, binaries_query_cache, bin_associations_id_serial, bin_associations_query_cache, reject_message;
457
458     count_total = 0;
459     count_bad = 0;
460     suite = suite.lower();
461     suite_id = db_access.get_suite_id(suite);
462     try:
463         file = utils.open_file (filename);
464     except utils.cant_open_exc:
465         utils.warn("can't open '%s'" % (filename));
466         return;
467     Scanner = apt_pkg.ParseTagFile(file);
468     while Scanner.Step() != 0:
469         package = Scanner.Section["package"]
470         version = Scanner.Section["version"]
471         maintainer = Scanner.Section["maintainer"]
472         maintainer = maintainer.replace("'", "\\'")
473         maintainer_id = db_access.get_or_set_maintainer_id(maintainer);
474         architecture = Scanner.Section["architecture"]
475         architecture_id = db_access.get_architecture_id (architecture);
476         fingerprint = "NOSIG";
477         fingerprint_id = db_access.get_or_set_fingerprint_id(fingerprint);
478         if not Scanner.Section.has_key("source"):
479             source = package
480         else:
481             source = Scanner.Section["source"]
482         source_version = ""
483         if source.find("(") != -1:
484             m = utils.re_extract_src_version.match(source)
485             source = m.group(1)
486             source_version = m.group(2)
487         if not source_version:
488             source_version = version
489         filename = Scanner.Section["filename"]
490         location = get_location_path(filename.split('/')[0]);
491         location_id = db_access.get_location_id (location, component, archive)
492         filename = poolify (filename, location)
493         if architecture == "all":
494             filename = re_arch_from_filename.sub("binary-all", filename);
495         cache_key = "%s~%s" % (source, source_version);
496         source_id = source_cache_for_binaries.get(cache_key, None);
497         size = Scanner.Section["size"];
498         md5sum = Scanner.Section["md5sum"];
499         files_id = get_or_set_files_id (filename, size, md5sum, location_id);
500         type = "deb"; # FIXME
501         cache_key = "%s~%s~%s~%d~%d~%d~%d" % (package, version, repr(source_id), architecture_id, location_id, files_id, suite_id);
502         if not arch_all_cache.has_key(cache_key):
503             arch_all_cache[cache_key] = 1;
504             cache_key = "%s~%s~%s~%d" % (package, version, repr(source_id), architecture_id);
505             if not binary_cache.has_key(cache_key):
506                 if not source_id:
507                     source_id = "\N";
508                     count_bad += 1;
509                 else:
510                     source_id = repr(source_id);
511                 binaries_id_serial += 1;
512                 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));
513                 binary_cache[cache_key] = binaries_id_serial;
514                 tmp_binaries_id = binaries_id_serial;
515             else:
516                 tmp_binaries_id = binary_cache[cache_key];
517
518             bin_associations_id_serial += 1;
519             bin_associations_query_cache.write("%d\t%d\t%d\n" % (bin_associations_id_serial, suite_id, tmp_binaries_id));
520             count_total += 1;
521
522     file.close();
523     if count_bad != 0:
524         print "%d binary packages processed; %d with no source match which is %.2f%%" % (count_total, count_bad, (float(count_bad)/count_total)*100);
525     else:
526         print "%d binary packages processed; 0 with no source match which is 0%%" % (count_total);
527
528 ###############################################################################
529
530 def do_sources(sources, suite, component, server):
531     temp_filename = tempfile.mktemp();
532     fd = os.open(temp_filename, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0700);
533     os.close(fd);
534     (result, output) = commands.getstatusoutput("gunzip -c %s > %s" % (sources, temp_filename));
535     if (result != 0):
536         utils.fubar("Gunzip invocation failed!\n%s" % (output), result);
537     print 'Processing '+sources+'...';
538     process_sources (temp_filename, suite, component, server);
539     os.unlink(temp_filename);
540
541 ###############################################################################
542
543 def do_da_do_da ():
544     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;
545
546     Cnf = utils.get_conf();
547
548     print "Re-Creating DB..."
549     (result, output) = commands.getstatusoutput("psql -f init_pool.sql template1");
550     if (result != 0):
551         utils.fubar("psql invocation failed!\n", result);
552     print output;
553
554     projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"]));
555
556     db_access.init (Cnf, projectB);
557
558     print "Adding static tables from conf file..."
559     projectB.query("BEGIN WORK");
560     update_architectures();
561     update_components();
562     update_archives();
563     update_locations();
564     update_suites();
565     update_override_type();
566     update_priority();
567     update_section();
568     projectB.query("COMMIT WORK");
569
570     files_query_cache = utils.open_file(Cnf["Neve::ExportDir"]+"files","w");
571     source_query_cache = utils.open_file(Cnf["Neve::ExportDir"]+"source","w");
572     src_associations_query_cache = utils.open_file(Cnf["Neve::ExportDir"]+"src_associations","w");
573     dsc_files_query_cache = utils.open_file(Cnf["Neve::ExportDir"]+"dsc_files","w");
574     binaries_query_cache = utils.open_file(Cnf["Neve::ExportDir"]+"binaries","w");
575     bin_associations_query_cache = utils.open_file(Cnf["Neve::ExportDir"]+"bin_associations","w");
576
577     projectB.query("BEGIN WORK");
578     # Process Sources files to popoulate `source' and friends
579     for location in Cnf.SubTree("Location").List():
580         SubSec = Cnf.SubTree("Location::%s" % (location));
581         server = SubSec["Archive"];
582         type = Cnf.Find("Location::%s::Type" % (location));
583         if type == "legacy-mixed":
584             sources = location + 'Sources.gz';
585             suite = Cnf.Find("Location::%s::Suite" % (location));
586             do_sources(sources, suite, "",  server);
587         elif type == "legacy" or type == "pool":
588             for suite in Cnf.ValueList("Location::%s::Suites" % (location)):
589                 for component in Cnf.SubTree("Component").List():
590                     sources = Cnf["Dir::Root"] + "dists/" + Cnf["Suite::%s::CodeName" % (suite)] + '/' + component + '/source/' + 'Sources.gz';
591                     do_sources(sources, suite, component, server);
592         else:
593             utils.fubar("Unknown location type ('%s')." % (type));
594
595     # Process Packages files to populate `binaries' and friends
596
597     for location in Cnf.SubTree("Location").List():
598         SubSec = Cnf.SubTree("Location::%s" % (location));
599         server = SubSec["Archive"];
600         type = Cnf.Find("Location::%s::Type" % (location));
601         if type == "legacy-mixed":
602             packages = location + 'Packages';
603             suite = Cnf.Find("Location::%s::Suite" % (location));
604             print 'Processing '+location+'...';
605             process_packages (packages, suite, "", server);
606         elif type == "legacy" or type == "pool":
607             for suite in Cnf.ValueList("Location::%s::Suites" % (location)):
608                 for component in Cnf.SubTree("Component").List():
609                     architectures = filter(utils.real_arch,
610                                            Cnf.ValueList("Suite::%s::Architectures" % (suite)));
611                     for architecture in architectures:
612                         packages = Cnf["Dir::Root"] + "dists/" + Cnf["Suite::%s::CodeName" % (suite)] + '/' + component + '/binary-' + architecture + '/Packages'
613                         print 'Processing '+packages+'...';
614                         process_packages (packages, suite, component, server);
615
616     files_query_cache.close();
617     source_query_cache.close();
618     src_associations_query_cache.close();
619     dsc_files_query_cache.close();
620     binaries_query_cache.close();
621     bin_associations_query_cache.close();
622     print "Writing data to `files' table...";
623     projectB.query("COPY files FROM '%s'" % (Cnf["Neve::ExportDir"]+"files"));
624     print "Writing data to `source' table...";
625     projectB.query("COPY source FROM '%s'" % (Cnf["Neve::ExportDir"]+"source"));
626     print "Writing data to `src_associations' table...";
627     projectB.query("COPY src_associations FROM '%s'" % (Cnf["Neve::ExportDir"]+"src_associations"));
628     print "Writing data to `dsc_files' table...";
629     projectB.query("COPY dsc_files FROM '%s'" % (Cnf["Neve::ExportDir"]+"dsc_files"));
630     print "Writing data to `binaries' table...";
631     projectB.query("COPY binaries FROM '%s'" % (Cnf["Neve::ExportDir"]+"binaries"));
632     print "Writing data to `bin_associations' table...";
633     projectB.query("COPY bin_associations FROM '%s'" % (Cnf["Neve::ExportDir"]+"bin_associations"));
634     print "Committing...";
635     projectB.query("COMMIT WORK");
636
637     # Add the constraints and otherwise generally clean up the database.
638     # See add_constraints.sql for more details...
639
640     print "Running add_constraints.sql...";
641     (result, output) = commands.getstatusoutput("psql %s < add_constraints.sql" % (Cnf["DB::Name"]));
642     print output
643     if (result != 0):
644         utils.fubar("psql invocation failed!\n%s" % (output), result);
645
646     return;
647
648 ################################################################################
649
650 def main():
651     utils.try_with_debug(do_da_do_da);
652
653 ################################################################################
654
655 if __name__ == '__main__':
656     main();