__init__.py 1.33 KB
Newer Older
1
#
2
# Copyright (C) 2006-2015  Nexedi SA
3
#
4 5 6 7
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
8
#
9 10 11 12 13 14
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

17 18
LOG_QUERIES = False

19
from neo.lib.exception import DatabaseFailure
20
from .manager import DatabaseManager
21

22
DATABASE_MANAGER_DICT = {
23
    'Importer': 'importer.ImporterDatabaseManager',
24 25 26
    'MySQL': 'mysqldb.MySQLDatabaseManager',
    'SQLite': 'sqlite.SQLiteDatabaseManager',
}
27

28 29 30 31
def getAdapterKlass(name):
    try:
        module, name = DATABASE_MANAGER_DICT[name or 'MySQL'].split('.')
    except KeyError:
32
        raise DatabaseFailure('Cannot find a database adapter <%s>' % name)
33 34
    module = getattr(__import__(__name__, fromlist=[module], level=1), module)
    return getattr(module, name)
35

36 37
def buildDatabaseManager(name, args=(), kw={}):
    return getAdapterKlass(name)(*args, **kw)