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