forked from chaincoin/sentinel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
98 lines (72 loc) · 2.51 KB
/
config.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
Set up defaults and read sentinel.conf
"""
import sys
import os
from chaincoin_config import ChaincoinConfig
default_sentinel_config = os.path.normpath(
os.path.join(os.path.dirname(__file__), '../sentinel.conf')
)
sentinel_config_file = os.environ.get('SENTINEL_CONFIG', default_sentinel_config)
sentinel_cfg = ChaincoinConfig.tokenize()
sentinel_version = "1.2.0"
min_chaincoind_proto_version_with_sentinel_ping = 70015
def get_network():
return sentinel_cfg.get('network', 'mainnet')
def get_rpchost():
return sentinel_cfg.get('rpchost', '127.0.0.1')
def get_rpcport():
# standard Chaincoin defaults...
default_port = 11995 if (get_network == 'mainnet') else 21995
if not ('rpcport' in sentinel_cfg):
return default_port
else:
return sentinel_cfg.get('rpcport')
def get_rpcuser():
return sentinel_cfg.get('rpcuser', 'user')
def get_rpcpassword():
return sentinel_cfg.get('rpcpassword', 'pass')
def sqlite_test_db_name(sqlite_file_path):
(root, ext) = os.path.splitext(sqlite_file_path)
test_sqlite_file_path = root + '_test' + ext
return test_sqlite_file_path
def get_db_conn():
import peewee
env = os.environ.get('SENTINEL_ENV', 'production')
# default values should be used unless you need a different config for development
db_host = sentinel_cfg.get('db_host', '127.0.0.1')
db_port = sentinel_cfg.get('db_port', None)
db_name = sentinel_cfg.get('db_name', 'sentinel')
db_user = sentinel_cfg.get('db_user', 'sentinel')
db_password = sentinel_cfg.get('db_password', 'sentinel')
db_charset = sentinel_cfg.get('db_charset', 'utf8mb4')
db_driver = sentinel_cfg.get('db_driver', 'sqlite')
if (env == 'test'):
if db_driver == 'sqlite':
db_name = sqlite_test_db_name(db_name)
else:
db_name = "%s_test" % db_name
peewee_drivers = {
'mysql': peewee.MySQLDatabase,
'postgres': peewee.PostgresqlDatabase,
'sqlite': peewee.SqliteDatabase,
}
driver = peewee_drivers.get(db_driver)
dbpfn = 'passwd' if db_driver == 'mysql' else 'password'
db_conn = {
'host': db_host,
'user': db_user,
dbpfn: db_password,
}
if db_port:
db_conn['port'] = int(db_port)
if driver == peewee.SqliteDatabase:
db_conn = {}
db = driver(db_name, **db_conn)
return db
network = get_network()
rpc_host = get_rpchost()
rpc_port = get_rpcport()
rpc_user = get_rpcuser()
rpc_password = get_rpcpassword()
db = get_db_conn()