Skip to contentSkip to conversation

hob: fix set_extra_setting function

PATCH New Marius Avram 1 participant 1 message Mar 25, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 hob: fix set_extra_setting function

The function is used to save additional variables in the configuration file when the user adds a new (key, value) pair from the Settings->Others. There was a problem though when the function was trying to retrieve an older instance of EXTRA_SETTINGS from the configuration file. Sometimes its value was returned as a dictionary and sometimes a string, which caused a crash when calling ast.literal_eval(). The reason of the problem must be a change in bitbake's parsing system. The changes will fix this issues.

While analysing this problem I discovered that the variables were not saved properly in the configuration file after consecutive changes to Settings->Others because of the way saveConfigurationVar() from cooker.py works. This patch will also solve this issue.

[YOCTO #5989]

---
 bitbake/lib/bb/ui/crumbs/hobeventhandler.py |   30 +++++++++++++++++++--------
 1 file changed, 21 insertions(+), 9 deletions(-)
bitbake/lib/bb/ui/crumbs/hobeventhandler.py +21 -9
index 73d5f98..890e05f 100644
@@ -359,20 +359,32 @@ class HobHandler(gobject.GObject):
         self.set_var_in_file("EXTRA_SETTING", extra_setting, "local.conf")
 
     def set_extra_config(self, extra_setting):
-        old_extra_setting = ast.literal_eval(self.runCommand(["getVariable", "EXTRA_SETTING"]) or "{}")
-        if extra_setting:
-            self.set_var_in_file("EXTRA_SETTING", extra_setting, "local.conf")
-        else:
-            self.remove_var_from_file("EXTRA_SETTING")
+        old_extra_setting = self.runCommand(["getVariable", "EXTRA_SETTING"]) or {}
+        old_extra_setting = str(old_extra_setting)
+
+        old_extra_setting = ast.literal_eval(old_extra_setting)
+        if not type(old_extra_setting) == dict:
+            old_extra_setting = {}
+
+        # settings not changed
+        if old_extra_setting == extra_setting:
+            return
 
-        #remove not needed settings from conf
-        for key in old_extra_setting:
+        # remove the old EXTRA SETTING variable
+        self.remove_var_from_file("EXTRA_SETTING")
+
+        # remove old settings from conf
+        for key in old_extra_setting.keys():
             if key not in extra_setting:
                 self.remove_var_from_file(key)
-        for key in extra_setting.keys():
-            value = extra_setting[key]
+
+        # add new settings
+        for key, value in extra_setting.iteritems():
             self.set_var_in_file(key, value, "local.conf")
 
+        if extra_setting:
+            self.set_var_in_file("EXTRA_SETTING", extra_setting, "local.conf")
+
     def set_http_proxy(self, http_proxy):
         self.set_var_in_file("http_proxy", http_proxy, "local.conf")
 
Signature · 1 line
1.7.9.5