getvar 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. This is useful to:
  12. * give dry commands on the README that don't change when we refactor directory structure
  13. * create simple bash scripts that call use self.env['py'] variables
  14. For example, to get the Buildroot output directory for an ARM build, use:
  15. ....
  16. ./%(prog)s -a arm buildroot_build_dir
  17. ....
  18. List all available variables:
  19. ....
  20. ./%(prog)s
  21. ....
  22. ''',
  23. )
  24. self.add_argument('--type', choices=['input', 'all'], default='all')
  25. self.add_argument('variable', nargs='?')
  26. def timed_main(self):
  27. variable = self.env['variable']
  28. if variable:
  29. print(self.env[variable])
  30. else:
  31. if self.env['type'] == 'input':
  32. to_print = self.input_args
  33. elif self.env['type'] == 'all':
  34. to_print = self.env
  35. for key in sorted(to_print):
  36. print('{}={}'.format(key, self.env[key]))
  37. if __name__ == '__main__':
  38. Main().cli()