forked from chaincoin/sentinel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.py
102 lines (70 loc) · 2.4 KB
/
init.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
99
100
101
102
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'lib'))
def is_valid_python_version():
version_valid = False
ver = sys.version_info
if (2 == ver.major) and (7 <= ver.minor):
version_valid = True
if (3 == ver.major) and (4 <= ver.minor):
version_valid = True
return version_valid
def python_short_ver_str():
ver = sys.version_info
return "%s.%s" % (ver.major, ver.minor)
def are_deps_installed():
installed = False
try:
import peewee
import bitcoinrpc.authproxy
import simplejson
installed = True
except ImportError as e:
print("[error]: Missing dependencies")
return installed
def is_database_correctly_configured():
import peewee
import config
configured = False
cannot_connect_message = "Cannot connect to database. Please ensure database service is running and user access is properly configured in 'sentinel.conf'."
try:
db = config.db
db.connect()
configured = True
except (peewee.ImproperlyConfigured, peewee.OperationalError, ImportError) as e:
print("[error]: %s" % e)
print(cannot_connect_message)
sys.exit(1)
return configured
def has_sentinel_conf():
import config
import io
valid_sentinel_conf = False
# ensure sentinel.conf exists & readable
#
# if not, print a message stating that Chaincoin Core must be installed and
# configured, including JSONRPC access in sentinel.conf
try:
f = io.open("sentinel.conf")
valid_sentinel_conf = True
except IOError as e:
print(e)
return valid_sentinel_conf
# === begin main
def main():
install_instructions = "\tpip install -r requirements.txt"
if not is_valid_python_version():
print("Python %s is not supported" % python_short_ver_str())
sys.exit(1)
if not are_deps_installed():
print("Please ensure all dependencies are installed:")
print(install_instructions)
sys.exit(1)
if not is_database_correctly_configured():
print("Please ensure correct database configuration.")
sys.exit(1)
if not has_sentinel_conf():
print("Chaincoin Core must be installed and configured, and sentinel.conf need specify the RPC credentials")
sys.exit(1)
main()