Skip to contentSkip to conversation

data_smart: Add appendVar/prependVar functions

RFC PATCH In review Richard Purdie 2 participants 2 messages Nov 8, 2011

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 data_smart: Add appendVar/prependVar functions

This patch adds appendVar and prependVar functions to the data store meaning python code would no longer have to do the getVar, append and the setVar dance that much of the current python code does.

It also adds corresponding variants for flags.

Currently there is no spacing added by these functions. That could be added as a parameter if desired.

If these functions turn out to be hotspots in the code, there are tricks that could potentially be used to increase the speed of these specific operations within the datastore.

lib/bb/data_smart.py +16 -0
index d8ba24f..aa25c0a 100644
@@ -298,6 +298,14 @@ class DataSmart(MutableMapping):
 
         self.delVar(key)
 
+    def appendVar(self, key, value):
+        value = (self.getVar(key, False) or "") + value
+        self.setVar(key, value)
+
+    def prependVar(self, key, value):
+        value = value + (self.getVar(key, False) or "")
+        self.setVar(key, value)
+
     def delVar(self, var):
         self.expand_cache = {}
         self.dict[var] = {}
@@ -333,6 +341,14 @@ class DataSmart(MutableMapping):
         if var in self.dict and flag in self.dict[var]:
             del self.dict[var][flag]
 
+    def appendVarFlag(self, key, flag, value):
+        value = (self.getVarFlag(key, flag, False) or "") + value
+        self.setVarFlag(key, flag, value)
+
+    def prependVarFlag(self, key, flag, value):
+        value = value + (self.getVarFlag(key, flag, False) or "")
+        self.setVarFlag(key, flag, value)
+
     def setVarFlags(self, var, flags):
         if not var in self.dict:
             self._makeShadowCopy(var)
#1 lore raw
Quoted 3 lines · Richard Purdie

This patch adds appendVar and prependVar functions to the data store meaning python code would no longer have to do the getVar, append and the setVar dance that much of the current python code does.

So useful! Thanks for this.

Scott

Signature · 3 lines
Scott Garman
Embedded Linux Engineer - Yocto Project
Intel Open Source Technology Center