]> err.no Git - dak/commitdiff
Convert class Component to ORMObject.
authorTorsten Werner <twerner@debian.org>
Wed, 26 Jan 2011 21:54:11 +0000 (22:54 +0100)
committerTorsten Werner <twerner@debian.org>
Wed, 26 Jan 2011 22:19:57 +0000 (23:19 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
daklib/dbconn.py
tests/dbtest_packages.py

index 1acb20d48621c31c00d79601f6498870b69325c0..e1e21d2b2b1f10a386dd42c50460287d7e6c8f4d 100755 (executable)
@@ -849,9 +849,9 @@ __all__.append('ChangePendingSource')
 
 ################################################################################
 
-class Component(object):
-    def __init__(self, *args, **kwargs):
-        pass
+class Component(ORMObject):
+    def __init__(self, component_name = None):
+        self.component_name = component_name
 
     def __eq__(self, val):
         if isinstance(val, str):
@@ -865,8 +865,12 @@ class Component(object):
         # This signals to use the normal comparison operator
         return NotImplemented
 
-    def __repr__(self):
-        return '<Component %s>' % self.component_name
+    def properties(self):
+        return ['component_name', 'component_id', 'description', 'location', \
+            'meets_dfsg']
+
+    def not_null_constraints(self):
+        return ['component_name']
 
 
 __all__.append('Component')
@@ -1572,9 +1576,12 @@ __all__.append('get_dbchange')
 
 ################################################################################
 
+# TODO: Why do we have a separate Location class? Can't it be fully integrated
+# into class Component?
 class Location(ORMObject):
-    def __init__(self, path = None):
+    def __init__(self, path = None, component = None):
         self.path = path
+        self.component = component
         # the column 'type' should go away, see comment at mapper
         self.archive_type = 'pool'
 
@@ -2989,7 +2996,8 @@ class DBConn(object):
 
         mapper(Component, self.tbl_component,
                properties = dict(component_id = self.tbl_component.c.id,
-                                 component_name = self.tbl_component.c.name))
+                                 component_name = self.tbl_component.c.name),
+               extension = validator)
 
         mapper(DBConfig, self.tbl_config,
                properties = dict(config_id = self.tbl_config.c.id))
@@ -3081,7 +3089,8 @@ class DBConn(object):
         mapper(Location, self.tbl_location,
                properties = dict(location_id = self.tbl_location.c.id,
                                  component_id = self.tbl_location.c.component,
-                                 component = relation(Component),
+                                 component = relation(Component, \
+                                     backref=backref('location', uselist = False)),
                                  archive_id = self.tbl_location.c.archive,
                                  archive = relation(Archive),
                                  # FIXME: the 'type' column is old cruft and
index 371b633e9bae74ec36739dfb0154501cf44b5aef..12ab5960ded9a9795604a6d84746d86f64f0b67d 100755 (executable)
@@ -6,7 +6,7 @@ from daklib.dbconn import Architecture, Suite, get_suite_architectures, \
     get_architecture_suites, Maintainer, DBSource, Location, PoolFile, \
     check_poolfile, get_poolfile_like_name, get_source_in_suite, \
     get_suites_source_in, add_dsc_to_db, source_exists, DBBinary, \
-    get_suites_binary_in, add_deb_to_db
+    get_suites_binary_in, add_deb_to_db, Component
 from daklib.queue_install import package_to_suite
 from daklib.queue import get_newest_source, get_suite_version_by_source, \
     get_source_by_package_and_suite, get_suite_version_by_package
@@ -62,16 +62,29 @@ class PackageTestCase(DBDakTestCase):
         self.arch['all'].arch_id = 2
         self.session.add_all(self.arch.values())
 
+    def setup_components(self):
+        'create some Component objects'
+
+        if 'comp' in self.__dict__:
+            return
+        self.comp = {}
+        self.comp['main'] = Component(component_name = 'main')
+        self.comp['contrib'] = Component(component_name = 'contrib')
+        self.session.add_all(self.comp.values())
+
     def setup_locations(self):
-        'create some Location objects, TODO: add component'
+        'create some Location objects'
 
         if 'loc' in self.__dict__:
             return
+        self.setup_components()
         self.loc = {}
-        self.loc['main'] = Location(path = \
-            '/srv/ftp-master.debian.org/ftp/pool/')
-        self.loc['contrib'] = Location(path = \
-            '/srv/ftp-master.debian.org/ftp/pool/')
+        self.loc['main'] = Location( \
+            path = '/srv/ftp-master.debian.org/ftp/pool/', \
+            component = self.comp['main'])
+        self.loc['contrib'] = Location( \
+            path = '/srv/ftp-master.debian.org/ftp/pool/', \
+            component = self.comp['contrib'])
         self.session.add_all(self.loc.values())
 
     def setup_poolfiles(self):
@@ -504,5 +517,11 @@ class PackageTestCase(DBDakTestCase):
         result = get_suite_version_by_package('python-hello', 'amd64', self.session)
         self.assertEqual([('squeeze', '2.2-1')], result)
 
+    def test_components(self):
+        'test class Component'
+
+        self.assertEqual(self.loc['main'], self.comp['main'].location)
+        self.assertEqual(self.loc['contrib'], self.comp['contrib'].location)
+
 if __name__ == '__main__':
     unittest.main()