xref: /openbmc/u-boot/tools/buildman/bsettings.py (revision 686e1448)
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
22import ConfigParser
23import os
24
25
26def Setup(fname=''):
27    """Set up the buildman settings module by reading config files
28
29    Args:
30        config_fname:   Config filename to read ('' for default)
31    """
32    global settings
33    global config_fname
34
35    settings = ConfigParser.SafeConfigParser()
36    config_fname = fname
37    if config_fname == '':
38        config_fname = '%s/.buildman' % os.getenv('HOME')
39    if config_fname:
40        settings.read(config_fname)
41
42def GetItems(section):
43    """Get the items from a section of the config.
44
45    Args:
46        section: name of section to retrieve
47
48    Returns:
49        List of (name, value) tuples for the section
50    """
51    try:
52        return settings.items(section)
53    except ConfigParser.NoSectionError as e:
54        print e
55        print ("Warning: No tool chains - please add a [toolchain] section "
56                "to your buildman config file %s. See README for details" %
57                config_fname)
58        return []
59    except:
60        raise
61