Mercurial > p > roundup > code
comparison roundup/backends/__init__.py @ 3718:0d561b24ceff
support sqlite3
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 04 Oct 2006 01:12:00 +0000 |
| parents | bcebddf1351f |
| children | 6a96ad643629 |
comparison
equal
deleted
inserted
replaced
| 3717:5770f1802cd0 | 3718:0d561b24ceff |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 18 # $Id: __init__.py,v 1.36 2006-01-25 03:24:09 richard Exp $ | 18 # $Id: __init__.py,v 1.37 2006-10-04 01:12:00 richard Exp $ |
| 19 | 19 |
| 20 '''Container for the hyperdb storage backend implementations. | 20 '''Container for the hyperdb storage backend implementations. |
| 21 ''' | 21 ''' |
| 22 __docformat__ = 'restructuredtext' | 22 __docformat__ = 'restructuredtext' |
| 23 | 23 |
| 26 # These names are used to suppress import errors. | 26 # These names are used to suppress import errors. |
| 27 # If get_backend raises an ImportError with appropriate | 27 # If get_backend raises an ImportError with appropriate |
| 28 # module name, have_backend quietly returns False. | 28 # module name, have_backend quietly returns False. |
| 29 # Otherwise the error is reraised. | 29 # Otherwise the error is reraised. |
| 30 _modules = { | 30 _modules = { |
| 31 'mysql': 'MySQLdb', | 31 'mysql': ('MySQLdb',), |
| 32 'postgresql': 'psycopg', | 32 'postgresql': ('psycopg',), |
| 33 'tsearch2': 'psycopg', | 33 'tsearch2': ('psycopg',), |
| 34 'sqlite': ('pysqlite', 'pysqlite2'), | |
| 34 } | 35 } |
| 35 | 36 |
| 36 def get_backend(name): | 37 def get_backend(name): |
| 37 '''Get a specific backend by name.''' | 38 '''Get a specific backend by name.''' |
| 38 vars = globals() | 39 vars = globals() |
| 63 return 0 | 64 return 0 |
| 64 try: | 65 try: |
| 65 get_backend(name) | 66 get_backend(name) |
| 66 return 1 | 67 return 1 |
| 67 except ImportError, e: | 68 except ImportError, e: |
| 68 global _modules | 69 for name in _modules.get(name, (name,)): |
| 69 if not str(e).startswith('No module named %s' | 70 if str(e).startswith('No module named %s'%name): |
| 70 % _modules.get(name, name)): | 71 return 0 |
| 71 raise | 72 raise |
| 72 return 0 | 73 return 0 |
| 73 | 74 |
| 74 def list_backends(): | 75 def list_backends(): |
| 75 '''List all available backend names. | 76 '''List all available backend names. |
| 76 | 77 |
