bsettings.py 909 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (c) 2012 The Chromium OS Authors.
  2. #
  3. # SPDX-License-Identifier: GPL-2.0+
  4. #
  5. import ConfigParser
  6. import os
  7. def Setup(fname=''):
  8. """Set up the buildman settings module by reading config files
  9. Args:
  10. config_fname: Config filename to read ('' for default)
  11. """
  12. global settings
  13. global config_fname
  14. settings = ConfigParser.SafeConfigParser()
  15. config_fname = fname
  16. if config_fname == '':
  17. config_fname = '%s/.buildman' % os.getenv('HOME')
  18. if config_fname:
  19. settings.read(config_fname)
  20. def GetItems(section):
  21. """Get the items from a section of the config.
  22. Args:
  23. section: name of section to retrieve
  24. Returns:
  25. List of (name, value) tuples for the section
  26. """
  27. try:
  28. return settings.items(section)
  29. except ConfigParser.NoSectionError as e:
  30. print e
  31. return []
  32. except:
  33. raise