-
Notifications
You must be signed in to change notification settings - Fork 37
/
app.py
executable file
·92 lines (76 loc) · 3.21 KB
/
app.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
#!/usr/bin/env python3
import json
import os, sys, os.path
import argparse
from jinja2 import Environment, FileSystemLoader
from icecream import ic
def Merge(dict1, dict2):
res = {**dict1, **dict2}
return res
def write_file(filename, rendered_data):
#logging.info('Creating File: {}'.format(filename))
with open(filename, "w") as fname:
fname.write(rendered_data)
return
parser = argparse.ArgumentParser()
parser.add_argument('--coins', help='List of coins. Eg.: BTC, LTC, DASH', default=False)
args = parser.parse_args()
list_coins = args.coins
if list_coins:
COIN_LIST = []
list_coins = list_coins.split(',')
for coin in list_coins:
ticker = coin.strip().upper()
COIN_LIST.append(ticker)
WALLETCONFPATH='../wallet-confs/'
XBRIDGECONFPATH='../xbridge-confs/'
if not os.path.isdir(WALLETCONFPATH):
os.mkdir(WALLETCONFPATH)
print('checking walletconfpath: {}'.format(os.path.isdir(WALLETCONFPATH)))
if not os.path.isdir(XBRIDGECONFPATH):
os.mkdir(XBRIDGECONFPATH)
print('checking xb: {}'.format(os.path.isdir(XBRIDGECONFPATH)))
J2_ENV = Environment(loader=FileSystemLoader(''),
trim_blocks=True)
with open('../manifest-latest.json') as json_file:
data = json.load(json_file)
if not list_coins:
COIN_LIST = list(set([chain['ticker'] for chain in data]))
COIN_LIST.sort(key = lambda t:t, reverse = False)
for chain in data:
#print (chain['blockchain'])
if chain['ticker'] in COIN_LIST:
print('start: {}'.format(chain['ver_id']))
#print(chain)
# load base config for specific coin
base_config_fname = 'configs/{}.base.j2'.format(chain['ticker'].lower())
base_config_template = J2_ENV.get_template(base_config_fname)
base_config = json.loads(base_config_template.render())
#print(base_config['BTC'])
print(base_config)
merged_dict = (Merge(chain,base_config[chain['ticker']]))
#print(json.dumps(merged_dict, indent=2))
# get version data
coin_title, p, this_coin_version = chain['ver_id'].partition('--')
print(this_coin_version)
#print(json.dumps(merged_dict['versions'], indent=2))
try:
version_data = merged_dict['versions'][this_coin_version]
except Exception as e:
print('error, check manifest: {}'.format(chain['ticker']))
print(merged_dict['versions'])
raise Exception
# load xb j2
print(version_data)
custom_template_fname = 'templates/xbridge.conf.j2'
custom_template = J2_ENV.get_template(custom_template_fname)
updated_dict = Merge(version_data,merged_dict)
#print(updated_dict)
rendered_data = custom_template.render(updated_dict)
write_file(XBRIDGECONFPATH+chain['ver_id']+'.conf', rendered_data)
ic(rendered_data)
custom_template_wallet_conf = 'templates/wallet.conf.j2'
custom_template_wallet = J2_ENV.get_template(custom_template_wallet_conf)
wallet_rendered_data = custom_template_wallet.render(updated_dict)
write_file(WALLETCONFPATH+chain['ver_id']+'.conf', wallet_rendered_data) # writes wallet conf
ic(wallet_rendered_data)