]> err.no Git - dak/commitdiff
Implement SourceContentsFileWriter.
authorTorsten Werner <twerner@debian.org>
Sat, 26 Mar 2011 10:47:12 +0000 (10:47 +0000)
committerTorsten Werner <twerner@debian.org>
Sat, 26 Mar 2011 10:47:12 +0000 (10:47 +0000)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/contents.py
daklib/filewriter.py

index 6e55f62901fa580b501342ff65321ed1fe7d56c0..a906b54d20e2cb8f75a83c525449a73bd601be68 100755 (executable)
@@ -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):
index 35919634e9e971515ff5388ff14289542e752ea8..31093f008099c87bfa83c3d8773ebcb2cc6b2651 100755 (executable)
@@ -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)