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