From bb95009b602311c280b4649aa6615099ceca11c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Fri, 5 Mar 2010 01:51:35 +0100 Subject: Add description support to the databases --- portato/db/database.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'portato/db/database.py') diff --git a/portato/db/database.py b/portato/db/database.py index 7a23e5e..67ac554 100644 --- a/portato/db/database.py +++ b/portato/db/database.py @@ -14,6 +14,10 @@ from __future__ import absolute_import, with_statement from threading import RLock from functools import wraps +from ..helper import error + +class UnsupportedSearchTypeError(Exception): + pass class PkgData (object): __slots__ = ("cat", "pkg", "inst", "disabled") @@ -37,8 +41,12 @@ class Database (object): ALL = _("ALL") + SEARCH_NAME = 1 + SEARCH_DESCRIPTION = 2 + def __init__ (self): self._lock = RLock() + self.type = self.SEARCH_NAME @staticmethod def lock (f): @@ -51,6 +59,25 @@ class Database (object): return wrapper + def search_types (self): + """The types of search supported by the database. + + @return: type + @rtype: int""" + raise NotImplentedError + + def set_type (self, type): + if type & self.search_types() == 0: + error("Search type %s not supported by database '%s'.", type, self.__class__.__name__) + raise UnsupportedSearchTypeError, type + + self._type = type + + def get_type (self): + return self._type + + type = property(get_type, set_type) + def populate (self, category = None): """Populates the database. -- cgit v1.2.3