cfg_main.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python3
  2. import os
  3. from mmgen.cfg import Config
  4. from mmgen.util import msg
  5. cfg = Config(process_opts=True)
  6. cmd_args = cfg._args
  7. op, args = (cmd_args[0], cmd_args[1:]) if cmd_args else (None, None)
  8. from mmgen.cfgfile import mmgen_cfg_file
  9. cf_usr = mmgen_cfg_file(cfg, 'usr')
  10. cf_sys = mmgen_cfg_file(cfg, 'sys')
  11. cf_sample = mmgen_cfg_file(cfg, 'sample')
  12. msg(f'Usr cfg file: {os.path.relpath(cf_usr.fn)}')
  13. msg(f'Sys cfg file: {os.path.relpath(cf_sys.fn)}')
  14. msg(f'Sample cfg file: {os.path.relpath(cf_sample.fn)}')
  15. if op:
  16. if op == 'print_cfg':
  17. for name in args:
  18. msg('{} {}'.format(name+':', getattr(cfg, name)))
  19. elif op == 'parse_test':
  20. ps = cf_sample.get_lines()
  21. msg(f'parsed chunks: {len(ps)}')
  22. pu = cf_usr.get_lines()
  23. msg('usr cfg: {}'.format(' '.join(f'{i.name}={i.value}' for i in pu)))
  24. elif op == 'coin_specific_vars':
  25. for varname in args:
  26. msg('{}.{}: {}'.format(
  27. type(cfg._proto).__name__,
  28. varname,
  29. getattr(cfg._proto, varname)
  30. ))
  31. elif op == 'autoset_opts':
  32. assert cfg.rpc_backend == 'aiohttp', "cfg.rpc_backend != 'aiohttp'"
  33. elif op == 'autoset_opts_cmdline':
  34. assert cfg.rpc_backend == 'curl', "cfg.rpc_backend != 'curl'"
  35. elif op == 'mnemonic_entry_modes':
  36. from mmgen.mn_entry import mn_entry
  37. msg('mnemonic_entry_modes: {}\nmmgen: {}\nbip39: {}'.format(
  38. cfg.mnemonic_entry_modes,
  39. mn_entry(cfg, 'mmgen').usr_dfl_entry_mode,
  40. mn_entry(cfg, 'bip39').usr_dfl_entry_mode))