]> git.decadent.org.uk Git - dak.git/blob - daklib/database.py
oops, forgot some changes to contents.py
[dak.git] / daklib / database.py
1 #!/usr/bin/env python
2
3 """ DB access functions
4 @group readonly: get_suite_id, get_section_id, get_priority_id, get_override_type_id,
5                  get_architecture_id, get_archive_id, get_component_id, get_location_id,
6                  get_source_id, get_suite_version, get_files_id, get_maintainer, get_suites
7 @group read/write: get_or_set*, set_files_id
8
9 @contact: Debian FTP Master <ftpmaster@debian.org>
10 @copyright: 2000, 2001, 2002, 2003, 2004, 2006  James Troup <james@nocrew.org>
11 @copyright: 2009  Joerg Jaspert <joerg@debian.org>
12 @license: GNU General Public License version 2 or later
13 """
14
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
19
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
29 ################################################################################
30
31 import sys
32 import time
33 import types
34
35 ################################################################################
36
37 Cnf = None                    #: Configuration, apt_pkg.Configuration
38 projectB = None               #: database connection, pgobject
39 suite_id_cache = {}           #: cache for suites
40 section_id_cache = {}         #: cache for sections
41 priority_id_cache = {}        #: cache for priorities
42 override_type_id_cache = {}   #: cache for overrides
43 architecture_id_cache = {}    #: cache for architectures
44 archive_id_cache = {}         #: cache for archives
45 component_id_cache = {}       #: cache for components
46 location_id_cache = {}        #: cache for locations
47 maintainer_id_cache = {}      #: cache for maintainers
48 keyring_id_cache = {}         #: cache for keyrings
49 source_id_cache = {}          #: cache for sources
50 files_id_cache = {}           #: cache for files
51 maintainer_cache = {}         #: cache for maintainer names
52 fingerprint_id_cache = {}     #: cache for fingerprints
53 queue_id_cache = {}           #: cache for queues
54 uid_id_cache = {}             #: cache for uids
55 suite_version_cache = {}      #: cache for suite_versions (packages)
56 suite_bin_version_cache = {}
57 cache_preloaded = False
58
59 ################################################################################
60
61 def init (config, sql):
62     """
63     database module init.
64
65     @type config: apt_pkg.Configuration
66     @param config: apt config, see U{http://apt.alioth.debian.org/python-apt-doc/apt_pkg/cache.html#Configuration}
67
68     @type sql: pgobject
69     @param sql: database connection
70
71     """
72     global Cnf, projectB
73
74     Cnf = config
75     projectB = sql
76
77
78 def do_query(query):
79     """
80     Executes a database query. Writes statistics / timing to stderr.
81
82     @type query: string
83     @param query: database query string, passed unmodified
84
85     @return: db result
86
87     @warning: The query is passed B{unmodified}, so be careful what you use this for.
88     """
89     sys.stderr.write("query: \"%s\" ... " % (query))
90     before = time.time()
91     r = projectB.query(query)
92     time_diff = time.time()-before
93     sys.stderr.write("took %.3f seconds.\n" % (time_diff))
94     if type(r) is int:
95         sys.stderr.write("int result: %s\n" % (r))
96     elif type(r) is types.NoneType:
97         sys.stderr.write("result: None\n")
98     else:
99         sys.stderr.write("pgresult: %s\n" % (r.getresult()))
100     return r
101
102 ################################################################################
103
104 def get_suite_id (suite):
105     """
106     Returns database id for given C{suite}.
107     Results are kept in a cache during runtime to minimize database queries.
108
109     @type suite: string
110     @param suite: The name of the suite
111
112     @rtype: int
113     @return: the database id for the given suite
114
115     """
116     global suite_id_cache
117
118     if suite_id_cache.has_key(suite):
119         return suite_id_cache[suite]
120
121     q = projectB.query("SELECT id FROM suite WHERE suite_name = '%s'" % (suite))
122     ql = q.getresult()
123     if not ql:
124         return -1
125
126     suite_id = ql[0][0]
127     suite_id_cache[suite] = suite_id
128
129     return suite_id
130
131 def get_section_id (section):
132     """
133     Returns database id for given C{section}.
134     Results are kept in a cache during runtime to minimize database queries.
135
136     @type section: string
137     @param section: The name of the section
138
139     @rtype: int
140     @return: the database id for the given section
141
142     """
143     global section_id_cache
144
145     if section_id_cache.has_key(section):
146         return section_id_cache[section]
147
148     q = projectB.query("SELECT id FROM section WHERE section = '%s'" % (section))
149     ql = q.getresult()
150     if not ql:
151         return -1
152
153     section_id = ql[0][0]
154     section_id_cache[section] = section_id
155
156     return section_id
157
158 def get_priority_id (priority):
159     """
160     Returns database id for given C{priority}.
161     Results are kept in a cache during runtime to minimize database queries.
162
163     @type priority: string
164     @param priority: The name of the priority
165
166     @rtype: int
167     @return: the database id for the given priority
168
169     """
170     global priority_id_cache
171
172     if priority_id_cache.has_key(priority):
173         return priority_id_cache[priority]
174
175     q = projectB.query("SELECT id FROM priority WHERE priority = '%s'" % (priority))
176     ql = q.getresult()
177     if not ql:
178         return -1
179
180     priority_id = ql[0][0]
181     priority_id_cache[priority] = priority_id
182
183     return priority_id
184
185 def get_override_type_id (type):
186     """
187     Returns database id for given override C{type}.
188     Results are kept in a cache during runtime to minimize database queries.
189
190     @type type: string
191     @param type: The name of the override type
192
193     @rtype: int
194     @return: the database id for the given override type
195
196     """
197     global override_type_id_cache
198
199     if override_type_id_cache.has_key(type):
200         return override_type_id_cache[type]
201
202     q = projectB.query("SELECT id FROM override_type WHERE type = '%s'" % (type))
203     ql = q.getresult()
204     if not ql:
205         return -1
206
207     override_type_id = ql[0][0]
208     override_type_id_cache[type] = override_type_id
209
210     return override_type_id
211
212 def get_architecture_id (architecture):
213     """
214     Returns database id for given C{architecture}.
215     Results are kept in a cache during runtime to minimize database queries.
216
217     @type architecture: string
218     @param architecture: The name of the override type
219
220     @rtype: int
221     @return: the database id for the given architecture
222
223     """
224     global architecture_id_cache
225
226     if architecture_id_cache.has_key(architecture):
227         return architecture_id_cache[architecture]
228
229     q = projectB.query("SELECT id FROM architecture WHERE arch_string = '%s'" % (architecture))
230     ql = q.getresult()
231     if not ql:
232         return -1
233
234     architecture_id = ql[0][0]
235     architecture_id_cache[architecture] = architecture_id
236
237     return architecture_id
238
239 def get_archive_id (archive):
240     """
241     Returns database id for given C{archive}.
242     Results are kept in a cache during runtime to minimize database queries.
243
244     @type archive: string
245     @param archive: The name of the override type
246
247     @rtype: int
248     @return: the database id for the given archive
249
250     """
251     global archive_id_cache
252
253     archive = archive.lower()
254
255     if archive_id_cache.has_key(archive):
256         return archive_id_cache[archive]
257
258     q = projectB.query("SELECT id FROM archive WHERE lower(name) = '%s'" % (archive))
259     ql = q.getresult()
260     if not ql:
261         return -1
262
263     archive_id = ql[0][0]
264     archive_id_cache[archive] = archive_id
265
266     return archive_id
267
268 def get_component_id (component):
269     """
270     Returns database id for given C{component}.
271     Results are kept in a cache during runtime to minimize database queries.
272
273     @type component: string
274     @param component: The name of the component
275
276     @rtype: int
277     @return: the database id for the given component
278
279     """
280     global component_id_cache
281
282     component = component.lower()
283
284     if component_id_cache.has_key(component):
285         return component_id_cache[component]
286
287     q = projectB.query("SELECT id FROM component WHERE lower(name) = '%s'" % (component))
288     ql = q.getresult()
289     if not ql:
290         return -1
291
292     component_id = ql[0][0]
293     component_id_cache[component] = component_id
294
295     return component_id
296
297 def get_location_id (location, component, archive):
298     """
299     Returns database id for the location behind the given combination of
300       - B{location} - the path of the location, eg. I{/srv/ftp.debian.org/ftp/pool/}
301       - B{component} - the id of the component as returned by L{get_component_id}
302       - B{archive} - the id of the archive as returned by L{get_archive_id}
303     Results are kept in a cache during runtime to minimize database queries.
304
305     @type location: string
306     @param location: the path of the location
307
308     @type component: int
309     @param component: the id of the component
310
311     @type archive: int
312     @param archive: the id of the archive
313
314     @rtype: int
315     @return: the database id for the location
316
317     """
318     global location_id_cache
319
320     cache_key = location + '_' + component + '_' + location
321     if location_id_cache.has_key(cache_key):
322         return location_id_cache[cache_key]
323
324     archive_id = get_archive_id (archive)
325     if component != "":
326         component_id = get_component_id (component)
327         if component_id != -1:
328             q = projectB.query("SELECT id FROM location WHERE path = '%s' AND component = %d AND archive = %d" % (location, component_id, archive_id))
329     else:
330         q = projectB.query("SELECT id FROM location WHERE path = '%s' AND archive = %d" % (location, archive_id))
331     ql = q.getresult()
332     if not ql:
333         return -1
334
335     location_id = ql[0][0]
336     location_id_cache[cache_key] = location_id
337
338     return location_id
339
340 def get_source_id (source, version):
341     """
342     Returns database id for the combination of C{source} and C{version}
343       - B{source} - source package name, eg. I{mailfilter}, I{bbdb}, I{glibc}
344       - B{version}
345     Results are kept in a cache during runtime to minimize database queries.
346
347     @type source: string
348     @param source: source package name
349
350     @type version: string
351     @param version: the source version
352
353     @rtype: int
354     @return: the database id for the source
355
356     """
357     global source_id_cache
358
359     cache_key = source + '_' + version + '_'
360     if source_id_cache.has_key(cache_key):
361         return source_id_cache[cache_key]
362
363     q = projectB.query("SELECT id FROM source s WHERE s.source = '%s' AND s.version = '%s'" % (source, version))
364
365     if not q.getresult():
366         return None
367
368     source_id = q.getresult()[0][0]
369     source_id_cache[cache_key] = source_id
370
371     return source_id
372
373 def get_suite_version(source, suite):
374     """
375     Returns database id for a combination of C{source} and C{suite}.
376
377       - B{source} - source package name, eg. I{mailfilter}, I{bbdb}, I{glibc}
378       - B{suite} - a suite name, eg. I{unstable}
379
380     Results are kept in a cache during runtime to minimize database queries.
381
382     @type source: string
383     @param source: source package name
384
385     @type suite: string
386     @param suite: the suite name
387
388     @rtype: string
389     @return: the version for I{source} in I{suite}
390
391     """
392
393     global suite_version_cache
394     cache_key = "%s_%s" % (source, suite)
395
396     if suite_version_cache.has_key(cache_key):
397         return suite_version_cache[cache_key]
398
399     q = projectB.query("""
400     SELECT s.version FROM source s, suite su, src_associations sa
401     WHERE sa.source=s.id
402       AND sa.suite=su.id
403       AND su.suite_name='%s'
404       AND s.source='%s'"""
405                               % (suite, source))
406
407     if not q.getresult():
408         return None
409
410     version = q.getresult()[0][0]
411     suite_version_cache[cache_key] = version
412
413     return version
414
415 def get_latest_binary_version_id(binary, section, suite, arch):
416     global suite_bin_version_cache
417     cache_key = "%s_%s_%s_%s" % (binary, section, suite, arch)
418     cache_key_all = "%s_%s_%s_%s" % (binary, section, suite, get_architecture_id("all"))
419
420     # Check for the cache hit for its arch, then arch all
421     if suite_bin_version_cache.has_key(cache_key):
422         return suite_bin_version_cache[cache_key]
423     if suite_bin_version_cache.has_key(cache_key_all):
424         return suite_bin_version_cache[cache_key_all]
425     if cache_preloaded == True:
426         return # package does not exist
427
428     q = projectB.query("SELECT DISTINCT b.id FROM binaries b JOIN bin_associations ba ON (b.id = ba.bin) JOIN override o ON (o.package=b.package) WHERE b.package = '%s' AND b.architecture = '%d' AND ba.suite = '%d' AND o.section = '%d'" % (binary, int(arch), int(suite), int(section)))
429
430     if not q.getresult():
431         return False
432
433     highest_bid = q.getresult()[0][0]
434
435     suite_bin_version_cache[cache_key] = highest_bid
436     return highest_bid
437
438 def preload_binary_id_cache():
439     global suite_bin_version_cache, cache_preloaded
440
441     # Get suite info
442     q = projectB.query("SELECT id FROM suite")
443     suites = q.getresult()
444
445     # Get arch mappings
446     q = projectB.query("SELECT id FROM architecture")
447     arches = q.getresult()
448
449     for suite in suites:
450         for arch in arches:
451             q = projectB.query("SELECT DISTINCT b.id, b.package, o.section FROM binaries b JOIN bin_associations ba ON (b.id = ba.bin) JOIN override o ON (o.package=b.package) WHERE b.architecture = '%d' AND ba.suite = '%d'" % (int(arch[0]), int(suite[0])))
452
453             for bi in q.getresult():
454                 cache_key = "%s_%s_%s_%s" % (bi[1], bi[2], suite[0], arch[0])
455                 suite_bin_version_cache[cache_key] = int(bi[0])
456
457     cache_preloaded = True
458
459 ################################################################################
460
461 def get_or_set_maintainer_id (maintainer):
462     """
463     If C{maintainer} does not have an entry in the maintainer table yet, create one
464     and return the new id.
465     If C{maintainer} already has an entry, simply return the existing id.
466
467     Results are kept in a cache during runtime to minimize database queries.
468
469     @type maintainer: string
470     @param maintainer: the maintainer name
471
472     @rtype: int
473     @return: the database id for the maintainer
474
475     """
476     global maintainer_id_cache
477
478     if maintainer_id_cache.has_key(maintainer):
479         return maintainer_id_cache[maintainer]
480
481     q = projectB.query("SELECT id FROM maintainer WHERE name = '%s'" % (maintainer))
482     if not q.getresult():
483         projectB.query("INSERT INTO maintainer (name) VALUES ('%s')" % (maintainer))
484         q = projectB.query("SELECT id FROM maintainer WHERE name = '%s'" % (maintainer))
485     maintainer_id = q.getresult()[0][0]
486     maintainer_id_cache[maintainer] = maintainer_id
487
488     return maintainer_id
489
490 ################################################################################
491
492 def get_or_set_keyring_id (keyring):
493     """
494     If C{keyring} does not have an entry in the C{keyrings} table yet, create one
495     and return the new id.
496     If C{keyring} already has an entry, simply return the existing id.
497
498     Results are kept in a cache during runtime to minimize database queries.
499
500     @type keyring: string
501     @param keyring: the keyring name
502
503     @rtype: int
504     @return: the database id for the keyring
505
506     """
507     global keyring_id_cache
508
509     if keyring_id_cache.has_key(keyring):
510         return keyring_id_cache[keyring]
511
512     q = projectB.query("SELECT id FROM keyrings WHERE name = '%s'" % (keyring))
513     if not q.getresult():
514         projectB.query("INSERT INTO keyrings (name) VALUES ('%s')" % (keyring))
515         q = projectB.query("SELECT id FROM keyrings WHERE name = '%s'" % (keyring))
516     keyring_id = q.getresult()[0][0]
517     keyring_id_cache[keyring] = keyring_id
518
519     return keyring_id
520
521 ################################################################################
522
523 def get_or_set_uid_id (uid):
524     """
525     If C{uid} does not have an entry in the uid table yet, create one
526     and return the new id.
527     If C{uid} already has an entry, simply return the existing id.
528
529     Results are kept in a cache during runtime to minimize database queries.
530
531     @type uid: string
532     @param uid: the uid.
533
534     @rtype: int
535     @return: the database id for the uid
536
537     """
538
539     global uid_id_cache
540
541     if uid_id_cache.has_key(uid):
542         return uid_id_cache[uid]
543
544     q = projectB.query("SELECT id FROM uid WHERE uid = '%s'" % (uid))
545     if not q.getresult():
546         projectB.query("INSERT INTO uid (uid) VALUES ('%s')" % (uid))
547         q = projectB.query("SELECT id FROM uid WHERE uid = '%s'" % (uid))
548     uid_id = q.getresult()[0][0]
549     uid_id_cache[uid] = uid_id
550
551     return uid_id
552
553 ################################################################################
554
555 def get_or_set_fingerprint_id (fingerprint):
556     """
557     If C{fingerprint} does not have an entry in the fingerprint table yet, create one
558     and return the new id.
559     If C{fingerprint} already has an entry, simply return the existing id.
560
561     Results are kept in a cache during runtime to minimize database queries.
562
563     @type fingerprint: string
564     @param fingerprint: the fingerprint
565
566     @rtype: int
567     @return: the database id for the fingerprint
568
569     """
570     global fingerprint_id_cache
571
572     if fingerprint_id_cache.has_key(fingerprint):
573         return fingerprint_id_cache[fingerprint]
574
575     q = projectB.query("SELECT id FROM fingerprint WHERE fingerprint = '%s'" % (fingerprint))
576     if not q.getresult():
577         projectB.query("INSERT INTO fingerprint (fingerprint) VALUES ('%s')" % (fingerprint))
578         q = projectB.query("SELECT id FROM fingerprint WHERE fingerprint = '%s'" % (fingerprint))
579     fingerprint_id = q.getresult()[0][0]
580     fingerprint_id_cache[fingerprint] = fingerprint_id
581
582     return fingerprint_id
583
584 ################################################################################
585
586 def get_files_id (filename, size, md5sum, location_id):
587     """
588     Returns -1, -2 or the file_id for filename, if its C{size} and C{md5sum} match an
589     existing copy.
590
591     The database is queried using the C{filename} and C{location_id}. If a file does exist
592     at that location, the existing size and md5sum are checked against the provided
593     parameters. A size or checksum mismatch returns -2. If more than one entry is
594     found within the database, a -1 is returned, no result returns None, otherwise
595     the file id.
596
597     Results are kept in a cache during runtime to minimize database queries.
598
599     @type filename: string
600     @param filename: the filename of the file to check against the DB
601
602     @type size: int
603     @param size: the size of the file to check against the DB
604
605     @type md5sum: string
606     @param md5sum: the md5sum of the file to check against the DB
607
608     @type location_id: int
609     @param location_id: the id of the location as returned by L{get_location_id}
610
611     @rtype: int / None
612     @return: Various return values are possible:
613                - -2: size/checksum error
614                - -1: more than one file found in database
615                - None: no file found in database
616                - int: file id
617
618     """
619     global files_id_cache
620
621     cache_key = "%s_%d" % (filename, location_id)
622
623     if files_id_cache.has_key(cache_key):
624         return files_id_cache[cache_key]
625
626     size = int(size)
627     q = projectB.query("SELECT id, size, md5sum FROM files WHERE filename = '%s' AND location = %d" % (filename, location_id))
628     ql = q.getresult()
629     if ql:
630         if len(ql) != 1:
631             return -1
632         ql = ql[0]
633         orig_size = int(ql[1])
634         orig_md5sum = ql[2]
635         if orig_size != size or orig_md5sum != md5sum:
636             return -2
637         files_id_cache[cache_key] = ql[0]
638         return files_id_cache[cache_key]
639     else:
640         return None
641
642 ################################################################################
643
644 def get_or_set_queue_id (queue):
645     """
646     If C{queue} does not have an entry in the queue table yet, create one
647     and return the new id.
648     If C{queue} already has an entry, simply return the existing id.
649
650     Results are kept in a cache during runtime to minimize database queries.
651
652     @type queue: string
653     @param queue: the queue name (no full path)
654
655     @rtype: int
656     @return: the database id for the queue
657
658     """
659     global queue_id_cache
660
661     if queue_id_cache.has_key(queue):
662         return queue_id_cache[queue]
663
664     q = projectB.query("SELECT id FROM queue WHERE queue_name = '%s'" % (queue))
665     if not q.getresult():
666         projectB.query("INSERT INTO queue (queue_name) VALUES ('%s')" % (queue))
667         q = projectB.query("SELECT id FROM queue WHERE queue_name = '%s'" % (queue))
668     queue_id = q.getresult()[0][0]
669     queue_id_cache[queue] = queue_id
670
671     return queue_id
672
673 ################################################################################
674
675 def set_files_id (filename, size, md5sum, sha1sum, sha256sum, location_id):
676     """
677     Insert a new entry into the files table and return its id.
678
679     @type filename: string
680     @param filename: the filename
681
682     @type size: int
683     @param size: the size in bytes
684
685     @type md5sum: string
686     @param md5sum: md5sum of the file
687
688     @type sha1sum: string
689     @param sha1sum: sha1sum of the file
690
691     @type sha256sum: string
692     @param sha256sum: sha256sum of the file
693
694     @type location_id: int
695     @param location_id: the id of the location as returned by L{get_location_id}
696
697     @rtype: int
698     @return: the database id for the new file
699
700     """
701     global files_id_cache
702
703     projectB.query("INSERT INTO files (filename, size, md5sum, sha1sum, sha256sum, location) VALUES ('%s', %d, '%s', '%s', '%s', %d)" % (filename, long(size), md5sum, sha1sum, sha256sum, location_id))
704
705     return get_files_id (filename, size, md5sum, location_id)
706
707     ### currval has issues with postgresql 7.1.3 when the table is big
708     ### it was taking ~3 seconds to return on auric which is very Not
709     ### Cool(tm).
710     ##
711     ##q = projectB.query("SELECT id FROM files WHERE id = currval('files_id_seq')")
712     ##ql = q.getresult()[0]
713     ##cache_key = "%s_%d" % (filename, location_id)
714     ##files_id_cache[cache_key] = ql[0]
715     ##return files_id_cache[cache_key]
716
717 ################################################################################
718
719 def get_maintainer (maintainer_id):
720     """
721     Return the name of the maintainer behind C{maintainer_id}.
722
723     Results are kept in a cache during runtime to minimize database queries.
724
725     @type maintainer_id: int
726     @param maintainer_id: the id of the maintainer, eg. from L{get_or_set_maintainer_id}
727
728     @rtype: string
729     @return: the name of the maintainer
730
731     """
732     global maintainer_cache
733
734     if not maintainer_cache.has_key(maintainer_id):
735         q = projectB.query("SELECT name FROM maintainer WHERE id = %s" % (maintainer_id))
736         maintainer_cache[maintainer_id] = q.getresult()[0][0]
737
738     return maintainer_cache[maintainer_id]
739
740 ################################################################################
741
742 def get_suites(pkgname, src=False):
743     """
744     Return the suites in which C{pkgname} can be found. If C{src} is True query for source
745     package, else binary package.
746
747     @type pkgname: string
748     @param pkgname: name of the package
749
750     @type src: bool
751     @param src: if True look for source packages, false (default) looks for binary.
752
753     @rtype: list
754     @return: list of suites, or empty list if no match
755
756     """
757     if src:
758         sql = """
759         SELECT suite_name
760         FROM source,
761              src_associations,
762              suite
763         WHERE source.id = src_associations.source
764         AND   source.source = '%s'
765         AND   src_associations.suite = suite.id
766         """ % (pkgname)
767     else:
768         sql = """
769         SELECT suite_name
770         FROM binaries,
771              bin_associations,
772              suite
773         WHERE binaries.id = bin_associations.bin
774         AND   package = '%s'
775         AND   bin_associations.suite = suite.id
776         """ % (pkgname)
777
778     q = projectB.query(sql)
779     return map(lambda x: x[0], q.getresult())
780
781
782 ################################################################################
783
784 def copy_temporary_contents(package, version, deb):
785     """
786     copy the previously stored contents from the temp table to the permanant one
787
788     during process-unchecked, the deb should have been scanned and the
789     contents stored in temp_content_associations
790     """
791
792     # first see if contents exist:
793
794     exists = projectB.query("""SELECT 1 FROM temp_content_associations
795                                WHERE package='%s' LIMIT 1""" % package ).getresult()
796
797     if not exists:
798         # This should NOT happen.  We should have added contents
799         # during process-unchecked.  if it did, log an error, and send
800         # an email.
801         subst = {
802             "__PACKAGE__": package,
803             "__VERSION__": version,
804             "__DAK_ADDRESS__": Cnf["Dinstall::MyEmailAddress"]
805             }
806
807         message = utils.TemplateSubst(Subst, Cnf["Dir::Templates"]+"/bts-categorize")
808         utils.send_mail( message )
809
810         exists = DBConn().insert_content_path(package, version, deb)
811
812     if exists:
813         sql = """INSERT INTO content_associations(binary_pkg,filepath,filename)
814                  SELECT currval('binaries_id_seq'), filepath, filename FROM temp_content_associations
815                  WHERE package='%s'
816                      AND version='%s'""" % (package, version)
817         projectB.query(sql)
818         projectB.query("""DELETE from temp_content_associations
819                           WHERE package='%s'
820                             AND version='%s'""" % (package, version))
821
822     return exists