From ac89f32d430096e45648271e7c953aae7c45b9f7 Mon Sep 17 00:00:00 2001 From: Torsten Werner Date: Sat, 26 Mar 2011 10:47:12 +0000 Subject: [PATCH] Implement SourceContentsFileWriter. Signed-off-by: Torsten Werner --- daklib/contents.py | 24 ++++++++---------------- daklib/filewriter.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/daklib/contents.py b/daklib/contents.py index 6e55f629..a906b54d 100755 --- a/daklib/contents.py +++ b/daklib/contents.py @@ -27,7 +27,7 @@ Helper code for contents generation. from daklib.dbconn import * from daklib.config import Config -from daklib.filewriter import BinaryContentsFileWriter +from daklib.filewriter import BinaryContentsFileWriter, SourceContentsFileWriter from multiprocessing import Pool from shutil import rmtree @@ -243,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): diff --git a/daklib/filewriter.py b/daklib/filewriter.py index 35919634..31093f00 100755 --- a/daklib/filewriter.py +++ b/daklib/filewriter.py @@ -98,3 +98,18 @@ class BinaryContentsFileWriter(BaseFileWriter): else: template = "dists/%(suite)s/Contents-%(architecture)s" BaseFileWriter.__init__(self, template, **flags) + +class SourceContentsFileWriter(BaseFileWriter): + def __init__(self, **keywords): + ''' + The value of the keywords suite and component are strings. + Output files are gzip compressed only. + ''' + flags = { + 'uncompressed': False, + 'gzip': True, + 'bzip2': False + } + flags.update(keywords) + template = "dists/%(suite)s/%(component)s/Contents-source" + BaseFileWriter.__init__(self, template, **flags) -- 2.39.5