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
'''
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):
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)