X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fcontents.py;h=5bf94d9a252da7c7bdd5a6c10d70b408294b5dab;hb=e8df34db4cc473d53136905027307484400fdf0d;hp=1148758c704e87b8e09695b5cee947fafae958b7;hpb=dfa2f059b345fcd07a64f19659ab2c459e960ce1;p=dak.git diff --git a/daklib/contents.py b/daklib/contents.py index 1148758c..5bf94d9a 100755 --- a/daklib/contents.py +++ b/daklib/contents.py @@ -31,6 +31,7 @@ from daklib.threadpool import ThreadPool from multiprocessing import Pool from sqlalchemy import desc, or_ +from sqlalchemy.exc import IntegrityError from subprocess import Popen, PIPE, call import os.path @@ -55,12 +56,16 @@ class ContentsWriter(object): ''' Returns a query object that is doing most of the work. ''' + overridesuite = self.suite + if self.suite.overridesuite is not None: + overridesuite = get_suite(self.suite.overridesuite, self.session) params = { - 'suite': self.suite.suite_id, - 'arch_all': get_architecture('all', self.session).arch_id, - 'arch': self.architecture.arch_id, - 'type_id': self.overridetype.overridetype_id, - 'type': self.overridetype.overridetype, + 'suite': self.suite.suite_id, + 'overridesuite': overridesuite.suite_id, + 'arch_all': get_architecture('all', self.session).arch_id, + 'arch': self.architecture.arch_id, + 'type_id': self.overridetype.overridetype_id, + 'type': self.overridetype.overridetype, } if self.component is not None: @@ -84,13 +89,13 @@ with unique_override as (select o.package, s.section from override o, section s - where o.suite = :suite and o.type = :type_id and o.section = s.id and + where o.suite = :overridesuite and o.type = :type_id and o.section = s.id and o.component = :component) -select bc.file, substring(o.section from position('/' in o.section) + 1) || '/' || b.package as package +select bc.file, string_agg(o.section || '/' || b.package, ',' order by b.package) as pkglist from newest_binaries b, bin_contents bc, unique_override o where b.id = bc.binary_id and o.package = b.package - order by bc.file, b.package''' + group by bc.file''' else: sql = ''' @@ -112,39 +117,29 @@ with unique_override as (select distinct on (o.package, s.section) o.package, s.section from override o, section s - where o.suite = :suite and o.type = :type_id and o.section = s.id + where o.suite = :overridesuite and o.type = :type_id and o.section = s.id order by o.package, s.section, o.modified desc) -select bc.file, substring(o.section from position('/' in o.section) + 1) || '/' || b.package as package +select bc.file, string_agg(o.section || '/' || b.package, ',' order by b.package) as pkglist from newest_binaries b, bin_contents bc, unique_override o where b.id = bc.binary_id and o.package = b.package - order by bc.file, b.package''' + group by bc.file''' - return self.session.query("file", "package").from_statement(sql). \ + return self.session.query("file", "pkglist").from_statement(sql). \ params(params) def formatline(self, filename, package_list): ''' Returns a formatted string for the filename argument. ''' - package_list = ','.join(package_list) return "%-55s %s\n" % (filename, package_list) def fetch(self): ''' Yields a new line of the Contents-$arch.gz file in filename order. ''' - last_filename = None - package_list = [] - for filename, package in self.query().yield_per(100): - if filename != last_filename: - if last_filename is not None: - yield self.formatline(last_filename, package_list) - last_filename = filename - package_list = [] - package_list.append(package) - if last_filename is not None: - yield self.formatline(last_filename, package_list) + for filename, package_list in self.query().yield_per(100): + yield self.formatline(filename, package_list) # end transaction to return connection to pool self.session.rollback() @@ -186,7 +181,9 @@ select bc.file, substring(o.section from position('/' in o.section) + 1) || '/' Write the output file. ''' command = ['gzip', '--rsyncable'] - output_file = open(self.output_filename(), 'w') + final_filename = self.output_filename() + temp_filename = final_filename + '.new' + output_file = open(temp_filename, 'w') gzip = Popen(command, stdin = PIPE, stdout = output_file) gzip.stdin.write(self.get_header()) for item in self.fetch(): @@ -194,6 +191,9 @@ select bc.file, substring(o.section from position('/' in o.section) + 1) || '/' gzip.stdin.close() output_file.close() gzip.wait() + os.remove(final_filename) + os.rename(temp_filename, final_filename) + os.chmod(final_filename, 0664) @classmethod def write_all(class_, suite_names = [], force = False): @@ -247,7 +247,10 @@ class ContentsScanner(object): ''' session = DBConn().session() binary = session.query(DBBinary).get(self.binary_id) - for filename in binary.scan_contents(): + fileset = set(binary.scan_contents()) + if len(fileset) == 0: + fileset.add('EMPTY_PACKAGE') + for filename in fileset: binary.contents.append(BinContents(file = filename)) session.commit() session.close()