]> err.no Git - dak/commitdiff
Refactor class ContentsWriter to prepare for source contents.
authorTorsten Werner <twerner@debian.org>
Thu, 24 Mar 2011 09:19:02 +0000 (10:19 +0100)
committerTorsten Werner <twerner@debian.org>
Thu, 24 Mar 2011 09:19:02 +0000 (10:19 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/contents.py
tests/dbtest_contents.py

index 2a29b2e55b5080eadc574e559edf38a22ae1615a..da7adb137ab2406481459cf5f0b31d7f963cda0f 100755 (executable)
@@ -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):
     '''
index e3128161780893ea6188165a9f91a7e5cfaa768f..51a6ddf4898721c17fb350e6fbc2d7420c70379c 100755 (executable)
@@ -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()))