Patchwork [bitbake-devel,1/3] command.py: Add a hook for config parsing

login
register
mail settings
Submitter Dongxiao Xu
Date April 12, 2012, 3:46 p.m.
Message ID <7cacaa562688f1b5bd78f7dc12b1c1d1a70196e2.1334245432.git.dongxiao.xu@intel.com>
Download mbox | patch
Permalink /patch/25693/
State New
Headers show

Comments

Dongxiao Xu - April 12, 2012, 3:46 p.m.
To make the UI settings take effect, we need to hook at the end of each
config file parsing and set UI specific values.

Signed-off-by: Richar Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com>
---
 lib/bb/command.py                    |    7 +++++++
 lib/bb/parse/parse_py/ConfHandler.py |    5 +++++
 2 files changed, 12 insertions(+), 0 deletions(-)
Richard Purdie - April 13, 2012, 10:54 a.m.
On Thu, 2012-04-12 at 23:46 +0800, Dongxiao Xu wrote:
> To make the UI settings take effect, we need to hook at the end of each
> config file parsing and set UI specific values.
> 
> Signed-off-by: Richar Purdie <richard.purdie@linuxfoundation.org>
> Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com>
> ---
>  lib/bb/command.py                    |    7 +++++++
>  lib/bb/parse/parse_py/ConfHandler.py |    5 +++++
>  2 files changed, 12 insertions(+), 0 deletions(-)
> 
> diff --git a/lib/bb/command.py b/lib/bb/command.py
> index 73aaca0..fd8912a 100644
> --- a/lib/bb/command.py
> +++ b/lib/bb/command.py
> @@ -179,6 +179,13 @@ class CommandsSync:
>          """
>          return bb.utils.cpu_count()
>  
> +    def setConfFilter(self, command, params):
> +        """
> +        Set the configuration file parsing filter
> +        """
> +        filterfunc = params[0]
> +        bb.parse.parse_py.ConfHandler.confFilters.append(filterfunc)
> +
>  class CommandsAsync:
>      """
>      A class of asynchronous commands
> diff --git a/lib/bb/parse/parse_py/ConfHandler.py b/lib/bb/parse/parse_py/ConfHandler.py
> index fa811f3..f108c24 100644
> --- a/lib/bb/parse/parse_py/ConfHandler.py
> +++ b/lib/bb/parse/parse_py/ConfHandler.py
> @@ -71,6 +71,8 @@ def include(oldfn, fn, lineno, data, error_out):
>              raise ParseError("Could not %(error_out)s file %(fn)s" % vars(), oldfn, lineno)
>          logger.debug(2, "CONF file '%s' not found", fn)
>  
> +confFilters = []
> +
>  def handle(fn, data, include):
>      init(data)
>  
> @@ -107,6 +109,9 @@ def handle(fn, data, include):
>      if oldfile:
>          data.setVar('FILE', oldfile)
>  
> +    for f in confFilters:
> +        f(fn, data)
> +
>      return data
>  
>  def feeder(lineno, s, fn, statements):


I've merged this but I added in a comment block about why we need to do
this since its not immediately clear why we need to do something quite
this nasty.

Cheers,

Richard

Patch

diff --git a/lib/bb/command.py b/lib/bb/command.py
index 73aaca0..fd8912a 100644
--- a/lib/bb/command.py
+++ b/lib/bb/command.py
@@ -179,6 +179,13 @@  class CommandsSync:
         """
         return bb.utils.cpu_count()
 
+    def setConfFilter(self, command, params):
+        """
+        Set the configuration file parsing filter
+        """
+        filterfunc = params[0]
+        bb.parse.parse_py.ConfHandler.confFilters.append(filterfunc)
+
 class CommandsAsync:
     """
     A class of asynchronous commands
diff --git a/lib/bb/parse/parse_py/ConfHandler.py b/lib/bb/parse/parse_py/ConfHandler.py
index fa811f3..f108c24 100644
--- a/lib/bb/parse/parse_py/ConfHandler.py
+++ b/lib/bb/parse/parse_py/ConfHandler.py
@@ -71,6 +71,8 @@  def include(oldfn, fn, lineno, data, error_out):
             raise ParseError("Could not %(error_out)s file %(fn)s" % vars(), oldfn, lineno)
         logger.debug(2, "CONF file '%s' not found", fn)
 
+confFilters = []
+
 def handle(fn, data, include):
     init(data)
 
@@ -107,6 +109,9 @@  def handle(fn, data, include):
     if oldfile:
         data.setVar('FILE', oldfile)
 
+    for f in confFilters:
+        f(fn, data)
+
     return data
 
 def feeder(lineno, s, fn, statements):