__all__.append('get_sources_from_name')
-# FIXME: This function fails badly if it finds more than 1 source package.
+# FIXME: This function fails badly if it finds more than 1 source package and
+# its implementation is trivial enough to be inlined.
@session_wrapper
def get_source_in_suite(source, suite, session=None):
"""
"""
- q = session.query(DBSource).filter_by(source = source). \
- filter(DBSource.suites.any(Suite.suite_name == suite))
-
+ q = get_suite(suite, session).get_sources(source)
try:
return q.one()
except NoResultFound:
('CopyChanges', 'copychanges'),
('OverrideSuite', 'overridesuite')]
+# Why the heck don't we have any UNIQUE constraints in table suite?
+# TODO: Add UNIQUE constraints for appropriate columns.
class Suite(object):
def __init__(self, suite_name = None, version = None):
self.suite_name = suite_name
q = q.filter(Architecture.arch_string != 'all')
return q.order_by(Architecture.arch_string).all()
+ def get_sources(self, source):
+ """
+ Returns a query object representing DBSource that is part of C{suite}.
+
+ - B{source} - source package name, eg. I{mailfilter}, I{bbdb}, I{glibc}
+
+ @type source: string
+ @param source: source package name
+
+ @rtype: sqlalchemy.orm.query.Query
+ @return: a query of DBSource
+
+ """
+
+ session = object_session(self)
+ return session.query(DBSource).filter_by(source = source). \
+ filter(DBSource.suites.contains(self))
+
__all__.append('Suite')
@session_wrapper
database.
"""
+ def setup_suites(self):
+ "setup a hash of Suite objects in self.suite"
+
+ if 'suite' in self.__dict__:
+ return
+ self.suite = {}
+ for suite_name in ('lenny', 'squeeze', 'sid'):
+ self.suite[suite_name] = Suite(suite_name = suite_name, version = '-')
+ self.session.add_all(self.suite.values())
+
def setup_architectures(self):
- "setup a hash of Architecture objects in self.arch"
+ "setup Architecture objects in self.arch and connect to suites"
+ if 'arch' in self.__dict__:
+ return
+ self.setup_suites()
self.arch = {}
for arch_string in ('source', 'all', 'i386', 'amd64', 'kfreebsd-i386'):
self.arch[arch_string] = Architecture(arch_string)
+ if arch_string != 'kfreebsd-i386':
+ self.arch[arch_string].suites = self.suite.values()
+ else:
+ self.arch[arch_string].suites = [self.suite['squeeze'], self.suite['sid']]
# hard code ids for source and all
self.arch['source'].arch_id = 1
self.arch['all'].arch_id = 2
self.session.add_all(self.arch.values())
- def setup_suites(self):
- "setup a hash of Suite objects in self.suite"
-
- self.suite = {}
- for suite_name in ('lenny', 'squeeze', 'sid'):
- self.suite[suite_name] = Suite(suite_name = suite_name, version = '-')
- self.session.add_all(self.suite.values())
-
def setUp(self):
super(PackageTestCase, self).setUp()
self.setup_architectures()
self.setup_suites()
- def connect_suite_architectures(self):
- """
- Gonnect all suites and all architectures except for kfreebsd-i386 which
- should not be in lenny.
- """
-
- for arch_string, architecture in self.arch.items():
- if arch_string != 'kfreebsd-i386':
- architecture.suites = self.suite.values()
- else:
- architecture.suites = [self.suite['squeeze'], self.suite['sid']]
-
def test_suite_architecture(self):
# check the id for architectures source and all
self.assertEqual(1, self.arch['source'].arch_id)
self.assertEqual(2, self.arch['all'].arch_id)
# check the many to many relation between Suite and Architecture
- self.arch['source'].suites.append(self.suite['lenny'])
self.assertEqual('source', self.suite['lenny'].architectures[0])
- self.arch['source'].suites = []
- self.assertEqual([], self.suite['lenny'].architectures)
- self.connect_suite_architectures()
self.assertEqual(4, len(self.suite['lenny'].architectures))
self.assertEqual(3, len(self.arch['i386'].suites))
# check the function get_suite_architectures()
def setup_locations(self):
'create some Location objects, TODO: add component'
+ if 'loc' in self.__dict__:
+ return
self.loc = {}
self.loc['main'] = Location(path = \
'/srv/ftp-master.debian.org/ftp/pool/')
def setup_poolfiles(self):
'create some PoolFile objects'
+ if 'file' in self.__dict__:
+ return
self.setup_locations()
self.file = {}
self.file['hello'] = PoolFile(filename = 'main/h/hello/hello_2.2-2.dsc', \
def setup_maintainers(self):
'create some Maintainer objects'
+ if 'maintainer' in self.__dict__:
+ return
self.maintainer = {}
self.maintainer['maintainer'] = Maintainer(name = 'Mr. Maintainer')
self.maintainer['uploader'] = Maintainer(name = 'Mrs. Uploader')
def setup_sources(self):
'create a DBSource object; but it cannot be stored in the DB yet'
+ if 'source' in self.__dict__:
+ return
self.setup_maintainers()
self.setup_poolfiles()
self.setup_suites()
poolfile = self.file['sl'], install_date = self.now())
self.source['sl'].suites.append(self.suite['squeeze'])
self.source['sl'].suites.append(self.suite['sid'])
+ self.session.add_all(self.source.values())
def test_maintainers(self):
'''