bsettings.py 1.0 KB

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