mmgen-wallet/test/start-coin-daemons.py

78 lines
2.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import sys
from include.tests_header import repo_root
from mmgen.common import *
from mmgen.daemon import *
network_ids = CoinDaemon.get_network_ids()
2021-07-29 14:20:44 +00:00
action = g.prog_name.split('-')[0]
opts_data = {
'sets': [('debug',True,'verbose',True)],
'text': {
'desc': '{} coin daemons for the MMGen test suite'.format(action.capitalize()),
'usage':'[opts] <network IDs>',
'options': """
-h, --help Print this help message
--, --longhelp Print help message for long options (common options)
2021-05-09 11:56:47 +00:00
-D, --debug Produce debugging output (implies --verbose)
2021-05-09 11:56:48 +00:00
-d, --datadir= Override the default datadir
2021-05-09 11:56:47 +00:00
-n, --no-daemonize Don't fork daemon to background
2021-05-09 11:56:48 +00:00
-p, --port-shift= Shift the RPC port by this number
-s, --get-state Get the state of the daemon(s) and exit
-t, --testing Testing mode. Print commands but don't execute them
-q, --quiet Produce quieter output
-v, --verbose Produce more verbose output
-W, --no-wait Don't wait for daemons to change state before exiting
""",
'notes': """
Valid network IDs: {nid}, all, or no_xmr
"""
},
'code': {
'options': lambda s: s.format(a=action.capitalize(),pn=g.prog_name),
2021-07-29 14:20:44 +00:00
'notes': lambda s: s.format(nid=', '.join(network_ids))
}
}
cmd_args = opts.init(opts_data)
def run(network_id=None,proto=None,daemon_id=None):
2021-05-09 11:56:47 +00:00
d = CoinDaemon(
network_id = network_id,
proto = proto,
2021-05-09 11:56:47 +00:00
test_suite = True,
2021-05-09 11:56:48 +00:00
opts = ['no_daemonize'] if opt.no_daemonize else None,
port_shift = int(opt.port_shift or 0),
datadir = opt.datadir,
daemon_id = daemon_id )
2021-07-29 14:20:44 +00:00
d.debug = d.debug or opt.debug
d.wait = not opt.no_wait
if opt.get_state:
2021-08-01 20:54:51 +00:00
print(d.state_msg())
elif opt.testing:
print(' '.join(getattr(d,action+'_cmd')))
else:
d.cmd(action,quiet=opt.quiet)
if 'all' in cmd_args or 'no_xmr' in cmd_args:
if len(cmd_args) != 1:
die(1,"'all' or 'no_xmr' must be the sole argument")
from mmgen.protocol import init_proto
for coin,data in CoinDaemon.coins.items():
if coin == 'XMR' and cmd_args[0] == 'no_xmr':
continue
for daemon_id in data.daemon_ids:
for network in globals()[daemon_id+'_daemon'].networks:
run(proto=init_proto(coin=coin,network=network),daemon_id=daemon_id)
else:
ids = cmd_args
if not ids:
opts.usage()
for i in ids:
if i not in network_ids:
die(1,f'{i!r}: invalid network ID')
for network_id in ids:
run(network_id=network_id.lower())