summaryrefslogtreecommitdiff
path: root/portato/db
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2009-08-14 23:57:35 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2009-08-14 23:57:35 +0200
commite4c2a57cdbb9082ce1cab7cbbfad122b16c56ff1 (patch)
treeb8b21b600c086aa9295af7317202476034930592 /portato/db
parentc916c961f34f47fdb25d5384370b0aed7e90ea49 (diff)
parent8d2b915b7705ba7d831d48ce9623ca8fe46f6f38 (diff)
downloadportato-e4c2a57cdbb9082ce1cab7cbbfad122b16c56ff1.tar.gz
portato-e4c2a57cdbb9082ce1cab7cbbfad122b16c56ff1.tar.bz2
portato-e4c2a57cdbb9082ce1cab7cbbfad122b16c56ff1.zip
Merged in eix-branch
Diffstat (limited to 'portato/db')
-rw-r--r--portato/db/__init__.py16
-rw-r--r--portato/db/eix_sql.py65
-rw-r--r--portato/db/hash.py (renamed from portato/db/dict.py)4
-rw-r--r--portato/db/sql.py3
4 files changed, 80 insertions, 8 deletions
diff --git a/portato/db/__init__.py b/portato/db/__init__.py
index da8a81e..9869e3f 100644
--- a/portato/db/__init__.py
+++ b/portato/db/__init__.py
@@ -22,7 +22,8 @@ _SESSION = 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."))
+ "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."))
}
def Database(type):
@@ -40,13 +41,18 @@ def Database(type):
warning(_("Cannot load SQLDatabase."))
return Database("dict")
else:
- return SQLDatabase(SectionDict(_SESSION, "SQL"))
+ return SQLDatabase(SectionDict(_SESSION, type))
elif type == "dict":
- debug("Using DictDatabase")
- from .dict import DictDatabase
- return DictDatabase(SectionDict(_SESSION, "dict"))
+ debug("Using HashDatabase")
+ from .hash import HashDatabase
+ return HashDatabase(SectionDict(_SESSION, type))
+ elif type == "eixsql":
+ debug("Using EixSQLDatabase")
+ from .eix_sql import EixSQLDatabase
+ return EixSQLDatabase(SectionDict(_SESSION, type))
+
else:
error(_("Unknown database type: %s"), type)
raise UnknownDatabaseTypeError, type
diff --git a/portato/db/eix_sql.py b/portato/db/eix_sql.py
new file mode 100644
index 0000000..3a0c6e9
--- /dev/null
+++ b/portato/db/eix_sql.py
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+#
+# 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
+# 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.
+#
+# Written by René 'Necoro' Neumann <necoro@necoro.net>
+
+from __future__ import absolute_import, with_statement
+
+try:
+ import sqlite3 as sql
+except ImportError:
+ from pysqlite2 import dbapi2 as sql
+
+import os
+
+from .sql import SQLDatabase
+from ..eix import EixReader
+from ..helper import debug, warning
+from ..backend import system
+
+class EixSQLDatabase (SQLDatabase):
+
+ CACHE_FILE = "/var/cache/eix"
+
+ def __init__ (self, session):
+
+ self.cache = session.get("cache", self.CACHE_FILE)
+ if not os.path.exists(self.cache):
+ warning(_("Cache file '%s' does not exist. Using default instead."), self.cache)
+ self.cache = self.CACHE_FILE
+
+ debug("Using '%s' as eix cache file.", self.cache)
+
+ session["cache"] = self.cache
+
+ SQLDatabase.__init__(self, session)
+
+ def updated (self):
+ mtime = os.stat(self.cache).st_mtime
+ old = self.session.get("mtime", 0)
+
+ self.session["mtime"] = str(mtime)
+
+ return old < mtime
+
+ @SQLDatabase.con
+ def populate (self, category = None, connection = None):
+ inst = set(system.find_packages(pkgSet = system.SET_INSTALLED, key = category, with_version = False))
+
+ def _get():
+ with EixReader(self.cache) as eix:
+ for cat in eix.categories:
+ 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)
+
+ connection.executemany("INSERT INTO packages (cat, name, inst, disabled) VALUES (?, ?, ?, ?)", _get())
+ connection.commit()
diff --git a/portato/db/dict.py b/portato/db/hash.py
index 279ab97..8cea6f2 100644
--- a/portato/db/dict.py
+++ b/portato/db/hash.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# File: portato/db/dict.py
+# File: portato/db/hash.py
# This file is part of the Portato-Project, a graphical portage-frontend.
#
# Copyright (C) 2006-2009 René 'Necoro' Neumann
@@ -19,7 +19,7 @@ from ..helper import info
from ..backend import system
from .database import Database, PkgData
-class DictDatabase (Database):
+class HashDatabase (Database):
"""An internal database which holds a simple dictionary cat -> [package_list]."""
lock = Database.lock
diff --git a/portato/db/sql.py b/portato/db/sql.py
index db66764..e79a27d 100644
--- a/portato/db/sql.py
+++ b/portato/db/sql.py
@@ -166,7 +166,7 @@ class SQLDatabase (Database):
def populate (self, category = None, connection = None):
def _get():
# get the lists
- inst = system.find_packages(pkgSet = system.SET_INSTALLED, key=category, with_version = False)
+ inst = set(system.find_packages(pkgSet = system.SET_INSTALLED, key=category, with_version = False))
for p in system.find_packages(key = category, with_version = False):
cat, pkg = p.split("/")
@@ -247,3 +247,4 @@ class SQLDatabase (Database):
self._restrict = "AND (name LIKE '%%%(restrict)s%%' OR cat LIKE '%(restrict)s%%')" % {"restrict":restrict}
restrict = property(get_restrict, set_restrict)
+ con = staticmethod(con)