input_func.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. # this script is used both for interactive and automated testing
  3. import sys,os
  4. os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(os.path.dirname(sys.argv[0])))))
  5. sys.path[0] = os.curdir
  6. from mmgen.cfg import Config
  7. from mmgen.util import msg
  8. opts_data = {
  9. 'text': {
  10. 'desc': '',
  11. 'usage':'',
  12. 'options':'-e, --echo-passphrase foo',
  13. }
  14. }
  15. cfg = Config(opts_data=opts_data)
  16. cmd_args = cfg._args
  17. cmd = cmd_args[0]
  18. if cmd == 'passphrase':
  19. from mmgen.ui import get_words_from_user
  20. pw = get_words_from_user(
  21. cfg,
  22. ('Enter passphrase: ','Enter passphrase (echoed): ')[bool(cfg.echo_passphrase)] )
  23. msg('Entered: {}'.format(' '.join(pw)))
  24. elif cmd in ('get_char','line_input'):
  25. from mmgen.term import get_char
  26. from mmgen.ui import line_input
  27. from ast import literal_eval
  28. func_args = literal_eval(cmd_args[1])
  29. msg(f'\n term: {get_char.__self__.__name__}')
  30. msg(f' cfg.hold_protect_disable: {cfg.hold_protect_disable}')
  31. if cmd == 'line_input':
  32. func_args.update({'cfg':cfg})
  33. msg(' Calling {name}( {args} )'.format(
  34. name = cmd,
  35. args = ', '.join(f'{k}={v!r}' for k,v in func_args.items())
  36. ))
  37. ret = locals()[cmd](**func_args)
  38. msg(f' ==> {ret!r}')