forked from OpenBazaar/OpenBazaar-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.py
216 lines (183 loc) · 6.48 KB
/
constants.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
__author__ = 'foxcarlos-TeamCreed'
from os import getcwd
from os.path import expanduser, join, isfile
import ConfigParser
PROTOCOL_VERSION = 7
dataFolderPath = expanduser('~')
currentPath = getcwd()
myFileConfig = 'ob.cfg'
finalFileConfig = join(currentPath, myFileConfig)
fc = ConfigParser.ConfigParser(allow_no_value=True)
# if file config not found
if not isfile(finalFileConfig):
message = 'The file Config "{0}" not found'.format(finalFileConfig)
print message
else:
fc.read(finalFileConfig)
# name of section in Config File ob.cfg
mySection = 'CONSTANTS'
# if exist the sections in file config
try:
# Extract Config DATA_FOLDER
data_f2 = ''
nameOptionDF = 'DATA_FOLDER'
# if exist option in file config
try:
optionDataFolder = fc.get(mySection, nameOptionDF)
# if have a value
if optionDataFolder:
data_f2 = optionDataFolder
except ConfigParser.Error, error:
data_f2 = dataFolderPath + "/OpenBazaar/"
# Extract Config SEED_NODE
seed_n = ''
seed_n_p = ''
nameOptionSN = 'SEED_NODE'
try:
optionSeedNode = fc.get(mySection, nameOptionSN)
# if have value
if optionSeedNode:
if ':' in fc.get(mySection, nameOptionSN):
seed_n = fc.get(mySection, nameOptionSN).split(':')[0]
try:
seed_n_p = int(fc.get(mySection, nameOptionSN).split(':')[1])
except ValueError, error:
print error
except ConfigParser.Error, error:
print error
# Extract Config SEED_NODE_TESTNET
seed_n_t = ''
seed_n_t_p = ''
nameOptionSNT = 'SEED_NODE_TESTNET'
try:
optionSeeNodeTest = fc.get(mySection, nameOptionSNT)
# if have value
if optionSeeNodeTest:
if ':' in fc.get(mySection, nameOptionSNT):
seed_n_t = fc.get(mySection, nameOptionSNT).split(':')[0]
try:
seed_n_t_p = int(fc.get(mySection, nameOptionSNT).split(':')[1])
except ValueError, error:
print error
except ConfigParser.Error, error:
print error
# Extract Config KSIZE
ks = ''
nameOptionKS = 'KSIZE'
try:
optionKSize = fc.get(mySection, nameOptionKS)
# if have value
try:
ks = '' if not optionKSize else int(optionKSize)
except ValueError, error:
print error
except ConfigParser.Error, error:
print error
# extract Config APLHA
alp = ''
nameOptionAlpha = 'ALPHA'
try:
optionAlpha = fc.get(mySection, nameOptionAlpha)
# if have value
try:
alp = '' if not optionAlpha else int(optionAlpha)
except ValueError, error:
print error
except ConfigParser.Error, error:
print error
# extract Config TRANSACTION_FEE
trans_f = ''
nameOptionTrans_f = 'TRANSACTION_FEE'
try:
optionTrans_f = fc.get(mySection, nameOptionTrans_f)
# if have value
try:
trans_f = '' if not optionTrans_f else int(optionTrans_f)
except ValueError, error:
print error
except ConfigParser.Error, error:
print error
# Extract Config LIBBITCOIN_SERVER
libbitcoin_s = ''
nameOptionLBS = 'LIBBITCOIN_SERVER'
try:
optionLBS = fc.get(mySection, nameOptionLBS)
# if have value
if optionLBS:
libbitcoin_s = optionLBS
except ConfigParser.Error, error:
print error
# Extract Config LIBBITCOIN_SERVER_TESTNET
libbitcoin_s_t = ''
nameOptionLBS_T = 'LIBBITCOIN_SERVER_TESTNET'
try:
optionLBS_T = fc.get(mySection, nameOptionLBS_T)
# if have value
if optionLBS_T:
libbitcoin_s_t = optionLBS_T
except ConfigParser.Error, error:
print error
# extract Config SSL_CERT
ssl_crt = ''
nameOptionSsl_crt = 'SSL_CERT'
try:
optionssl_crt = fc.get(mySection, nameOptionSsl_crt)
# if have value
try:
ssl_crt = '' if not optionssl_crt else optionssl_crt
except ValueError, error:
print error
except ConfigParser.Error, error:
pass
# extract Config SSL_KEY
ssl_key = ''
nameOptionSsl_key = 'SSL_KEY'
try:
optionssl_key = fc.get(mySection, nameOptionSsl_key)
# if have value
try:
ssl_key = '' if not optionssl_key else optionssl_key
except ValueError, error:
print error
except ConfigParser.Error, error:
pass
# Extract Config SEEDS
mySection_2 = 'SEEDS'
seed = ''
lSeed = []
goodSeeds = []
logError = 'Wrong config file "{0}", this value is ignored'
if fc.has_section(mySection_2):
try:
listSeed = [seeds[1] for seeds in fc.items(mySection_2)]
lSeed = [tuple(s.split(",")) for s in listSeed]
except ConfigParser.Error, error:
print error
for s in lSeed:
errorInSeed = True
if len(s) == 2:
seed, key = s
if ':' in seed:
url, port = seed.split(':')
if url and port:
if key:
goodSeeds.append(s)
errorInSeed = False
if errorInSeed:
print logError.format(s)
else:
print 'No SECTIONS "{0}" in fileConfig ob.cfg'.format(mySection_2)
# Constant Assignment
DATA_FOLDER = data_f2
SEED_NODE = (seed_n, seed_n_p)
SEED_NODE_TESTNET = (seed_n_t, seed_n_t_p)
KSIZE = ks
ALPHA = alp
TRANSACTION_FEE = trans_f
LIBBITCOIN_SERVER = libbitcoin_s
LIBBITCOIN_SERVER_TESTNET = libbitcoin_s_t
SSL_CERT = ssl_crt
SSL_KEY = ssl_key
SEED = goodSeeds
except ConfigParser.Error, error:
print error