X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fcontents.py;h=a906b54d20e2cb8f75a83c525449a73bd601be68;hb=1149b8e288d45a56c61b7d3804e25fd33de4f27a;hp=449fb88e126fdc13038c1fd512edf0631bfff060;hpb=3b0114ce123dc45186d02045233510b777a01b02;p=dak.git diff --git a/daklib/contents.py b/daklib/contents.py index 449fb88e..a906b54d 100755 --- a/daklib/contents.py +++ b/daklib/contents.py @@ -27,6 +27,7 @@ Helper code for contents generation. from daklib.dbconn import * from daklib.config import Config +from daklib.filewriter import BinaryContentsFileWriter, SourceContentsFileWriter from multiprocessing import Pool from shutil import rmtree @@ -144,19 +145,17 @@ select bc.file, string_agg(o.section || '/' || b.package, ',' order by b.package ''' return [item for item in self.fetch()] - def output_filename(self): + def writer(self): ''' - Returns the name of the output file. + Returns a writer object. ''' values = { - 'root': Config()['Dir::Root'], - 'suite': self.suite.suite_name, - 'architecture': self.architecture.arch_string + 'suite': self.suite.suite_name, + 'architecture': self.architecture.arch_string, } - if self.component is None: - return "%(root)s/dists/%(suite)s/Contents-%(architecture)s.gz" % values - values['component'] = self.component.component_name - return "%(root)s/dists/%(suite)s/%(component)s/Contents-%(architecture)s.gz" % values + if self.component is not None: + values['component'] = self.component.component_name + return BinaryContentsFileWriter(**values) def get_header(self): ''' @@ -175,19 +174,12 @@ select bc.file, string_agg(o.section || '/' || b.package, ',' order by b.package ''' Write the output file. ''' - command = ['gzip', '--rsyncable'] - 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()) + writer = self.writer() + file = writer.open() + file.write(self.get_header()) for item in self.fetch(): - gzip.stdin.write(item) - gzip.stdin.close() - output_file.close() - gzip.wait() - os.chmod(temp_filename, 0664) - os.rename(temp_filename, final_filename) + file.write(item) + writer.close() class SourceContentsWriter(object): @@ -251,33 +243,25 @@ select sc.file, string_agg(s.source, ',' order by s.source) as pkglist ''' return [item for item in self.fetch()] - def output_filename(self): + def writer(self): ''' - Returns the name of the output file. + Returns a writer object. ''' values = { - 'root': Config()['Dir::Root'], 'suite': self.suite.suite_name, 'component': self.component.component_name } - return "%(root)s/dists/%(suite)s/%(component)s/Contents-source.gz" % values + return SourceContentsFileWriter(**values) def write_file(self): ''' Write the output file. ''' - command = ['gzip', '--rsyncable'] - final_filename = self.output_filename() - temp_filename = final_filename + '.new' - output_file = open(temp_filename, 'w') - gzip = Popen(command, stdin = PIPE, stdout = output_file) + writer = self.writer() + file = writer.open() for item in self.fetch(): - gzip.stdin.write(item) - gzip.stdin.close() - output_file.close() - gzip.wait() - os.chmod(temp_filename, 0664) - os.rename(temp_filename, final_filename) + file.write(item) + writer.close() def binary_helper(suite_id, arch_id, overridetype_id, component_id = None):