Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. |
| 2 | # |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 3 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 4 | # |
| 5 | |
| 6 | import ConfigParser |
| 7 | import os |
| 8 | |
| 9 | |
| 10 | def Setup(fname=''): |
| 11 | """Set up the buildman settings module by reading config files |
| 12 | |
| 13 | Args: |
| 14 | config_fname: Config filename to read ('' for default) |
| 15 | """ |
| 16 | global settings |
| 17 | global config_fname |
| 18 | |
| 19 | settings = ConfigParser.SafeConfigParser() |
| 20 | config_fname = fname |
| 21 | if config_fname == '': |
| 22 | config_fname = '%s/.buildman' % os.getenv('HOME') |
| 23 | if config_fname: |
| 24 | settings.read(config_fname) |
| 25 | |
| 26 | def GetItems(section): |
| 27 | """Get the items from a section of the config. |
| 28 | |
| 29 | Args: |
| 30 | section: name of section to retrieve |
| 31 | |
| 32 | Returns: |
| 33 | List of (name, value) tuples for the section |
| 34 | """ |
| 35 | try: |
| 36 | return settings.items(section) |
| 37 | except ConfigParser.NoSectionError as e: |
| 38 | print e |
Simon Glass | c05694f | 2013-04-03 11:07:16 +0000 | [diff] [blame] | 39 | return [] |
| 40 | except: |
| 41 | raise |