comparison roundup/backends/__init__.py @ 1809:bd127cafe3a8

Simplify backend importing, by moving the imports into the backend modules.
author Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
date Sun, 14 Sep 2003 18:55:37 +0000
parents 7625bf9feec1
children f63aa57386b0
comparison
equal deleted inserted replaced
1808:3ac35c8e1782 1809:bd127cafe3a8
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.23 2003-04-24 06:55:24 richard Exp $ 18 # $Id: __init__.py,v 1.24 2003-09-14 18:55:37 jlgijsbers Exp $
19 19
20 ''' Container for the hyperdb storage backend implementations. 20 ''' Container for the hyperdb storage backend implementations.
21 21
22 The __all__ variable is constructed containing only the backends which are 22 The __all__ variable is constructed containing only the backends which are
23 available. 23 available.
24 ''' 24 '''
25 25
26 __all__ = [] 26 __all__ = []
27 27
28 try: 28 for backend in ['anydbm', ('mysql', 'MySQLdb'), 'bsddb', 'bsddb3', 'sqlite',
29 import sys, anydbm 29 'metakit']:
30 if not hasattr(sys, 'version_info') or sys.version_info < (2,1,2): 30 if len(backend) == 2:
31 import dumbdbm 31 backend, backend_module = backend
32 # dumbdbm only works in python 2.1.2+ 32 else:
33 assert anydbm._defaultmod != dumbdbm 33 backend_module = backend
34 del anydbm 34 try:
35 del dumbdbm 35 globals()[backend] = __import__('back_%s' % backend, globals())
36 except AssertionError: 36 __all__.append(backend)
37 print "WARNING: you should upgrade to python 2.1.3" 37 except ImportError, e:
38 except ImportError, message: 38 if not str(e).startswith('No module named %s' % backend_module):
39 if str(message) != 'No module named anydbm': raise 39 raise
40 else:
41 import back_anydbm
42 anydbm = back_anydbm
43 __all__.append('anydbm')
44
45 try:
46 import MySQLdb
47 except ImportError, message:
48 if str(message) != 'No module named MySQLdb': raise
49 else:
50 import back_mysql
51 mysql = back_mysql
52 __all__.append('mysql')
53
54 try:
55 import sqlite
56 except ImportError, message:
57 if str(message) != 'No module named sqlite': raise
58 else:
59 import back_sqlite
60 sqlite = back_sqlite
61 __all__.append('sqlite')
62
63 try:
64 import bsddb
65 except ImportError, message:
66 if not str(message).startswith('No module named'): raise
67 else:
68 import back_bsddb
69 bsddb = back_bsddb
70 __all__.append('bsddb')
71
72 try:
73 import bsddb3
74 except ImportError, message:
75 if str(message) != 'No module named bsddb3': raise
76 else:
77 import back_bsddb3
78 bsddb3 = back_bsddb3
79 __all__.append('bsddb3')
80
81 try:
82 import metakit
83 except ImportError, message:
84 if str(message) != 'No module named metakit': raise
85 else:
86 import back_metakit
87 metakit = back_metakit
88 __all__.append('metakit')
89 40
90 # vim: set filetype=python ts=4 sw=4 et si 41 # vim: set filetype=python ts=4 sw=4 et si

Roundup Issue Tracker: http://roundup-tracker.org/