From patchwork Tue Dec 4 00:43:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 203519 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 1BAAD2C008F for ; Tue, 4 Dec 2012 11:43:53 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7C2114A176; Tue, 4 Dec 2012 01:43:51 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wRbX8UlJFvfi; Tue, 4 Dec 2012 01:43:51 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E85544A17B; Tue, 4 Dec 2012 01:43:38 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A6E464A170 for ; Tue, 4 Dec 2012 01:43:32 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gsrBoaCfOFRq for ; Tue, 4 Dec 2012 01:43:28 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-we0-f202.google.com (mail-we0-f202.google.com [74.125.82.202]) by theia.denx.de (Postfix) with ESMTPS id 654AD4A132 for ; Tue, 4 Dec 2012 01:43:26 +0100 (CET) Received: by mail-we0-f202.google.com with SMTP id t57so407968wey.3 for ; Mon, 03 Dec 2012 16:43:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=O3dNSOJS7k+hkbnSI/Fp+BYSW60RBAmcF2vx7YOsbHM=; b=Y8VUh+H+JbX0OehL+/Qx5hH8/zqiR/qBaywwfWR6Se03z+LPhTlrJG2pNC/cifahiv WOFRB3lcx9cZmfe4w6BxAGfH2gssnDvgHbIPGMt7EkixW6Jhd5SCVj7+jWIdd65y2dKv 01Tj4N7H2ejd3BFaL5+czink0meFY7iUcIOy08pb38Z7upY9Lb9rYnRi4urnuiOFqlQE +euL4DcVj/OsY60KmDFKEENePxUSdnuwSswVWXCamqBZBzbbXNvJHBX7tAkr/Rnucgki ozAHUrV8uIDOO6qkYJQctkqsMznTghlF3PU7LpewFbZlvVt9gRNwakl676C6jz7bDWYr dpQA== Received: by 10.14.173.136 with SMTP id v8mr12280166eel.2.1354581805134; Mon, 03 Dec 2012 16:43:25 -0800 (PST) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id z44si115320een.0.2012.12.03.16.43.25 (version=TLSv1/SSLv3 cipher=AES128-SHA); Mon, 03 Dec 2012 16:43:25 -0800 (PST) Received: from tictac.mtv.corp.google.com (tictac.mtv.corp.google.com [172.22.73.80]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id 98310200057; Mon, 3 Dec 2012 16:43:24 -0800 (PST) Received: by tictac.mtv.corp.google.com (Postfix, from userid 121310) id D1C9181151; Mon, 3 Dec 2012 16:43:23 -0800 (PST) From: Doug Anderson To: Simon Glass Date: Mon, 3 Dec 2012 16:43:17 -0800 Message-Id: <1354581799-775-2-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1354581799-775-1-git-send-email-dianders@chromium.org> References: <1354321745-1359-1-git-send-email-dianders@chromium.org> <1354581799-775-1-git-send-email-dianders@chromium.org> X-Gm-Message-State: ALoCoQlHMoPs0PGuu3Ij/VBLkRh2cR2F61gsmFCod9IDquI3Gyx67negwZVMNTHg+mSX6KFKhilWT5l5sJghVTh/ui+vf/InfU42M4B/qPsLXSZuqiVeqYG8qEBbzzpc/HYrnD9JQK/EVGqe3Xoh69c6WePhm2D7fnB0ULge93++UVACixTNqLLczvyuM7mb0JYa0SLbyOj+ Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 2/4] patman: Add support for settings in .patman X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 --- Changes in v2: None tools/patman/README | 16 ++++++++++++++++ tools/patman/gitutil.py | 2 -- tools/patman/patman.py | 3 +++ tools/patman/settings.py | 39 +++++++++++++++++++++++++++++++++++---- 4 files changed, 54 insertions(+), 6 deletions(-) diff --git a/tools/patman/README b/tools/patman/README index 16b51eb..2743da9 100644 --- a/tools/patman/README +++ b/tools/patman/README @@ -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 ============= diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py index 72d37a0..e7753cf 100644 --- a/tools/patman/gitutil.py +++ b/tools/patman/gitutil.py @@ -377,8 +377,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: diff --git a/tools/patman/patman.py b/tools/patman/patman.py index 4181d80..b327c67 100755 --- a/tools/patman/patman.py +++ b/tools/patman/patman.py @@ -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 diff --git a/tools/patman/settings.py b/tools/patman/settings.py index 4dda17b..5208f7d 100644 --- a/tools/patman/settings.py +++ b/tools/patman/settings.py @@ -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 = {}