summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Reporting/Storage/__init__.py
blob: 85356fcfe8aca1ee76d2476989b5a334e3a4d878 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Public storage routines
"""

import traceback

from Bcfg2.Reporting.Storage.base import StorageError, \
    StorageImportError

def load_storage(storage_name, setup):
    """
    Try to load the storage.  Raise StorageImportError on failure
    """
    try:
        mod_name = "%s.%s" % (__name__, storage_name)
        mod = getattr(__import__(mod_name).Reporting.Storage, storage_name)
    except ImportError:
        try:
            mod = __import__(storage_name)
        except:
            raise StorageImportError("Unavailable")
    try:
        cls = getattr(mod, storage_name)
        return cls(setup)
    except:
        raise StorageImportError("Storage unavailable: %s" %
            traceback.format_exc().splitlines()[-1])

def load_storage_from_config(setup):
    """Load the storage in the config... eventually"""
    return load_storage('DjangoORM', setup)