blob: fdd875b0736f9ec918c443b50778c84aef33cdfa [file] [log] [blame]
Simon Glassfc3fe1c2013-04-03 11:07:16 +00001# Copyright (c) 2012 The Chromium OS Authors.
2#
Wolfgang Denk1a459662013-07-08 09:37:19 +02003# SPDX-License-Identifier: GPL-2.0+
Simon Glassfc3fe1c2013-04-03 11:07:16 +00004#
5
6import ConfigParser
7import os
Simon Glass8b985ee2014-09-05 19:00:15 -06008import StringIO
Simon Glassfc3fe1c2013-04-03 11:07:16 +00009
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()
Simon Glass8b985ee2014-09-05 19:00:15 -060021 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))
Simon Glassfc3fe1c2013-04-03 11:07:16 +000030
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
Simon Glassfc3fe1c2013-04-03 11:07:16 +000044 return []
45 except:
46 raise