+# SPDX-License-Identifier: GPL-2.0+
# Copyright (c) 2011 The Chromium OS Authors.
#
-# SPDX-License-Identifier: GPL-2.0+
-#
from __future__ import print_function
- Merge general default settings/aliases with project-specific ones.
# Sample config used for tests below...
- >>> import StringIO
+ >>> try:
+ ... from StringIO import StringIO
+ ... except ImportError:
+ ... from io import StringIO
>>> sample_config = '''
... [alias]
... me: Peter P. <likesspiders@example.com>
# Check to make sure that bogus project gets general alias.
>>> config = _ProjectConfigParser("zzz")
- >>> config.readfp(StringIO.StringIO(sample_config))
+ >>> config.readfp(StringIO(sample_config))
>>> config.get("alias", "enemies")
'Evil <evil@example.com>'
# Check to make sure that alias gets overridden by project.
>>> config = _ProjectConfigParser("sm")
- >>> config.readfp(StringIO.StringIO(sample_config))
+ >>> config.readfp(StringIO(sample_config))
>>> config.get("alias", "enemies")
'Green G. <ugly@example.com>'
# Check to make sure that settings get merged with project.
>>> config = _ProjectConfigParser("linux")
- >>> config.readfp(StringIO.StringIO(sample_config))
+ >>> config.readfp(StringIO(sample_config))
>>> sorted(config.items("settings"))
[('am_hero', 'True'), ('process_tags', 'False')]
# Check to make sure that settings works with unknown project.
>>> config = _ProjectConfigParser("unknown")
- >>> config.readfp(StringIO.StringIO(sample_config))
+ >>> config.readfp(StringIO(sample_config))
>>> sorted(config.items("settings"))
[('am_hero', 'True')]
"""
if not self.has_section(project_settings):
self.add_section(project_settings)
project_defaults = _default_settings.get(project_name, {})
- for setting_name, setting_value in project_defaults.iteritems():
+ for setting_name, setting_value in project_defaults.items():
self.set(project_settings, setting_name, setting_value)
def get(self, section, option, *args, **kwargs):
print("Couldn't create patman config file\n")
raise
- print("[alias]\nme: %s <%s>" % (name, email), file=f)
+ print('''[alias]
+me: %s <%s>
+
+[bounces]
+nxp = Zhikang Zhang <zhikang.zhang@nxp.com>
+''' % (name, email), file=f)
f.close();
def _UpdateDefaults(parser, config):
if bad_line:
print(bad_line)
+def _ReadBouncesFile(fname):
+ """Read in the bounces file if it exists
+
+ Args:
+ fname: Filename to read.
+ """
+ if os.path.exists(fname):
+ with open(fname) as fd:
+ for line in fd:
+ if line.startswith('#'):
+ continue
+ bounces.add(line.strip())
+
+def GetItems(config, section):
+ """Get the items from a section of the config.
+
+ Args:
+ config: _ProjectConfigParser object containing settings
+ section: name of section to retrieve
+
+ Returns:
+ List of (name, value) tuples for the section
+ """
+ try:
+ return config.items(section)
+ except ConfigParser.NoSectionError as e:
+ return []
+ except:
+ raise
+
def Setup(parser, project_name, config_fname=''):
"""Set up the settings module by reading config files.
config.read(config_fname)
- for name, value in config.items('alias'):
+ for name, value in GetItems(config, 'alias'):
alias[name] = value.split(',')
+ _ReadBouncesFile('doc/bounces')
+ for name, value in GetItems(config, 'bounces'):
+ bounces.add(value)
+
_UpdateDefaults(parser, config)
# These are the aliases we understand, indexed by alias. Each member is a list.
alias = {}
+bounces = set()
if __name__ == "__main__":
import doctest