diff options
author | Tom Rini <trini@konsulko.com> | 2016-10-12 20:48:43 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2016-10-12 20:48:43 -0400 |
commit | 79493609c5300be6cc555ab8bd38971360b381f6 (patch) | |
tree | dff7c18752cbc05974dc5459c0b90879edf8e342 /tools/patman/settings.py | |
parent | 5ebd27d860ec0c6e36f1b0f973653fe66a7360be (diff) | |
parent | bfeba0173aa45c24bbdba45149716c83258d25f6 (diff) | |
download | u-boot-79493609c5300be6cc555ab8bd38971360b381f6.tar.gz |
Merge git://git.denx.de/u-boot-dm
Diffstat (limited to 'tools/patman/settings.py')
-rw-r--r-- | tools/patman/settings.py | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/tools/patman/settings.py b/tools/patman/settings.py index ba2a68ff63..5f207f5ef1 100644 --- a/tools/patman/settings.py +++ b/tools/patman/settings.py @@ -3,7 +3,13 @@ # SPDX-License-Identifier: GPL-2.0+ # -import ConfigParser +from __future__ import print_function + +try: + import configparser as ConfigParser +except: + import ConfigParser + import os import re @@ -30,7 +36,10 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): - 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> @@ -48,25 +57,25 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): # 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')] """ @@ -88,7 +97,7 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): 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): @@ -156,7 +165,7 @@ def ReadGitAliases(fname): try: fd = open(fname, 'r') except IOError: - print "Warning: Cannot find alias file '%s'" % fname + print("Warning: Cannot find alias file '%s'" % fname) return re_line = re.compile('alias\s+(\S+)\s+(.*)') @@ -167,7 +176,7 @@ def ReadGitAliases(fname): m = re_line.match(line) if not m: - print "Warning: Alias file line '%s' not understood" % line + print("Warning: Alias file line '%s' not understood" % line) continue list = alias.get(m.group(1), []) @@ -200,10 +209,10 @@ def CreatePatmanConfigFile(config_fname): try: f = open(config_fname, 'w') except IOError: - print "Couldn't create patman config file\n" + print("Couldn't create patman config file\n") raise - print >>f, "[alias]\nme: %s <%s>" % (name, email) + print("[alias]\nme: %s <%s>" % (name, email), file=f) f.close(); def _UpdateDefaults(parser, config): @@ -233,7 +242,7 @@ def _UpdateDefaults(parser, config): val = config.getint('settings', name) parser.set_default(name, val) else: - print "WARNING: Unknown setting %s" % name + print("WARNING: Unknown setting %s" % name) def _ReadAliasFile(fname): """Read in the U-Boot git alias file if it exists. @@ -258,7 +267,7 @@ def _ReadAliasFile(fname): continue alias[words[1]] = [s.strip() for s in words[2].split(',')] if bad_line: - print bad_line + print(bad_line) def Setup(parser, project_name, config_fname=''): """Set up the settings module by reading config files. @@ -276,7 +285,7 @@ def Setup(parser, project_name, config_fname=''): config_fname = '%s/.patman' % os.getenv('HOME') if not os.path.exists(config_fname): - print "No config file found ~/.patman\nCreating one...\n" + print("No config file found ~/.patman\nCreating one...\n") CreatePatmanConfigFile(config_fname) config.read(config_fname) |