- ## Cache functions
- def __init_caches(self):
- self.caches = {'suite': Cache(),
- 'section': Cache(),
- 'priority': Cache(),
- 'override_type': Cache(),
- 'architecture': Cache(),
- 'archive': Cache(),
- 'component': Cache(),
- 'content_path_names': Cache(),
- 'content_file_names': Cache(),
- 'location': Cache(lambda x: '%s_%s_%s' % (x['location'], x['component'], x['location'])),
- 'maintainer': {}, # TODO
- 'keyring': {}, # TODO
- 'source': Cache(lambda x: '%s_%s_' % (x['source'], x['version'])),
- 'files': Cache(lambda x: '%s_%s_' % (x['filename'], x['location'])),
- 'maintainer': {}, # TODO
- 'fingerprint': {}, # TODO
- 'queue': {}, # TODO
- 'uid': {}, # TODO
- 'suite_version': Cache(lambda x: '%s_%s' % (x['source'], x['suite'])),
- }
-
- self.prepared_statements = {}
-
- def prepare(self,name,statement):
- if not self.prepared_statements.has_key(name):
- pgc.execute(statement)
- self.prepared_statements[name] = statement
-
- def clear_caches(self):
- self.__init_caches()
-
- ## Get functions
- def __get_id(self, retfield, selectobj, cachekey, cachename=None):
- # This is a bit of a hack but it's an internal function only
- if cachename is not None:
- res = self.caches[cachename].GetValue(cachekey)
- if res:
- return res
-
- c = selectobj.execute()
-
- if c.rowcount != 1:
- return None
-
- res = c.fetchone()
-
- if retfield not in res.keys():
- return None
-
- res = res[retfield]
-
- if cachename is not None:
- self.caches[cachename].SetValue(cachekey, res)
-
- return res
-
- def get_suite_id(self, suite):
- """
- Returns database id for given C{suite}.
- Results are kept in a cache during runtime to minimize database queries.
-
- @type suite: string
- @param suite: The name of the suite
-
- @rtype: int
- @return: the database id for the given suite
-
- """
- return int(self.__get_id('id',
- self.tbl_suite.select(self.tbl_suite.columns.suite_name == suite),
- suite,
- 'suite'))
-
- def get_section_id(self, section):
- """
- Returns database id for given C{section}.
- Results are kept in a cache during runtime to minimize database queries.
-
- @type section: string
- @param section: The name of the section
-
- @rtype: int
- @return: the database id for the given section
-
- """
- return self.__get_id('id',
- self.tbl_section.select(self.tbl_section.columns.section == section),
- section,
- 'section')
-
- def get_priority_id(self, priority):
- """
- Returns database id for given C{priority}.
- Results are kept in a cache during runtime to minimize database queries.
-
- @type priority: string
- @param priority: The name of the priority
-
- @rtype: int
- @return: the database id for the given priority
-
- """
- return self.__get_id('id',
- self.tbl_priority.select(self.tbl_priority.columns.priority == priority),
- priority,
- 'priority')
-
- def get_override_type_id(self, override_type):
- """
- Returns database id for given override C{type}.
- Results are kept in a cache during runtime to minimize database queries.
-
- @type override_type: string
- @param override_type: The name of the override type
-
- @rtype: int
- @return: the database id for the given override type
-
- """
- return self.__get_id('id',
- self.tbl_override_type.select(self.tbl_override_type.columns.type == override_type),
- override_type,
- 'override_type')
-
- def get_architecture_id(self, architecture):
- """
- Returns database id for given C{architecture}.
- Results are kept in a cache during runtime to minimize database queries.
-
- @type architecture: string
- @param architecture: The name of the override type
-
- @rtype: int
- @return: the database id for the given architecture
-
- """
- return self.__get_id('id',
- self.tbl_architecture.select(self.tbl_architecture.columns.arch_string == architecture),
- architecture,
- 'architecture')