start-coin-daemons.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 CoinDaemon
  6. action = g.prog_name.split('-')[0]
  7. opts_data = {
  8. 'sets': [('debug',True,'verbose',True)],
  9. 'text': {
  10. 'desc': '{} coin daemons for the MMGen test suite'.format(action.capitalize()),
  11. 'usage':'[opts] <network IDs>',
  12. 'options': """
  13. -h, --help Print this help message
  14. --, --longhelp Print help message for long options (common options)
  15. -D, --debug Produce debugging output (implies --verbose)
  16. -n, --no-daemonize Don't fork daemon to background
  17. -s, --get-state Get the state of the daemon(s) and exit
  18. -t, --testing Testing mode. Print commands but don't execute them
  19. -v, --verbose Produce more verbose output
  20. -W, --no-wait Don't wait for daemons to change state before exiting
  21. """,
  22. 'notes': """
  23. Valid network IDs: {nid}, all, or no_xmr
  24. """
  25. },
  26. 'code': {
  27. 'options': lambda s: s.format(a=action.capitalize(),pn=g.prog_name),
  28. 'notes': lambda s: s.format(nid=', '.join(CoinDaemon.network_ids))
  29. }
  30. }
  31. cmd_args = opts.init(opts_data)
  32. if 'all' in cmd_args or 'no_xmr' in cmd_args:
  33. if len(cmd_args) != 1:
  34. die(1,"'all' or 'no_xmr' must be the sole argument")
  35. else:
  36. ids = list(CoinDaemon.network_ids)
  37. if cmd_args[0] == 'no_xmr':
  38. ids.remove('xmr')
  39. else:
  40. ids = cmd_args
  41. if not ids:
  42. opts.usage()
  43. for i in ids:
  44. if i not in CoinDaemon.network_ids:
  45. die(1,f'{i!r}: invalid network ID')
  46. if 'eth' in ids and 'etc' in ids:
  47. msg('Cannot run ETH and ETC simultaneously, so skipping ETC')
  48. ids.remove('etc')
  49. for network_id in ids:
  50. network_id = network_id.lower()
  51. d = CoinDaemon(
  52. network_id,
  53. test_suite = True,
  54. opts = ['no_daemonize'] if opt.no_daemonize else None )
  55. d.debug = opt.debug
  56. d.wait = not opt.no_wait
  57. if opt.get_state:
  58. print('{} {} (port {}) is {}'.format(d.net_desc,d.desc,d.rpc_port,d.state))
  59. elif opt.testing:
  60. print(' '.join(getattr(d,action+'_cmd')))
  61. else:
  62. d.cmd(action)