From 7dbe30a03daaa3e724e98660a1303441cb713dcf Mon Sep 17 00:00:00 2001 From: jlgijsbers Date: Sun, 14 Sep 2003 18:55:37 +0000 Subject: [PATCH] Simplify backend importing, by moving the imports into the backend modules. git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1876 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/backends/__init__.py | 75 ++++++--------------------------- roundup/backends/back_anydbm.py | 14 +++++- 2 files changed, 25 insertions(+), 64 deletions(-) diff --git a/roundup/backends/__init__.py b/roundup/backends/__init__.py index 16c16f2..d225301 100644 --- a/roundup/backends/__init__.py +++ b/roundup/backends/__init__.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -# $Id: __init__.py,v 1.23 2003-04-24 06:55:24 richard Exp $ +# $Id: __init__.py,v 1.24 2003-09-14 18:55:37 jlgijsbers Exp $ ''' Container for the hyperdb storage backend implementations. @@ -25,66 +25,17 @@ available. __all__ = [] -try: - import sys, anydbm - if not hasattr(sys, 'version_info') or sys.version_info < (2,1,2): - import dumbdbm - # dumbdbm only works in python 2.1.2+ - assert anydbm._defaultmod != dumbdbm - del anydbm - del dumbdbm -except AssertionError: - print "WARNING: you should upgrade to python 2.1.3" -except ImportError, message: - if str(message) != 'No module named anydbm': raise -else: - import back_anydbm - anydbm = back_anydbm - __all__.append('anydbm') - -try: - import MySQLdb -except ImportError, message: - if str(message) != 'No module named MySQLdb': raise -else: - import back_mysql - mysql = back_mysql - __all__.append('mysql') - -try: - import sqlite -except ImportError, message: - if str(message) != 'No module named sqlite': raise -else: - import back_sqlite - sqlite = back_sqlite - __all__.append('sqlite') - -try: - import bsddb -except ImportError, message: - if not str(message).startswith('No module named'): raise -else: - import back_bsddb - bsddb = back_bsddb - __all__.append('bsddb') - -try: - import bsddb3 -except ImportError, message: - if str(message) != 'No module named bsddb3': raise -else: - import back_bsddb3 - bsddb3 = back_bsddb3 - __all__.append('bsddb3') - -try: - import metakit -except ImportError, message: - if str(message) != 'No module named metakit': raise -else: - import back_metakit - metakit = back_metakit - __all__.append('metakit') +for backend in ['anydbm', ('mysql', 'MySQLdb'), 'bsddb', 'bsddb3', 'sqlite', + 'metakit']: + if len(backend) == 2: + backend, backend_module = backend + else: + backend_module = backend + try: + globals()[backend] = __import__('back_%s' % backend, globals()) + __all__.append(backend) + except ImportError, e: + if not str(e).startswith('No module named %s' % backend_module): + raise # vim: set filetype=python ts=4 sw=4 et si diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index 33392a7..8d7ecd8 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -15,7 +15,7 @@ # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. # -#$Id: back_anydbm.py,v 1.127 2003-09-08 20:39:18 jlgijsbers Exp $ +#$Id: back_anydbm.py,v 1.128 2003-09-14 18:55:37 jlgijsbers Exp $ ''' This module defines a backend that saves the hyperdatabase in a database chosen by anydbm. It is guaranteed to always be available in python @@ -23,7 +23,17 @@ versions >2.1.1 (the dumbdbm fallback in 2.1.1 and earlier has several serious bugs, and is not available) ''' -import whichdb, anydbm, os, marshal, re, weakref, string, copy +try: + import anydbm, sys + # dumbdbm only works in python 2.1.2+ + if sys.version_info < (2,1,2): + import dumbdbm + assert anydbm._defaultmod != dumbdbm + del dumbdbm +except AssertionError: + print "WARNING: you should upgrade to python 2.1.3" + +import whichdb, os, marshal, re, weakref, string, copy from roundup import hyperdb, date, password, roundupdb, security from blobfiles import FileStorage from sessions import Sessions, OneTimeKeys -- 2.30.2