start-coin-daemons.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. from mmgen.regtest import MMGenRegtest
  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, --no-daemonize Don't fork daemon to background
  18. -r, --regtest-user=U {a} a regtest daemon for user 'U'
  19. -s, --get-state Get the state of the daemon(s) and exit
  20. -t, --testing Testing mode. Print commands but don't execute them
  21. -v, --verbose Produce more verbose output
  22. -W, --no-wait Don't wait for daemons to change state before exiting
  23. """,
  24. 'notes': """
  25. Valid network IDs: {nid}, all, or no_xmr
  26. Valid Regtest network IDs: {rid}, or all
  27. Valid Regtest users: {ru}
  28. """
  29. },
  30. 'code': {
  31. 'options': lambda s: s.format(a=action.capitalize(),pn=g.prog_name),
  32. 'notes': lambda s: s.format(
  33. nid=', '.join(CoinDaemon.network_ids),
  34. rid=', '.join(MMGenRegtest.coins),
  35. ru=', '.join(MMGenRegtest.users),
  36. )
  37. }
  38. }
  39. cmd_args = opts.init(opts_data)
  40. if 'all' in cmd_args or 'no_xmr' in cmd_args:
  41. if len(cmd_args) != 1:
  42. die(1,"'all' or 'no_xmr' must be the sole argument")
  43. if opt.regtest_user:
  44. ids = MMGenRegtest.coins
  45. else:
  46. ids = list(CoinDaemon.network_ids)
  47. if cmd_args[0] == 'no_xmr':
  48. ids.remove('xmr')
  49. else:
  50. ids = cmd_args
  51. if not ids:
  52. opts.usage()
  53. for i in ids:
  54. if i not in CoinDaemon.network_ids:
  55. die(1,'{!r}: invalid network ID'.format(i))
  56. if 'eth' in ids and 'etc' in ids:
  57. msg('Cannot run ETH and ETC simultaneously, so skipping ETC')
  58. ids.remove('etc')
  59. for network_id in ids:
  60. network_id = network_id.lower()
  61. if opt.regtest_user:
  62. d = MMGenRegtest(network_id).test_daemon(opt.regtest_user)
  63. else:
  64. if network_id.endswith('_rt'):
  65. continue
  66. d = CoinDaemon(network_id,test_suite=True,flags=['no_daemonize'] if opt.no_daemonize else None)
  67. d.debug = opt.debug
  68. d.wait = not opt.no_wait
  69. if opt.get_state:
  70. print('{} {} is {}'.format(d.net_desc,d.desc,d.state))
  71. elif opt.testing:
  72. print(' '.join(getattr(d,action+'_cmd')))
  73. else:
  74. d.cmd(action)