From 261b162f4512609fb8fabd23f44e6ddc0536d43b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Thu, 20 May 2010 13:01:27 +0200 Subject: More declarative handling of the database types --- portato/db/__init__.py | 95 ++++++++++++++++++++++----------------- portato/db/exceptions.py | 2 + portato/gui/windows/preference.py | 8 ++-- 3 files changed, 59 insertions(+), 46 deletions(-) (limited to 'portato') diff --git a/portato/db/__init__.py b/portato/db/__init__.py index 21d8f80..bb5c6fc 100644 --- a/portato/db/__init__.py +++ b/portato/db/__init__.py @@ -12,66 +12,79 @@ from __future__ import absolute_import +from collections import namedtuple + from . import database as db -from .exceptions import UnknownDatabaseTypeError, DatabaseInstantiationError +from .exceptions import UnknownDatabaseTypeError, DatabaseInstantiationError, DatabaseInitError from ..session import Session, SectionDict from ..helper import debug, warning, error, info +from ..odict import OrderedDict + +DBType = namedtuple("DBType", "name descr module cls alt") + +types = [ + ("eixsql", + DBType( + _("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."), + "eix_sql", "EixSQLDatabase", + "sql")), + ("sql", + DBType( + _("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."), + "sql", "SQLDatabase", + "dict")), + ("dict", + DBType( + _("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."), + "hash", "HashDatabase", + None)) + ] -types = ( - ("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.")), - ("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.")) - ) +types = OrderedDict(types) class Database(db.Database): DEFAULT = "dict" def __new__ (cls, type = None): - if not '_the_instance' in cls.__dict__: - dbcls = cls._generate(type) - cls._the_instance = dbcls(cls._get_session()) - elif type is not None: - raise DatabaseInstantiationError("Database instantiation called with 'type' argument multiple times.") + try: + if not '_the_instance' in cls.__dict__: + dbcls = cls._generate(type) + cls._the_instance = dbcls(cls._get_session()) + elif type is not None: + raise DatabaseInstantiationError("Database instantiation called with 'type' argument multiple times.") + except (ImportError, DatabaseInitError) as e: + db = types[cls.DB_TYPE] + error(_("Cannot load %s."), db.cls) + error(_("Error: %s"), e) + + if db.alt is not None: + return cls.__new__(cls, db.alt) + else: + error(_("No alternative database given. Aborting.")) + raise DatabaseInstantiationError("Cannot load database.") + return cls._the_instance @classmethod def _generate(cls, type): - if type is None: warning("No database type specified! Falling back to default.") type = cls.DEFAULT - - cls.DB_TYPE = type - msg = _("Using database type '%s'") - if type == "sql": - info(msg, "SQLDatabase") - try: - from .sql import SQLDatabase - except ImportError: - warning(_("Cannot load %s."), "SQLDatabase") - return cls._generate("dict") - else: - return SQLDatabase - - elif type == "dict": - info(msg, "HashDatabase") - from .hash import HashDatabase - return HashDatabase - - elif type == "eixsql": - info(msg,"EixSQLDatabase") - try: - from .eix_sql import EixSQLDatabase - except ImportError: - warning(_("Cannot load %s."), "EixSQLDatabase.") - return cls._generate("sql") - else: - return EixSQLDatabase - - else: + try: + db = types[type] + except KeyError: error(_("Unknown database type: %s"), type) raise UnknownDatabaseTypeError, type + + cls.DB_TYPE = type + info(_("Using database type '%s'"), db.cls) + + mod = __import__(db.module, globals(), locals(), [db.cls]) + return getattr(mod, db.cls) @classmethod def _get_session(cls): diff --git a/portato/db/exceptions.py b/portato/db/exceptions.py index 8a6e424..82fa337 100644 --- a/portato/db/exceptions.py +++ b/portato/db/exceptions.py @@ -22,3 +22,5 @@ class DatabaseInstantiationError (DatabaseError): class UnsupportedSearchTypeError(DatabaseError): pass +class DatabaseInitError (DatabaseError): + pass diff --git a/portato/gui/windows/preference.py b/portato/gui/windows/preference.py index 2b6974e..dd2a892 100644 --- a/portato/gui/windows/preference.py +++ b/portato/gui/windows/preference.py @@ -168,14 +168,12 @@ class PreferenceWindow (AbstractDialog): self.databaseCombo = self.tree.get_widget("databaseCombo") model = gtk.ListStore(str, str, str) - ctr = 0 active = 0 - for k, name, desc in db.types: - if k == dbtype: + for ctr, (key, t) in enumerate(db.types.iteritems()): + if key == dbtype: active = ctr - model.append([name, desc, k]) - ctr += 1 + model.append([t.name, t.descr, key]) self.databaseCombo.set_model(model) self.databaseCombo.set_active(active) -- cgit v1.2.3 From bf961022b5e191e897e68f69784425d2c8166968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Thu, 20 May 2010 13:02:29 +0200 Subject: Handle missing eix-cache file more gracefully --- portato/db/eix_sql.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'portato') diff --git a/portato/db/eix_sql.py b/portato/db/eix_sql.py index 758f42c..58b0acc 100644 --- a/portato/db/eix_sql.py +++ b/portato/db/eix_sql.py @@ -20,10 +20,14 @@ except ImportError: import os from .sql import SQLDatabase +from .exceptions import DatabaseInitError from ..eix import EixReader from ..helper import debug, warning from ..backend import system +class EixInitError (DatabaseInitError): + pass + class EixSQLDatabase (SQLDatabase): CACHE_FILE = "/var/cache/eix" @@ -35,6 +39,9 @@ class EixSQLDatabase (SQLDatabase): warning(_("Cache file '%s' does not exist. Using default instead."), self.cache) self.cache = self.CACHE_FILE + if not os.path.exists(self.cache): + raise EixInitError(_("Cache file '%s' does not exist.") % self.cache) + debug("Using '%s' as eix cache file.", self.cache) session["cache"] = self.cache -- cgit v1.2.3 From 24ba9cba2c307a092c95f68c2531cd3e0ead7b6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Sat, 22 May 2010 20:27:33 +0200 Subject: Fix the link buttons --- portato/gui/windows/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'portato') diff --git a/portato/gui/windows/main.py b/portato/gui/windows/main.py index de62f45..7cf20e1 100644 --- a/portato/gui/windows/main.py +++ b/portato/gui/windows/main.py @@ -175,7 +175,7 @@ class PackageTable: ftexts.append(t) for t in ftexts: - link = gtk.LinkButton(t) + link = gtk.LinkButton(uri = t, label = t) link.set_alignment(0.0, 0.5) link.set_border_width(0) self.linkBox.add(link) -- cgit v1.2.3 From fd0724455c9df3a2e77e15bdc81011875051224f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Sat, 22 May 2010 20:31:44 +0200 Subject: Update gtk-version in glade files --- portato/gui/templates/AboutWindow.ui | 2 +- portato/gui/templates/MailInfoWindow.ui | 2 +- portato/gui/templates/MainWindow.ui | 2 +- portato/gui/templates/PkgListWindow.ui | 2 +- portato/gui/templates/PluginWindow.ui | 2 +- portato/gui/templates/PreferenceWindow.ui | 2 +- portato/gui/templates/SearchWindow.ui | 2 +- portato/gui/templates/SplashScreen.ui | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'portato') diff --git a/portato/gui/templates/AboutWindow.ui b/portato/gui/templates/AboutWindow.ui index 893958a..79c8522 100644 --- a/portato/gui/templates/AboutWindow.ui +++ b/portato/gui/templates/AboutWindow.ui @@ -1,6 +1,6 @@ - + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/portato/gui/templates/MailInfoWindow.ui b/portato/gui/templates/MailInfoWindow.ui index e3cdd1f..fec34ed 100644 --- a/portato/gui/templates/MailInfoWindow.ui +++ b/portato/gui/templates/MailInfoWindow.ui @@ -1,6 +1,6 @@ - + Send Bug Mail ... diff --git a/portato/gui/templates/MainWindow.ui b/portato/gui/templates/MainWindow.ui index 2eaaae1..63cf225 100644 --- a/portato/gui/templates/MainWindow.ui +++ b/portato/gui/templates/MainWindow.ui @@ -1,6 +1,6 @@ - + 2 diff --git a/portato/gui/templates/PkgListWindow.ui b/portato/gui/templates/PkgListWindow.ui index fdcdb23..80ba5c7 100644 --- a/portato/gui/templates/PkgListWindow.ui +++ b/portato/gui/templates/PkgListWindow.ui @@ -1,6 +1,6 @@ - + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/portato/gui/templates/PluginWindow.ui b/portato/gui/templates/PluginWindow.ui index 42a3156..fed260c 100644 --- a/portato/gui/templates/PluginWindow.ui +++ b/portato/gui/templates/PluginWindow.ui @@ -1,6 +1,6 @@ - + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/portato/gui/templates/PreferenceWindow.ui b/portato/gui/templates/PreferenceWindow.ui index 0f0a16f..1e8bf7d 100644 --- a/portato/gui/templates/PreferenceWindow.ui +++ b/portato/gui/templates/PreferenceWindow.ui @@ -1,6 +1,6 @@ - + 300 diff --git a/portato/gui/templates/SearchWindow.ui b/portato/gui/templates/SearchWindow.ui index f62d259..fa17396 100644 --- a/portato/gui/templates/SearchWindow.ui +++ b/portato/gui/templates/SearchWindow.ui @@ -1,6 +1,6 @@ - + 350 diff --git a/portato/gui/templates/SplashScreen.ui b/portato/gui/templates/SplashScreen.ui index c136062..2cc5152 100644 --- a/portato/gui/templates/SplashScreen.ui +++ b/portato/gui/templates/SplashScreen.ui @@ -1,6 +1,6 @@ - + 300 -- cgit v1.2.3 From 7b831112022ce45c6c683bd5c9c9b41a8c3c6015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Tue, 25 May 2010 20:50:51 +0200 Subject: Do not bail out, if we try to replace stuff in a category w/o a dash --- portato/backend/flags.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'portato') diff --git a/portato/backend/flags.py b/portato/backend/flags.py index 810b607..6c74024 100644 --- a/portato/backend/flags.py +++ b/portato/backend/flags.py @@ -159,11 +159,17 @@ def generate_path (cpv, exp): cat, pkg, ver, rev = system.split_cpv(cpv) if rev != "r0": ver = "%s-%s" % (ver, rev) + exp = exp.replace("$(cat)",cat).\ replace("$(pkg)",pkg).\ replace("$(cat-1)",cat.split("-")[0]).\ - replace("$(cat-2)",cat.split("-")[1]).\ replace("$(version)",ver) + + try: + exp = exp.replace("$(cat-2)",cat.split("-")[1]) + except IndexError: # category only consists of one part -- ignore + pass + return exp ### USE FLAG PART ### -- cgit v1.2.3 From 7191bedb01980674fc99ee5a29042c90a0177101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Tue, 6 Jul 2010 21:27:15 +0200 Subject: format strings need tuples --- portato/db/sql.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'portato') diff --git a/portato/db/sql.py b/portato/db/sql.py index 2de2795..889789f 100644 --- a/portato/db/sql.py +++ b/portato/db/sql.py @@ -263,7 +263,7 @@ class SQLDatabase (Database): if self._type & self.SEARCH_NAME: if "/" in restrict: - rest = "(name LIKE '%s%%' AND cat LIKE '%s')" % restrict.split("/",1) + rest = "(name LIKE '%s%%' AND cat LIKE '%s')" % tuple(restrict.split("/",1)) else: rest = "(name LIKE '%%%(restrict)s%%' OR cat LIKE '%(restrict)s%%')" % {"restrict":restrict} -- cgit v1.2.3 From 7614c3c1b33441c785cc204b7d47529ed8f9c473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Sat, 4 Sep 2010 03:59:43 +0200 Subject: Fix system.split_cpv --- portato/backend/portage/system.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'portato') diff --git a/portato/backend/portage/system.py b/portato/backend/portage/system.py index 990a39a..030c120 100644 --- a/portato/backend/portage/system.py +++ b/portato/backend/portage/system.py @@ -235,7 +235,11 @@ class PortageSystem (SystemInterface): return filter(self.find_lambda(name), categories) def split_cpv (self, cpv): - cpv = portage.dep_getcpv(cpv) + try: + cpv = portage.dep_getcpv(cpv) + except portage.exception.InvalidAtom: + pass + return portage.catpkgsplit(cpv) def sort_package_list(self, pkglist, only_cpv = False): -- cgit v1.2.3 From 7e345560e77158b6b8b301abcaf959c1e832d668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Mon, 6 Sep 2010 17:09:36 +0200 Subject: Gnah - changing portage-API --- portato/backend/portage/settings_22.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'portato') diff --git a/portato/backend/portage/settings_22.py b/portato/backend/portage/settings_22.py index ba4f1e8..325e4e3 100644 --- a/portato/backend/portage/settings_22.py +++ b/portato/backend/portage/settings_22.py @@ -12,7 +12,11 @@ from __future__ import absolute_import -import portage.sets +try: + import portage.sets as psets +except ImportError: + import portage._sets as psets + from .settings import PortageSettings class PortageSettings_22 (PortageSettings): @@ -24,4 +28,4 @@ class PortageSettings_22 (PortageSettings): def load (self): PortageSettings.load(self) - self.setsconfig = portage.sets.load_default_config(self.settings, self.trees[self.settings["ROOT"]]) + self.setsconfig = psets.load_default_config(self.settings, self.trees[self.settings["ROOT"]]) -- cgit v1.2.3 From 6a25d98dfbed84d0294fbff6e0db99113c6490b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Mon, 6 Sep 2010 17:09:59 +0200 Subject: Workaround for bug#557715 --- portato/backend/portage/system.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'portato') diff --git a/portato/backend/portage/system.py b/portato/backend/portage/system.py index 030c120..b86a8f7 100644 --- a/portato/backend/portage/system.py +++ b/portato/backend/portage/system.py @@ -289,12 +289,15 @@ class PortageSystem (SystemInterface): if len(inst) > 1: myslots = set() + splitp = p.split('[', 1) # split away the useflags for i in inst: # get the slots of the installed packages myslots.add(i.get_package_settings("SLOT")) myslots.add(best_p.get_package_settings("SLOT")) # add the slot of the best package in portage for slot in myslots: - crit = "%s:%s" % (p, slot) + crit = splitp[:] + crit[0] = "%s:%s" % (crit[0], slot) + crit = "[".join(crit) # re-add possible useflags append(crit, self.find_best_match(crit), inst) else: append(p, best_p, inst) -- cgit v1.2.3 From 9e5d14fd6fe250f1239928e51fe5430b14c9bc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Mon, 6 Sep 2010 17:14:39 +0200 Subject: Handle portage-2.1.9 and above as portage-2.2 --- portato/backend/portage/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'portato') diff --git a/portato/backend/portage/__init__.py b/portato/backend/portage/__init__.py index e559f9e..5bd324f 100644 --- a/portato/backend/portage/__init__.py +++ b/portato/backend/portage/__init__.py @@ -17,7 +17,7 @@ from portage import VERSION as PV VERSION = tuple(map(int, (x.split("_")[0] for x in PV.split(".")))) -if VERSION >= (2, 2): +if VERSION >= (2, 2) or VERSION >= (2, 1, 9): debug("Using portage-2.2") from .system_22 import PortageSystem_22 as PortageSystem from .package_22 import PortagePackage_22 as PortagePackage -- cgit v1.2.3 From 9db89dab613718eabd50f54540111093141060c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Mon, 6 Sep 2010 17:16:41 +0200 Subject: Handle portage-2.1.8 and above as portage-2.2 --- portato/backend/portage/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'portato') diff --git a/portato/backend/portage/__init__.py b/portato/backend/portage/__init__.py index 5bd324f..11bdd89 100644 --- a/portato/backend/portage/__init__.py +++ b/portato/backend/portage/__init__.py @@ -17,7 +17,7 @@ from portage import VERSION as PV VERSION = tuple(map(int, (x.split("_")[0] for x in PV.split(".")))) -if VERSION >= (2, 2) or VERSION >= (2, 1, 9): +if VERSION >= (2, 2) or VERSION >= (2, 1, 8): debug("Using portage-2.2") from .system_22 import PortageSystem_22 as PortageSystem from .package_22 import PortagePackage_22 as PortagePackage -- cgit v1.2.3