summaryrefslogtreecommitdiff
path: root/portato
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--portato/db/database.py27
-rw-r--r--portato/db/eix_sql.py7
-rw-r--r--portato/db/hash.py3
-rw-r--r--portato/db/sql.py26
4 files changed, 55 insertions, 8 deletions
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.
diff --git a/portato/db/eix_sql.py b/portato/db/eix_sql.py
index c2d2292..39e556b 100644
--- a/portato/db/eix_sql.py
+++ b/portato/db/eix_sql.py
@@ -41,6 +41,9 @@ class EixSQLDatabase (SQLDatabase):
SQLDatabase.__init__(self, session)
+ def search_types(self):
+ return Database.SEARCH_NAME | Database.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.desription, 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..aa8c73e 100644
--- a/portato/db/hash.py
+++ b/portato/db/hash.py
@@ -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..48de9eb 100644
--- a/portato/db/sql.py
+++ b/portato/db/sql.py
@@ -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 Database.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 & Database.NAME_DESCRIPTION:
+ 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 & Database.SEARCH_DESCRIPTION:
+ r = "descr LIKE '%%%(restrict)s%%'" % {"restrict":restrict}
+ if not rest:
+ rest = "(%s OR %s)" % (r, rest)
+ else:
+ rest = r
+
+ self._restrict = "AND " + rest
restrict = property(get_restrict, set_restrict)
con = staticmethod(con)