Patchwork [2/7] wic: Add utility function for parsing sourceparams

login
register
mail settings
Submitter tom.zanussi@linux.intel.com
Date Aug. 12, 2014, 1:35 a.m.
Message ID <e646c60804ff223f54de4fb08353ec33cc573d6c.1407806939.git.tom.zanussi@linux.intel.com>
Download mbox | patch
Permalink /patch/77923/
State Accepted
Commit ef700ea11f51f239a886831ad26ff0d64b57c73d
Headers show

Comments

tom.zanussi@linux.intel.com - Aug. 12, 2014, 1:35 a.m.
Parses strings of the form key1=val1[,key2=val2,...] and returns a
dict.  Also accepts valueless keys i.e. without =.

Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
 scripts/lib/wic/utils/oe/misc.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Patch

diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py
index 87e3041..aa9b235 100644
--- a/scripts/lib/wic/utils/oe/misc.py
+++ b/scripts/lib/wic/utils/oe/misc.py
@@ -179,3 +179,26 @@  def get_bitbake_var(key):
             val = get_line_val(line, key)
             return val
     return None
+
+def parse_sourceparams(sourceparams):
+    """
+    Split sourceparams string of the form key1=val1[,key2=val2,...]
+    into a dict.  Also accepts valueless keys i.e. without =.
+
+    Returns dict of param key/val pairs (note that val may be None).
+    """
+    params_dict = {}
+
+    params = sourceparams.split(',')
+    if params:
+        for p in params:
+            if not p:
+                continue
+            if not '=' in p:
+                key = p
+                val = None
+            else:
+                key, val = p.split('=')
+            params_dict[key] = val
+
+    return params_dict