oneshot_warning.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python3
  2. from mmgen.cfg import Config
  3. from mmgen.util import msg, oneshot_warning, oneshot_warning_group
  4. cfg = Config()
  5. class foo(oneshot_warning):
  6. color = 'purple'
  7. message = 'foo variant {} selected'
  8. class bar(oneshot_warning):
  9. color = 'yellow'
  10. message = 'bar is experimental software'
  11. class wg(oneshot_warning_group):
  12. class foo:
  13. color = 'yellow'
  14. message = 'foo is experimental software. Proceed at your own risk'
  15. class bar:
  16. color = 'red'
  17. message = 'The bar command is {} and can break your {}!!!'
  18. class baz:
  19. color = 'orange'
  20. message = 'baz variant {} selected'
  21. for i in (1, 2, 3):
  22. from mmgen.crypto import Crypto
  23. msg('\npw')
  24. for k in ('A', 'B'):
  25. ret = Crypto.pwfile_reuse_warning(k).warning_shown
  26. assert ret == (i != 1), 'warning_shown incorrect'
  27. msg('wg1')
  28. wg('foo')
  29. msg('wg2')
  30. wg('bar', fmt_args=['dangerous', 'computer'])
  31. msg('wg3')
  32. wg('baz', div='alpha', fmt_args=['alpha'])
  33. msg('wg4')
  34. wg('baz', div='beta', fmt_args=['beta'])
  35. msg('w1')
  36. foo(div='alpha', fmt_args=['alpha'])
  37. msg('w2')
  38. foo(div='beta', fmt_args=['beta'])
  39. msg('w3')
  40. bar()
  41. msg('bottom')