From 33b8ae45109ebbbd62a560690ccbaf2c009772b1 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 6 Feb 2011 16:13:22 -0800 Subject: cache.sqlite: handle sqlite ImportError This will fix bug #353836. --- pym/portage/cache/sqlite.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'pym') diff --git a/pym/portage/cache/sqlite.py b/pym/portage/cache/sqlite.py index 2e13be320..d15b6ece1 100644 --- a/pym/portage/cache/sqlite.py +++ b/pym/portage/cache/sqlite.py @@ -1,4 +1,4 @@ -# Copyright 1999-2010 Gentoo Foundation +# Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import sys @@ -8,11 +8,6 @@ from portage import os from portage import _unicode_decode from portage.util import writemsg from portage.localization import _ -try: - import sqlite3 as db_module # sqlite3 is optional with >=python-2.5 -except ImportError: - from pysqlite2 import dbapi2 as db_module -DBError = db_module.Error if sys.hexversion >= 0x3000000: basestring = str @@ -25,12 +20,11 @@ class database(fs_template.FsBased): # to calculate the number of pages requested, according to the following # equation: cache_bytes = page_bytes * page_count cache_bytes = 1024 * 1024 * 10 - _db_module = db_module - _db_error = DBError _db_table = None def __init__(self, *args, **config): super(database, self).__init__(*args, **config) + self._import_sqlite() self._allowed_keys = ["_mtime_", "_eclasses_"] self._allowed_keys.extend(self._known_keys) self._allowed_keys.sort() @@ -49,6 +43,19 @@ class database(fs_template.FsBased): self._db_init_connection(config) self._db_init_structures() + def _import_sqlite(self): + # sqlite3 is optional with >=python-2.5 + try: + import sqlite3 as db_module + except ImportError: + try: + from pysqlite2 import dbapi2 as db_module + except ImportError as e: + raise cache_errors.InitializationError(self.__class__, e) + + self._db_module = db_module + self._db_error = db_module.Error + def _db_escape_string(self, s): """meta escaping, returns quoted string for use in sql statements""" if not isinstance(s, basestring): -- cgit v1.2.3-1-g7c22