]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
patman: Add support for settings in .patman
authorDoug Anderson <dianders@chromium.org>
Mon, 3 Dec 2012 14:43:17 +0000 (14:43 +0000)
committerSimon Glass <sjg@chromium.org>
Thu, 31 Jan 2013 23:23:40 +0000 (15:23 -0800)
This patch adds support for a [settings] section in the .patman file.
In this section you can add settings that will affect the default
values for command-line options.

Support is added in a generic way such that any setting can be updated
by just referring to the "dest" of the option that is passed to the
option parser.  At the moment options that would make sense to put in
settings are "ignore_errors", "process_tags", and "verbose".  You
could override them like:

 [settings]
 ignore_errors: True
 process_tags: False
 verbose: True

The settings functionality is also used in a future change which adds
support for per-project settings.

Signed-off-by: Doug Anderson <dianders@chromium.org>
tools/patman/README
tools/patman/gitutil.py
tools/patman/patman.py
tools/patman/settings.py

index 16b51eb59c7fb063f6fe98e6f0eebfad08498716..2743da9eb2981f27fd73c99080c59a4d7bca0e7e 100644 (file)
@@ -98,6 +98,22 @@ The checkpatch.pl in the U-Boot tools/ subdirectory will be located and
 used. Failing that you can put it into your path or ~/bin/checkpatch.pl
 
 
+If you want to change the defaults for patman's command-line arguments,
+you can add a [settings] section to your .patman file.  This can be used
+for any command line option by referring to the "dest" for the option in
+patman.py.  For reference, the useful ones (at the moment) shown below
+(all with the non-default setting):
+
+>>>
+
+[settings]
+ignore_errors: True
+process_tags: False
+verbose: True
+
+<<<
+
+
 How to run it
 =============
 
index 41a74a55a08aea9eb29b3fd9a1d805a2ee06bd98..ca3ba4a03e49a01e40522b5fdd03df5ef514fdbc 100644 (file)
@@ -384,8 +384,6 @@ def GetDefaultUserEmail():
 
 def Setup():
     """Set up git utils, by reading the alias files."""
-    settings.Setup('')
-
     # Check for a git alias file also
     alias_fname = GetAliasFile()
     if alias_fname:
index 4181d807897a7e98324dcc65dd82a9597c306ad5..b327c675f719eedd0a748c6a71b5ec5c34a85f39 100755 (executable)
@@ -34,6 +34,7 @@ import checkpatch
 import command
 import gitutil
 import patchstream
+import settings
 import terminal
 import test
 
@@ -64,6 +65,8 @@ parser.usage = """patman [options]
 Create patches from commits in a branch, check them and email them as
 specified by tags you place in the commits. Use -n to """
 
+
+settings.Setup(parser, '')
 (options, args) = parser.parse_args()
 
 # Run our meagre tests
index 4dda17bf516d15ebab877f2d1e1f61b13bfe5cc8..5208f7df6ab9198e3b770a1e9801a93b3afa6bb5 100644 (file)
@@ -88,13 +88,43 @@ def CreatePatmanConfigFile(config_fname):
     print >>f, "[alias]\nme: %s <%s>" % (name, email)
     f.close();
 
-def Setup(config_fname=''):
+def _UpdateDefaults(parser, config):
+    """Update the given OptionParser defaults based on config.
+
+    We'll walk through all of the settings from the parser
+    For each setting we'll look for a default in the option parser.
+    If it's found we'll update the option parser default.
+
+    The idea here is that the .patman file should be able to update
+    defaults but that command line flags should still have the final
+    say.
+
+    Args:
+        parser: An instance of an OptionParser whose defaults will be
+            updated.
+        config: An instance of SafeConfigParser that we will query
+            for settings.
+    """
+    defaults = parser.get_default_values()
+    for name, val in config.items('settings'):
+        if hasattr(defaults, name):
+            default_val = getattr(defaults, name)
+            if isinstance(default_val, bool):
+                val = config.getboolean('settings', name)
+            elif isinstance(default_val, int):
+                val = config.getint('settings', name)
+            parser.set_default(name, val)
+        else:
+            print "WARNING: Unknown setting %s" % name
+
+def Setup(parser, config_fname=''):
     """Set up the settings module by reading config files.
 
     Args:
+        parser:         The parser to update
         config_fname:   Config filename to read ('' for default)
     """
-    settings = ConfigParser.SafeConfigParser()
+    config = ConfigParser.SafeConfigParser()
     if config_fname == '':
         config_fname = '%s/.patman' % os.getenv('HOME')
 
@@ -102,11 +132,12 @@ def Setup(config_fname=''):
         print "No config file found ~/.patman\nCreating one...\n"
         CreatePatmanConfigFile(config_fname)
 
-    settings.read(config_fname)
+    config.read(config_fname)
 
-    for name, value in settings.items('alias'):
+    for name, value in config.items('alias'):
         alias[name] = value.split(',')
 
+    _UpdateDefaults(parser, config)
 
 # These are the aliases we understand, indexed by alias. Each member is a list.
 alias = {}