Edgewall Software

Ticket #8625: sqlite-get_supported_schemes

File sqlite-get_supported_schemes, 2.0 KB (added by cboos, 3 years ago)

Better reporting of installation issues related to PySqlite.

Line 
1Better reporting of installation issues related to PySqlite.
2
3Use the same mechanism as for errors on VCS connectors (r7435).
4
5Related to #8562.
6
7diff --git a/trac/db/api.py b/trac/db/api.py
8--- a/trac/db/api.py
9+++ b/trac/db/api.py
10@@ -37,6 +37,10 @@
11     def get_supported_schemes():
12         """Return the connection URL schemes supported by the connector, and
13         their relative priorities as an iterable of `(scheme, priority)` tuples.
14+       
15+        If `priority` is a negative number, this is indicative of an
16+        error  condition with the connector. An error message should be
17+        attached to the `error` attribute of the connector.
18         """
19 
20     def get_connection(path, log=None, **kwargs):
21@@ -121,6 +125,8 @@
22             for scheme_, priority in connector.get_supported_schemes():
23                 if scheme_ != scheme:
24                     continue
25+                if priority < 0:
26+                    raise TracError(connector.error)
27                 highest = candidates.get(scheme_, (None, 0))[1]
28                 if priority > highest:
29                     candidates[scheme] = (connector, priority)
30diff --git a/trac/db/sqlite_backend.py b/trac/db/sqlite_backend.py
31--- a/trac/db/sqlite_backend.py
32+++ b/trac/db/sqlite_backend.py
33@@ -22,6 +22,7 @@
34 from trac.db.api import IDatabaseConnector
35 from trac.db.util import ConnectionWrapper
36 from trac.util import get_pkginfo, getuser
37+from trac.util.translation import _
38 
39 _like_escape_re = re.compile(r'([/_%])')
40 
41@@ -112,9 +113,14 @@
42 
43     def __init__(self):
44         self._version = None
45+        self.error = None
46 
47     def get_supported_schemes(self):
48-        return [('sqlite', 1)]
49+        if have_pysqlite:
50+            yield ('sqlite', 1)
51+        else:
52+            self.error = _("Coudn't load Python bindings for SQLite")
53+            yield ('sqlite', -1)
54 
55     def get_connection(self, path, log=None, params={}):
56         if not self._version: