main_tool.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. -P, --passwd-file= f Get passphrase from file 'f'.
  31. -q, --quiet Produce quieter output
  32. -r, --usr-randchars=n Get 'n' characters of additional randomness from
  33. user (min={g.min_urandchars}, max={g.max_urandchars})
  34. -v, --verbose Produce more verbose output
  35. """.format(g=g),
  36. 'notes': """
  37. COMMANDS:{}
  38. Type '{} usage <command> for usage information on a particular
  39. command
  40. """.format(tool.cmd_help,g.prog_name)
  41. }
  42. cmd_args = opts.init(opts_data,
  43. add_opts=[
  44. 'no_keyconv',
  45. 'hidden_incog_input_params',
  46. 'in_fmt'
  47. ])
  48. if len(cmd_args) < 1:
  49. opts.usage()
  50. sys.exit(1)
  51. command = cmd_args.pop(0)
  52. if command not in tool.cmd_data:
  53. die(1,"'%s': no such command" % command)
  54. if cmd_args and cmd_args[0] == '--help':
  55. tool.tool_usage(g.prog_name, command)
  56. sys.exit()
  57. args,kwargs = tool.process_args(g.prog_name, command, cmd_args)
  58. tool.__dict__[command](*args,**kwargs)