main.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2020 The MMGen Project <mmgen@tuta.io>
  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. main.py - Script launcher for the MMGen suite
  20. """
  21. def launch(mod):
  22. if mod in ('walletgen','walletchk','walletconv','passchg','subwalletgen','seedsplit'):
  23. mod = 'wallet'
  24. if mod == 'keygen': mod = 'addrgen'
  25. import sys,os
  26. from .globalvars import g
  27. if g.platform == 'linux' and sys.stdin.isatty():
  28. import termios,atexit
  29. fd = sys.stdin.fileno()
  30. old = termios.tcgetattr(fd)
  31. atexit.register(lambda: termios.tcsetattr(fd,termios.TCSADRAIN,old))
  32. try:
  33. __import__('mmgen.main_' + mod)
  34. except KeyboardInterrupt:
  35. sys.stderr.write('\nUser interrupt\n')
  36. sys.exit(1) # must exit normally so exit handlers will be called
  37. except EOFError:
  38. sys.stderr.write('\nEnd of file\n')
  39. except Exception as e:
  40. if os.getenv('MMGEN_TRACEBACK'):
  41. raise
  42. else:
  43. try: m = '{}'.format(e.args[0])
  44. except: m = repr(e.args[0])
  45. from .util import die,ydie,rdie
  46. d = [ (ydie,2,'\nMMGen Unhandled Exception ({n}): {m}'),
  47. (die, 1,'{m}'),
  48. (ydie,2,'{m}'),
  49. (ydie,3,'\nMMGen Error ({n}): {m}'),
  50. (rdie,4,'\nMMGen Fatal Error ({n}): {m}')
  51. ][e.mmcode if hasattr(e,'mmcode') else 0]
  52. d[0](d[1],d[2].format(n=type(e).__name__,m=m))