getvar 888 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. import types
  3. import common
  4. parser = common.get_argparse(argparse_args={
  5. 'description': '''Print the value of a common.py variable.
  6. This is useful to:
  7. * give dry commands on the README that don't change when we refactor directory structure
  8. * create simple bash scripts that call use common.py variables
  9. For example, to get the Buildroot output directory for an ARM build, use:
  10. ....
  11. ./%(prog)s -a arm buildroot_build_dir
  12. ....
  13. List all available variables:
  14. ....
  15. ./%(prog)s
  16. ....
  17. ....
  18. '''
  19. })
  20. parser.add_argument('variable', nargs='?')
  21. args = common.setup(parser)
  22. if args.variable:
  23. print(getattr(common, args.variable))
  24. else:
  25. for attr in dir(common):
  26. if not attr.startswith('__'):
  27. val = getattr(common, attr)
  28. if not callable(val) and not type(val) is types.ModuleType:
  29. print('{} {}'.format(attr, val))