diff options
Diffstat (limited to 'portato/db')
-rw-r--r-- | portato/db/__init__.py | 4 | ||||
-rw-r--r-- | portato/db/database.py | 35 | ||||
-rw-r--r-- | portato/db/eix_sql.py | 9 | ||||
-rw-r--r-- | portato/db/hash.py | 5 | ||||
-rw-r--r-- | portato/db/sql.py | 28 |
5 files changed, 67 insertions, 14 deletions
diff --git a/portato/db/__init__.py b/portato/db/__init__.py index 9d21d3b..21f72ce 100644 --- a/portato/db/__init__.py +++ b/portato/db/__init__.py @@ -3,7 +3,7 @@ # File: portato/db/__init__.py # This file is part of the Portato-Project, a graphical portage-frontend. # -# Copyright (C) 2006-2009 René 'Necoro' Neumann +# Copyright (C) 2006-2010 René 'Necoro' Neumann # This is free software. You may redistribute copies of it under the terms of # the GNU General Public License version 2. # There is NO WARRANTY, to the extent permitted by law. @@ -26,7 +26,7 @@ _DATABASE = None types = { "sql": (_("SQLite"), _("Uses an SQLite-database to store package information.\nMay take longer to generate at the first time, but has advantages if portato is re-started with an unchanged portage tree. Additionally it allows to use fast SQL expressions for fetching the data.")), "dict": (_("Hashmap"), _("Uses an in-memory hashmap to store package information.\nHas been used since at least version 0.3.3, but all information has to be regenerated on each startup.")), - "eixsql" : (_("eix + SQLite"), _("Similar to SQLite, but now uses the eix database to get the package information.\nThis should be much faster on startup, but requires that your eix database is always up-to-date.")) + "eixsql" : (_("eix + SQLite"), _("Similar to SQLite, but now uses the eix database to get the package information.\nThis should be much faster on startup, but requires that your eix database is always up-to-date.\nAdditionally, this is the only database allowing searching in descriptions.")) } def Database(type = None): diff --git a/portato/db/database.py b/portato/db/database.py index 7a23e5e..6e92d79 100644 --- a/portato/db/database.py +++ b/portato/db/database.py @@ -3,7 +3,7 @@ # File: portato/db/database.py # This file is part of the Portato-Project, a graphical portage-frontend. # -# Copyright (C) 2006-2009 René 'Necoro' Neumann +# Copyright (C) 2006-2010 René 'Necoro' Neumann # This is free software. You may redistribute copies of it under the terms of # the GNU General Public License version 2. # There is NO WARRANTY, to the extent permitted by law. @@ -14,6 +14,10 @@ from __future__ import absolute_import, with_statement from threading import RLock from functools import wraps +from ..helper import warning + +class UnsupportedSearchTypeError(Exception): + pass class PkgData (object): __slots__ = ("cat", "pkg", "inst", "disabled") @@ -37,8 +41,19 @@ class Database (object): ALL = _("ALL") + SEARCH_NAME = 1 + SEARCH_DESCRIPTION = 2 + + TYPES = { + SEARCH_NAME : _("Name"), + SEARCH_DESCRIPTION : _("Description"), + SEARCH_NAME | SEARCH_DESCRIPTION : "%s + %s" % (_("Name"), _("Description")) + } + + def __init__ (self): self._lock = RLock() + self.type = self.SEARCH_NAME @staticmethod def lock (f): @@ -51,6 +66,24 @@ 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() != type: + 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. diff --git a/portato/db/eix_sql.py b/portato/db/eix_sql.py index c2d2292..75bcb1e 100644 --- a/portato/db/eix_sql.py +++ b/portato/db/eix_sql.py @@ -3,7 +3,7 @@ # File: portato/db/eix_sql.py # This file is part of the Portato-Project, a graphical portage-frontend. # -# Copyright (C) 2006-2009 René 'Necoro' Neumann +# Copyright (C) 2006-2010 René 'Necoro' Neumann # This is free software. You may redistribute copies of it under the terms of # the GNU General Public License version 2. # There is NO WARRANTY, to the extent permitted by law. @@ -41,6 +41,9 @@ class EixSQLDatabase (SQLDatabase): SQLDatabase.__init__(self, session) + def search_types(self): + return self.SEARCH_NAME | self.SEARCH_DESCRIPTION + def updated (self): mtime = os.stat(self.cache).st_mtime old = self.session.get("mtime", 0) @@ -63,7 +66,7 @@ class EixSQLDatabase (SQLDatabase): if category is None or cat.name == category: for pkg in cat.packages: p = "%s/%s" % (cat.name, pkg.name) - yield (cat.name, pkg.name, p in inst, False) + yield (cat.name, pkg.name, pkg.description, p in inst, False) - connection.executemany("INSERT INTO packages (cat, name, inst, disabled) VALUES (?, ?, ?, ?)", _get()) + connection.executemany("INSERT INTO packages (cat, name, descr, inst, disabled) VALUES (?, ?, ?, ?, ?)", _get()) connection.commit() diff --git a/portato/db/hash.py b/portato/db/hash.py index 8cea6f2..4a6958b 100644 --- a/portato/db/hash.py +++ b/portato/db/hash.py @@ -3,7 +3,7 @@ # File: portato/db/hash.py # This file is part of the Portato-Project, a graphical portage-frontend. # -# Copyright (C) 2006-2009 René 'Necoro' Neumann +# Copyright (C) 2006-2010 René 'Necoro' Neumann # This is free software. You may redistribute copies of it under the terms of # the GNU General Public License version 2. # There is NO WARRANTY, to the extent permitted by law. @@ -32,6 +32,9 @@ class HashDatabase (Database): self.__initialize() self.populate() + def search_types(self): + return Database.SEARCH_NAME + def __initialize (self): self._db = defaultdict(list) self.inst_cats = set([self.ALL]) diff --git a/portato/db/sql.py b/portato/db/sql.py index fbc01e6..a9c27ab 100644 --- a/portato/db/sql.py +++ b/portato/db/sql.py @@ -3,7 +3,7 @@ # File: portato/db/sql.py # This file is part of the Portato-Project, a graphical portage-frontend. # -# Copyright (C) 2006-2009 René 'Necoro' Neumann +# Copyright (C) 2006-2010 René 'Necoro' Neumann # This is free software. You may redistribute copies of it under the terms of # the GNU General Public License version 2. # There is NO WARRANTY, to the extent permitted by law. @@ -34,7 +34,7 @@ from .database import Database, PkgData class SQLDatabase (Database): - FORMAT = "1" + FORMAT = "2" FORBIDDEN = (".bzr", ".svn", ".git", "CVS", ".hg", "_darcs") lock = Database.lock @@ -68,6 +68,7 @@ class SQLDatabase (Database): ( name TEXT, cat TEXT, + descr TEXT DEFAULT "", inst INTEGER, disabled INTEGER )""") @@ -83,6 +84,9 @@ class SQLDatabase (Database): pkg_conn.close() + def search_types(self): + return self.SEARCH_NAME + def updated (self): changed = False @@ -253,12 +257,22 @@ class SQLDatabase (Database): self._restrict = "" else: restrict = restrict.replace(".*","%").replace(".","_") + rest = "" + + if self._type & self.SEARCH_NAME: + if "/" in restrict: + rest = "(name LIKE '%s%%' AND cat LIKE '%s')" % (pkg, cat) + else: + rest = "(name LIKE '%%%(restrict)s%%' OR cat LIKE '%(restrict)s%%')" % {"restrict":restrict} - if "/" in restrict: - cat,pkg = restrict.split("/") - self._restrict = "AND name LIKE '%s%%' AND cat LIKE '%s'" % (pkg, cat) - else: - self._restrict = "AND (name LIKE '%%%(restrict)s%%' OR cat LIKE '%(restrict)s%%')" % {"restrict":restrict} + if self._type & self.SEARCH_DESCRIPTION: + r = "descr LIKE '%%%(restrict)s%%'" % {"restrict":restrict} + if rest: + rest = "(%s OR %s)" % (r, rest) + else: + rest = r + + self._restrict = "AND " + rest restrict = property(get_restrict, set_restrict) con = staticmethod(con) |