Patchwork [bitbake-devel,5/7] bitbake: cooker, command: add a command to return global data

login
register
mail settings
Submitter Alexandru DAMIAN
Date Sept. 16, 2013, 1:33 p.m.
Message ID <6614ca8b4786486ae3a58e78ca0c40b131c6ff57.1379338189.git.alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/58151/
State New
Headers show

Comments

Alexandru DAMIAN - Sept. 16, 2013, 1:33 p.m.
From: Alexandru DAMIAN <alexandru.damian@intel.com>

Adding the 'getAllKeysWithFlags' read-only command that will
return a dump of the global data state, together with specified
flags for each key. The flag list is passed in as the first
parameter to the command.

This will be used by UI clients to get the build configuration.

Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
---
 bitbake/lib/bb/command.py |  8 ++++++++
 bitbake/lib/bb/cooker.py  | 15 +++++++++++++++
 2 files changed, 23 insertions(+)
Richard Purdie - Sept. 16, 2013, 1:54 p.m.
On Mon, 2013-09-16 at 14:33 +0100, Alex DAMIAN wrote:
> From: Alexandru DAMIAN <alexandru.damian@intel.com>
> 
> Adding the 'getAllKeysWithFlags' read-only command that will
> return a dump of the global data state, together with specified
> flags for each key. The flag list is passed in as the first
> parameter to the command.
> 
> This will be used by UI clients to get the build configuration.
> 
> Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
> ---
>  bitbake/lib/bb/command.py |  8 ++++++++
>  bitbake/lib/bb/cooker.py  | 15 +++++++++++++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/bitbake/lib/bb/command.py b/bitbake/lib/bb/command.py
> index f1abaf7..5d359e7 100644
> --- a/bitbake/lib/bb/command.py
> +++ b/bitbake/lib/bb/command.py
> @@ -145,6 +145,14 @@ class CommandsSync:
>          """
>          command.cooker.shutdown(True)
>  
> +    def getAllKeysWithFlags(self, command, params):
> +        """
> +        Returns a dump of the global state. Call with
> +        variable flags to be retrieved as params.
> +        """
> +        return command.cooker.getAllKeysWithFlags(params[0])
> +    getAllKeysWithFlags.readonly = True

Please match the style of the other commands, i.e.:

+        flaglist = params[0]
+
+        return command.cooker.getAllKeysWithFlags(flaglist)

which then indicates what params[0] actually is. We spell this out in
the functions so people can look at the commands and get some idea of
how to use them without having to look at the code itself.

>      def getVariable(self, command, params):
>          """
>          Read the value of a variable from data
> diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
> index cb0e3e5..981379b 100644
> --- a/bitbake/lib/bb/cooker.py
> +++ b/bitbake/lib/bb/cooker.py
> @@ -1134,6 +1134,21 @@ class BBCooker:
>  
>          self.configuration.server_register_idlecallback(buildTargetsIdle, rq)
>  
> +
> +    def getAllKeysWithFlags(self, flaglist):
> +        dump = {}
> +        for k in self.data.keys():
> +            try:
> +                v = self.data.getVar(k, True)
> +                if not k.startswith("__") and not bool(self.data.getVarFlag(k, 'func')) and not isinstance(v, bb.data_smart.DataSmart):

Please get rid of the "not bool(self.data.getVarFlag(k, 'func')" and
filter your results on the other side of the connection if you need to
do that (you can request the func flag too).

> +                    dump[k] = { 'v' : v }
> +                    for d in flaglist:
> +                        dump[k][d] = self.data.getVarFlag(k, d)
> +            except:

which exceptions are we worried about here? Lets be specific please.

> +                pass
> +        return dump
> +
> +
>      def generateNewImage(self, image, base_image, package_queue, timestamp, description):
>          '''
>          Create a new image with a "require"/"inherit" base_image statement

Patch

diff --git a/bitbake/lib/bb/command.py b/bitbake/lib/bb/command.py
index f1abaf7..5d359e7 100644
--- a/bitbake/lib/bb/command.py
+++ b/bitbake/lib/bb/command.py
@@ -145,6 +145,14 @@  class CommandsSync:
         """
         command.cooker.shutdown(True)
 
+    def getAllKeysWithFlags(self, command, params):
+        """
+        Returns a dump of the global state. Call with
+        variable flags to be retrieved as params.
+        """
+        return command.cooker.getAllKeysWithFlags(params[0])
+    getAllKeysWithFlags.readonly = True
+
     def getVariable(self, command, params):
         """
         Read the value of a variable from data
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index cb0e3e5..981379b 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -1134,6 +1134,21 @@  class BBCooker:
 
         self.configuration.server_register_idlecallback(buildTargetsIdle, rq)
 
+
+    def getAllKeysWithFlags(self, flaglist):
+        dump = {}
+        for k in self.data.keys():
+            try:
+                v = self.data.getVar(k, True)
+                if not k.startswith("__") and not bool(self.data.getVarFlag(k, 'func')) and not isinstance(v, bb.data_smart.DataSmart):
+                    dump[k] = { 'v' : v }
+                    for d in flaglist:
+                        dump[k][d] = self.data.getVarFlag(k, d)
+            except:
+                pass
+        return dump
+
+
     def generateNewImage(self, image, base_image, package_queue, timestamp, description):
         '''
         Create a new image with a "require"/"inherit" base_image statement