diff mbox series

[U-Boot] patman: Fix error when the email blacklist is missing

Message ID 20170913023028.127727-1-sjg@chromium.org
State Accepted
Commit ad8931400b193f701a415e7f69f1ad454d1b0380
Delegated to: Simon Glass
Headers show
Series [U-Boot] patman: Fix error when the email blacklist is missing | expand

Commit Message

Simon Glass Sept. 13, 2017, 2:30 a.m. UTC
This section of the settings file may be missing. Handle that gracefully
rather than emitting an error.

Also update patman to write this section when a new settings file is
created.

Fixes: e11aa602 (patman: add support for omitting bouncing addresses)

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/patman/settings.py | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

Comments

Chris Packham Sept. 13, 2017, 4:56 a.m. UTC | #1
On Wed, Sep 13, 2017 at 2:30 PM, Simon Glass <sjg@chromium.org> wrote:
> This section of the settings file may be missing. Handle that gracefully
> rather than emitting an error.
>
> Also update patman to write this section when a new settings file is
> created.
>
> Fixes: e11aa602 (patman: add support for omitting bouncing addresses)
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>

Reviewed-by: Chris Packham <judge.pckham@gmail.com>

>  tools/patman/settings.py | 28 +++++++++++++++++++++++++---
>  1 file changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/tools/patman/settings.py b/tools/patman/settings.py
> index d735ff9ba3..92379b72e7 100644
> --- a/tools/patman/settings.py
> +++ b/tools/patman/settings.py
> @@ -212,7 +212,12 @@ def CreatePatmanConfigFile(config_fname):
>          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):
> @@ -282,6 +287,23 @@ def _ReadBouncesFile(fname):
>                      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.
>
> @@ -303,11 +325,11 @@ def Setup(parser, project_name, config_fname=''):
>
>      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 config.items('bounces'):
> +    for name, value in GetItems(config, 'bounces'):
>          bounces.add(value)
>
>      _UpdateDefaults(parser, config)
> --
> 2.14.1.581.gf28d330327-goog
>
Bin Meng Sept. 13, 2017, 5:29 a.m. UTC | #2
On Wed, Sep 13, 2017 at 12:56 PM, Chris Packham <judge.packham@gmail.com> wrote:
> On Wed, Sep 13, 2017 at 2:30 PM, Simon Glass <sjg@chromium.org> wrote:
>> This section of the settings file may be missing. Handle that gracefully
>> rather than emitting an error.
>>
>> Also update patman to write this section when a new settings file is
>> created.
>>
>> Fixes: e11aa602 (patman: add support for omitting bouncing addresses)
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>
> Reviewed-by: Chris Packham <judge.pckham@gmail.com>
>

Tested-by: Bin Meng <bmeng.cn@gmail.com>
Simon Glass Sept. 14, 2017, 1:33 a.m. UTC | #3
On 12 September 2017 at 23:29, Bin Meng <bmeng.cn@gmail.com> wrote:
> On Wed, Sep 13, 2017 at 12:56 PM, Chris Packham <judge.packham@gmail.com> wrote:
>> On Wed, Sep 13, 2017 at 2:30 PM, Simon Glass <sjg@chromium.org> wrote:
>>> This section of the settings file may be missing. Handle that gracefully
>>> rather than emitting an error.
>>>
>>> Also update patman to write this section when a new settings file is
>>> created.
>>>
>>> Fixes: e11aa602 (patman: add support for omitting bouncing addresses)
>>>
>>> Signed-off-by: Simon Glass <sjg@chromium.org>
>>> ---
>>>
>>
>> Reviewed-by: Chris Packham <judge.pckham@gmail.com>
>>
>
> Tested-by: Bin Meng <bmeng.cn@gmail.com>

Applied to u-boot-dm
diff mbox series

Patch

diff --git a/tools/patman/settings.py b/tools/patman/settings.py
index d735ff9ba3..92379b72e7 100644
--- a/tools/patman/settings.py
+++ b/tools/patman/settings.py
@@ -212,7 +212,12 @@  def CreatePatmanConfigFile(config_fname):
         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):
@@ -282,6 +287,23 @@  def _ReadBouncesFile(fname):
                     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.
 
@@ -303,11 +325,11 @@  def Setup(parser, project_name, config_fname=''):
 
     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 config.items('bounces'):
+    for name, value in GetItems(config, 'bounces'):
         bounces.add(value)
 
     _UpdateDefaults(parser, config)