From d36d7bc0fbafcb88ff38016335395820d001e2aa Mon Sep 17 00:00:00 2001 From: Torsten Werner Date: Thu, 24 Mar 2011 10:19:02 +0100 Subject: [PATCH] Refactor class ContentsWriter to prepare for source contents. Signed-off-by: Torsten Werner --- daklib/contents.py | 51 ++++++++++++++++++++-------------------- tests/dbtest_contents.py | 10 ++++---- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/daklib/contents.py b/daklib/contents.py index 2a29b2e5..da7adb13 100755 --- a/daklib/contents.py +++ b/daklib/contents.py @@ -35,16 +35,11 @@ from tempfile import mkdtemp import os.path -class ContentsWriter(object): +class BinaryContentsWriter(object): ''' - ContentsWriter writes the Contents-$arch.gz files. + BinaryContentsWriter writes the Contents-$arch.gz files. ''' def __init__(self, suite, architecture, overridetype, component = None): - ''' - The constructor clones its arguments into a new session object to make - sure that the new ContentsWriter object can be executed in a different - thread. - ''' self.suite = suite self.architecture = architecture self.overridetype = overridetype @@ -193,6 +188,30 @@ select bc.file, string_agg(o.section || '/' || b.package, ',' order by b.package os.chmod(temp_filename, 0664) os.rename(temp_filename, final_filename) + +def generate_helper(suite_id, arch_id, overridetype_id, component_id = None): + ''' + This function is called in a new subprocess. + ''' + session = DBConn().session() + suite = Suite.get(suite_id, session) + architecture = Architecture.get(arch_id, session) + overridetype = OverrideType.get(overridetype_id, session) + log_message = [suite.suite_name, architecture.arch_string, overridetype.overridetype] + if component_id is None: + component = None + else: + component = Component.get(component_id, session) + log_message.append(component.component_name) + contents_writer = BinaryContentsWriter(suite, architecture, overridetype, component) + contents_writer.write_file() + return log_message + +class ContentsWriter(object): + ''' + Loop over all suites, architectures, overridetypes, and components to write + all contents files. + ''' @classmethod def log_result(class_, result): ''' @@ -235,24 +254,6 @@ select bc.file, string_agg(o.section || '/' || b.package, ',' order by b.package pool.join() session.close() -def generate_helper(suite_id, arch_id, overridetype_id, component_id = None): - ''' - This function is called in a new subprocess. - ''' - session = DBConn().session() - suite = Suite.get(suite_id, session) - architecture = Architecture.get(arch_id, session) - overridetype = OverrideType.get(overridetype_id, session) - log_message = [suite.suite_name, architecture.arch_string, overridetype.overridetype] - if component_id is None: - component = None - else: - component = Component.get(component_id, session) - log_message.append(component.component_name) - contents_writer = ContentsWriter(suite, architecture, overridetype, component) - contents_writer.write_file() - return log_message - class BinaryContentsScanner(object): ''' diff --git a/tests/dbtest_contents.py b/tests/dbtest_contents.py index e3128161..51a6ddf4 100755 --- a/tests/dbtest_contents.py +++ b/tests/dbtest_contents.py @@ -3,7 +3,7 @@ from db_test import DBDakTestCase, fixture from daklib.dbconn import * -from daklib.contents import ContentsWriter, BinaryContentsScanner, \ +from daklib.contents import BinaryContentsWriter, BinaryContentsScanner, \ UnpackedSource, SourceContentsScanner from os.path import normpath @@ -131,9 +131,9 @@ class ContentsTestCase(DBDakTestCase): self.assertEqual(self.override['hello_sid_main_udeb'], \ self.otype['udeb'].overrides.one()) - def test_contentswriter(self): + def test_binarycontentswriter(self): ''' - Test the ContentsWriter class. + Test the BinaryContentsWriter class. ''' self.setup_suites() self.setup_architectures() @@ -142,7 +142,7 @@ class ContentsTestCase(DBDakTestCase): self.setup_overrides() self.binary['hello_2.2-1_i386'].contents.append(BinContents(file = '/usr/bin/hello')) self.session.commit() - cw = ContentsWriter(self.suite['squeeze'], self.arch['i386'], self.otype['deb']) + cw = BinaryContentsWriter(self.suite['squeeze'], self.arch['i386'], self.otype['deb']) self.assertEqual(['/usr/bin/hello python/hello\n'], \ cw.get_list()) # test formatline and sort order @@ -151,7 +151,7 @@ class ContentsTestCase(DBDakTestCase): # test output_filename self.assertEqual('tests/fixtures/ftp/dists/squeeze/Contents-i386.gz', \ normpath(cw.output_filename())) - cw = ContentsWriter(self.suite['squeeze'], self.arch['i386'], \ + cw = BinaryContentsWriter(self.suite['squeeze'], self.arch['i386'], \ self.otype['udeb'], self.comp['main']) self.assertEqual('tests/fixtures/ftp/dists/squeeze/main/Contents-i386.gz', \ normpath(cw.output_filename())) -- 2.39.5