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