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:13:22 -0800 |
commit | 33b8ae45109ebbbd62a560690ccbaf2c009772b1 (patch) | |
tree | 4c6b538ab0c57ee56a2c2961b5043655d18aef2f | |
parent | b766bd9e9d60bcbeef24d29d16873f5374e95310 (diff) | |
download | portage-33b8ae45109ebbbd62a560690ccbaf2c009772b1.tar.gz portage-33b8ae45109ebbbd62a560690ccbaf2c009772b1.tar.bz2 portage-33b8ae45109ebbbd62a560690ccbaf2c009772b1.zip |
cache.sqlite: handle sqlite ImportErrorv2.2.0_alpha21
This will fix bug #353836.
-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): |