start-coin-daemons.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. import sys
  3. from include.tests_header import repo_root
  4. from mmgen.common import *
  5. from mmgen.daemon import *
  6. network_ids = CoinDaemon.get_network_ids()
  7. action = g.prog_name.split('-')[0]
  8. opts_data = {
  9. 'sets': [('debug',True,'verbose',True)],
  10. 'text': {
  11. 'desc': '{} coin daemons for the MMGen test suite'.format(action.capitalize()),
  12. 'usage':'[opts] <network IDs>',
  13. 'options': """
  14. -h, --help Print this help message
  15. --, --longhelp Print help message for long options (common options)
  16. -D, --debug Produce debugging output (implies --verbose)
  17. -d, --datadir= Override the default datadir
  18. -n, --no-daemonize Don't fork daemon to background
  19. -p, --port-shift= Shift the RPC port by this number
  20. -s, --get-state Get the state of the daemon(s) and exit
  21. -t, --testing Testing mode. Print commands but don't execute them
  22. -v, --verbose Produce more verbose output
  23. -W, --no-wait Don't wait for daemons to change state before exiting
  24. """,
  25. 'notes': """
  26. Valid network IDs: {nid}, all, or no_xmr
  27. """
  28. },
  29. 'code': {
  30. 'options': lambda s: s.format(a=action.capitalize(),pn=g.prog_name),
  31. 'notes': lambda s: s.format(nid=', '.join(network_ids))
  32. }
  33. }
  34. cmd_args = opts.init(opts_data)
  35. def run(network_id=None,proto=None,daemon_id=None):
  36. d = CoinDaemon(
  37. network_id = network_id,
  38. proto = proto,
  39. test_suite = True,
  40. opts = ['no_daemonize'] if opt.no_daemonize else None,
  41. port_shift = int(opt.port_shift or 0),
  42. datadir = opt.datadir,
  43. daemon_id = daemon_id )
  44. d.debug = d.debug or opt.debug
  45. d.wait = not opt.no_wait
  46. if opt.get_state:
  47. print(d.state_msg())
  48. elif opt.testing:
  49. print(' '.join(getattr(d,action+'_cmd')))
  50. else:
  51. d.cmd(action)
  52. if 'all' in cmd_args or 'no_xmr' in cmd_args:
  53. if len(cmd_args) != 1:
  54. die(1,"'all' or 'no_xmr' must be the sole argument")
  55. from mmgen.protocol import init_proto
  56. for coin,data in CoinDaemon.coins.items():
  57. if coin == 'XMR' and cmd_args[0] == 'no_xmr':
  58. continue
  59. for daemon_id in data.daemon_ids:
  60. for network in globals()[daemon_id+'_daemon'].networks:
  61. run(proto=init_proto(coin=coin,network=network),daemon_id=daemon_id)
  62. else:
  63. ids = cmd_args
  64. if not ids:
  65. opts.usage()
  66. for i in ids:
  67. if i not in network_ids:
  68. die(1,f'{i!r}: invalid network ID')
  69. for network_id in ids:
  70. run(network_id=network_id.lower())