getvar 926 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python3
  2. import common
  3. class Main(common.LkmcCliFunction):
  4. def __init__(self):
  5. super().__init__(
  6. defaults = {
  7. 'show_time': False,
  8. },
  9. description='''\
  10. Print the value of a self.env['py'] variable.
  11. https://cirosantilli.com/linux-kernel-module-cheat#getvar
  12. ''',
  13. )
  14. self.add_argument('--type', choices=['input', 'all'], default='all')
  15. self.add_argument('variable', nargs='?')
  16. def timed_main(self):
  17. variable = self.env['variable']
  18. if variable:
  19. print(self.env[variable])
  20. else:
  21. if self.env['type'] == 'input':
  22. to_print = self.input_args
  23. elif self.env['type'] == 'all':
  24. to_print = self.env
  25. for key in sorted(to_print):
  26. print('{}={}'.format(key, self.env[key]))
  27. if __name__ == '__main__':
  28. Main().cli()