diff options
author | Zac Medico <zmedico@gentoo.org> | 2011-02-06 16:13:22 -0800 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-02-06 16:29:08 -0800 |
commit | ad0f4abd188e3ba183f2ebd80eb23e1a7e919ed6 (patch) | |
tree | bf4e8fbafdedc91be8158ad5f66db8b2a0db3536 /pym | |
parent | 997e00c3ae05c543f03085e6f9d87cc062c67d8a (diff) | |
download | portage-ad0f4abd188e3ba183f2ebd80eb23e1a7e919ed6.tar.gz portage-ad0f4abd188e3ba183f2ebd80eb23e1a7e919ed6.tar.bz2 portage-ad0f4abd188e3ba183f2ebd80eb23e1a7e919ed6.zip |
cache.sqlite: handle sqlite ImportErrorv2.1.9.37
This will fix bug #353836.
Diffstat (limited to 'pym')
-rw-r--r-- | pym/portage/cache/sqlite.py | 23 |
1 files changed, 15 insertions, 8 deletions
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): |