bsettings.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (c) 2012 The Chromium OS Authors.
  2. #
  3. # See file CREDITS for list of people who contributed to this
  4. # project.
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License as
  8. # published by the Free Software Foundation; either version 2 of
  9. # the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. # MA 02111-1307 USA
  20. #
  21. import ConfigParser
  22. import os
  23. def Setup(fname=''):
  24. """Set up the buildman settings module by reading config files
  25. Args:
  26. config_fname: Config filename to read ('' for default)
  27. """
  28. global settings
  29. global config_fname
  30. settings = ConfigParser.SafeConfigParser()
  31. config_fname = fname
  32. if config_fname == '':
  33. config_fname = '%s/.buildman' % os.getenv('HOME')
  34. if config_fname:
  35. settings.read(config_fname)
  36. def GetItems(section):
  37. """Get the items from a section of the config.
  38. Args:
  39. section: name of section to retrieve
  40. Returns:
  41. List of (name, value) tuples for the section
  42. """
  43. try:
  44. return settings.items(section)
  45. except ConfigParser.NoSectionError as e:
  46. print e
  47. print ("Warning: No tool chains - please add a [toolchain] section "
  48. "to your buildman config file %s. See README for details" %
  49. config_fname)
  50. return []
  51. except:
  52. raise