Skip to contentSkip to conversation

Add exception handling into Hob

PATCH New Shane Wang 1 participant 2 messages Apr 15, 2012

lore
Share & tools
lore

Shane Wang

author
#0 lore raw

cover Add exception handling into Hob

This patch is to add try-except-finally exception handling to Hob. Please review.

The following changes since commit a5210e47b08e0ee42e9e188d83953203147a994d:

guile: Fix binary relocation issue for precompiled guile objects (2012-04-15 12:06:41 +0100)

are available in the git repository at:
git://git.pokylinux.org/poky-contrib shane/hob_0415
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=shane/hob_0415

Shane Wang (1):
Hob: add exception handling

 bitbake/lib/bb/ui/crumbs/builder.py         |   56 ++++++---
 bitbake/lib/bb/ui/crumbs/hobeventhandler.py |  175 ++++++++++++++-------------
 2 files changed, 128 insertions(+), 103 deletions(-)
Signature · 1 line
1.7.6
author
#1 lore raw

PATCH 1/1 Hob: add exception handling

Create a wrapper with exception handling to call self.server.runCommand() safely. Again, add exception handling to load_template() and save_template()

---
 bitbake/lib/bb/ui/crumbs/builder.py         |   56 ++++++---
 bitbake/lib/bb/ui/crumbs/hobeventhandler.py |  175 ++++++++++++++-------------
 2 files changed, 128 insertions(+), 103 deletions(-)
bitbake/lib/bb/ui/crumbs/builder.py +36 -20
index 48053b3..d916199 100755
@@ -466,11 +466,15 @@ class Builder(gtk.Window):
             return None
 
         self.template = TemplateMgr()
-        self.template.load(path)
-        self.configuration.load(self.template)
-
-        self.template.destroy()
-        self.template = None
+        try:
+            self.template.load(path)
+            self.configuration.load(self.template)
+        except Exception as e:
+            self.show_error_dialog("Hob Exception - %s" % (str(e)))
+            self.reset()
+        finally:
+            self.template.destroy()
+            self.template = None
 
         for layer in self.configuration.layers:
             if not os.path.exists(layer+'/conf/layer.conf'):
@@ -489,12 +493,17 @@ class Builder(gtk.Window):
             path = path[0:path.rfind("/")]
 
         self.template = TemplateMgr()
-        self.template.open(filename, path)
-        self.configuration.save(self.template, defaults)
+        try:
+            self.template.open(filename, path)
+            self.configuration.save(self.template, defaults)
 
-        self.template.save()
-        self.template.destroy()
-        self.template = None
+            self.template.save()
+        except Exception as e:
+            self.show_error_dialog("Hob Exception - %s" % (str(e)))
+            self.reset()
+        finally:
+            self.template.destroy()
+            self.template = None
 
     def save_defaults(self):
         if not os.path.exists(".hob/"):
@@ -589,6 +598,12 @@ class Builder(gtk.Window):
             self.configuration.update(params)
             self.parameters.update(params)
 
+    def reset(self):
+        self.configuration.curr_mach = ""
+        self.configuration.clear_selection()
+        self.image_configuration_page.switch_machine_combo()
+        self.switch_page(self.MACHINE_SELECTION)
+
     # Callback Functions
     def handler_config_updated_cb(self, handler, which, values):
         if which == "distro":
@@ -629,19 +644,20 @@ class Builder(gtk.Window):
             elif self.current_step == self.IMAGE_GENERATING:
                 self.switch_page(self.IMAGE_GENERATED)
 
+    def show_error_dialog(self, msg):
+        lbl = "<b>Error</b>\n"
+        lbl = lbl + "%s\n\n" % msg
+        dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_ERROR)
+        button = dialog.add_button("Close", gtk.RESPONSE_OK)
+        HobButton.style_button(button)
+        response = dialog.run()
+        dialog.destroy()
+
     def handler_command_failed_cb(self, handler, msg):
         if msg:
             msg = msg.replace("your local.conf", "Settings")
-            lbl = "<b>Error</b>\n"
-            lbl = lbl + "%s\n\n" % msg
-            dialog = CrumbsMessageDialog(self, lbl, gtk.STOCK_DIALOG_ERROR)
-            button = dialog.add_button("Close", gtk.RESPONSE_OK)
-            HobButton.style_button(button)
-            response = dialog.run()
-            dialog.destroy()
-        self.configuration.curr_mach = ""
-        self.image_configuration_page.switch_machine_combo()
-        self.switch_page(self.MACHINE_SELECTION)
+            self.show_error_dialog(msg)
+        self.reset()
 
     def window_sensitive(self, sensitive):
         self.image_configuration_page.machine_combo.set_sensitive(sensitive)
bitbake/lib/bb/ui/crumbs/hobeventhandler.py +92 -83

335 lines not on this page · raw message

Signature · 1 line
1.7.6