main_tool.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env python
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2017 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. {}
  40. Type '{} help <command> for help on a particular command
  41. """.format(tool.cmd_help,g.prog_name)
  42. }
  43. cmd_args = opts.init(opts_data,add_opts=['hidden_incog_input_params','in_fmt'])
  44. if len(cmd_args) < 1: opts.usage()
  45. Command = cmd_args.pop(0).capitalize()
  46. if Command == 'Help' and not cmd_args: tool.usage(None)
  47. if Command not in tool.cmd_data:
  48. die(1,"'%s': no such command" % Command.lower())
  49. args,kwargs = tool.process_args(Command,cmd_args)
  50. ret = tool.__dict__[Command](*args,**kwargs)
  51. sys.exit(0 if ret in (None,True) else 1) # some commands die, some return False on failure