Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:2.1.9 commit in: pym/portage/cache/
Date: Mon, 07 Feb 2011 00:29:40
Message-Id: ad0f4abd188e3ba183f2ebd80eb23e1a7e919ed6.zmedico@gentoo
1 commit: ad0f4abd188e3ba183f2ebd80eb23e1a7e919ed6
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Mon Feb 7 00:13:22 2011 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Mon Feb 7 00:29:08 2011 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=ad0f4abd
7
8 cache.sqlite: handle sqlite ImportError
9
10 This will fix bug #353836.
11
12 ---
13 pym/portage/cache/sqlite.py | 23 +++++++++++++++--------
14 1 files changed, 15 insertions(+), 8 deletions(-)
15
16 diff --git a/pym/portage/cache/sqlite.py b/pym/portage/cache/sqlite.py
17 index 2e13be3..d15b6ec 100644
18 --- a/pym/portage/cache/sqlite.py
19 +++ b/pym/portage/cache/sqlite.py
20 @@ -1,4 +1,4 @@
21 -# Copyright 1999-2010 Gentoo Foundation
22 +# Copyright 1999-2011 Gentoo Foundation
23 # Distributed under the terms of the GNU General Public License v2
24
25 import sys
26 @@ -8,11 +8,6 @@ from portage import os
27 from portage import _unicode_decode
28 from portage.util import writemsg
29 from portage.localization import _
30 -try:
31 - import sqlite3 as db_module # sqlite3 is optional with >=python-2.5
32 -except ImportError:
33 - from pysqlite2 import dbapi2 as db_module
34 -DBError = db_module.Error
35
36 if sys.hexversion >= 0x3000000:
37 basestring = str
38 @@ -25,12 +20,11 @@ class database(fs_template.FsBased):
39 # to calculate the number of pages requested, according to the following
40 # equation: cache_bytes = page_bytes * page_count
41 cache_bytes = 1024 * 1024 * 10
42 - _db_module = db_module
43 - _db_error = DBError
44 _db_table = None
45
46 def __init__(self, *args, **config):
47 super(database, self).__init__(*args, **config)
48 + self._import_sqlite()
49 self._allowed_keys = ["_mtime_", "_eclasses_"]
50 self._allowed_keys.extend(self._known_keys)
51 self._allowed_keys.sort()
52 @@ -49,6 +43,19 @@ class database(fs_template.FsBased):
53 self._db_init_connection(config)
54 self._db_init_structures()
55
56 + def _import_sqlite(self):
57 + # sqlite3 is optional with >=python-2.5
58 + try:
59 + import sqlite3 as db_module
60 + except ImportError:
61 + try:
62 + from pysqlite2 import dbapi2 as db_module
63 + except ImportError as e:
64 + raise cache_errors.InitializationError(self.__class__, e)
65 +
66 + self._db_module = db_module
67 + self._db_error = db_module.Error
68 +
69 def _db_escape_string(self, s):
70 """meta escaping, returns quoted string for use in sql statements"""
71 if not isinstance(s, basestring):