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