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