aboutsummaryrefslogtreecommitdiff
path: root/steuermann/config.py
blob: 7f8d04cddacc87044fcbdb54f2348e6867267730 (plain) (blame)
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
33
34
35
36
from __future__ import print_function
import os
import sys

_sys = sys.path
config_dir = os.path.join(os.path.expanduser('~'), '.steuermann', 'default')
user_config = os.path.join(config_dir, 'config.py')

if not os.path.exists(user_config):
    os.mkdir(config_dir)

try:
    sys.path.insert(1, os.path.dirname(user_config))
    import config
except ImportError:
    # We don't care if this config does exist, we have further options to test
    if 'STEUERMANN_CONFIG' in os.environ:
        user_config = os.path.abspath(os.environ['STEUERMANN_CONFIG'])
        sys.path = _sys
        sys.path.insert(1, os.path.dirname(user_config))
        try:
            import config
        except ImportError:
            print('FATAL: Missing config (i.e. {0})'.format(user_config))
            exit(1)


db_creds = config.db_creds


def open_db():
    import sqlite3
    return sqlite3.connect(db_creds)

logdir = config.logdir
host_logs = config.host_logs