aboutsummaryrefslogtreecommitdiff
path: root/steuermann/config.py
blob: 247dc9d6efbca2f6a69adbcf287fad39da906677 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from __future__ import print_function
import os
import sys

_path = sys.path.copy()

#if not os.path.exists(config_dir):
#    os.makedirs(config_dir, mode=0o700)

try:
    # We don't care if this config does exist, we have further options to test
    config_dir = ''
    if 'STEUERMANN_CONFIG' in os.environ:
        config_dir = os.path.abspath(os.environ['STEUERMANN_CONFIG'])
    user_config = os.path.join(config_dir, 'config.py')
    hosts_config = os.path.join(config_dir, 'hosts.ini')

    sys.path.insert(1, config_dir)
    import config

except ImportError:
    config_dir = os.path.join(os.path.expanduser('~'), '.steuermann', 'default')
    user_config = os.path.join(config_dir, 'config.py')
    hosts_config = os.path.join(config_dir, 'hosts.ini')

    sys.path = _path
    sys.path.insert(1, config_dir)
    try:
        import config
    except ImportError as e:
        print(e)
        print('FATAL: Missing config (i.e. {0})'.format(user_config))
        exit(1)

print("Using: {0}".format(config_dir))

try:
    auth_users = config.auth_users
except NameError:
    auth_users = ()

db_creds = config.db_creds


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

logdir = config.logdir
host_logs = config.host_logs