main_tool.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2016 Philemon <mmgen-py@yandex.com>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. mmgen-tool: Perform various MMGen- and Bitcoin-related operations.
  20. Part of the MMGen suite
  21. """
  22. from mmgen.common import *
  23. import mmgen.tool as tool
  24. opts_data = {
  25. 'desc': 'Perform various {pnm}- and Bitcoin-related operations'.format(pnm=g.proj_name),
  26. 'usage': '[opts] <command> <command args>',
  27. 'options': """
  28. -d, --outdir= d Specify an alternate directory 'd' for output
  29. -h, --help Print this help message
  30. --, --longhelp Print help message for long options (common options)
  31. -P, --passwd-file= f Get passphrase from file 'f'.
  32. -q, --quiet Produce quieter output
  33. -r, --usr-randchars=n Get 'n' characters of additional randomness from
  34. user (min={g.min_urandchars}, max={g.max_urandchars})
  35. -v, --verbose Produce more verbose output
  36. """.format(g=g),
  37. 'notes': """
  38. COMMANDS:{}
  39. Type '{} help <command> for help on a particular command
  40. """.format(tool.cmd_help,g.prog_name)
  41. }
  42. cmd_args = opts.init(opts_data,
  43. add_opts=[
  44. 'hidden_incog_input_params',
  45. 'in_fmt'
  46. ])
  47. if len(cmd_args) < 1:
  48. opts.usage()
  49. sys.exit(1)
  50. command = cmd_args.pop(0)
  51. if command not in tool.cmd_data:
  52. die(1,"'%s': no such command" % command)
  53. if cmd_args and cmd_args[0] == '--help':
  54. tool.tool_usage(g.prog_name, command)
  55. sys.exit()
  56. args,kwargs = tool.process_args(g.prog_name, command, cmd_args)
  57. ret = tool.__dict__[command](*args,**kwargs)
  58. sys.exit(0 if ret in (None,True) else 1) # some commands die, some return False on failure