From 2e01a44f3b8406fa2dbcb1cc2061784a2a099eac Mon Sep 17 00:00:00 2001 From: Shane Wang Date: Mon, 16 Apr 2012 00:09:25 +0800 Subject: 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 rev: cb07a027d3366ed30b0f7e5e85d08c6fda4eb5b9) Signed-off-by: Shane Wang Signed-off-by: Richard Purdie --- bitbake/lib/bb/ui/crumbs/builder.py | 56 ++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 20 deletions(-) (limited to 'bitbake/lib/bb/ui/crumbs/builder.py') diff --git a/bitbake/lib/bb/ui/crumbs/builder.py b/bitbake/lib/bb/ui/crumbs/builder.py index cd66c3fc9d..bd45016045 100755 --- a/bitbake/lib/bb/ui/crumbs/builder.py +++ b/bitbake/lib/bb/ui/crumbs/builder.py @@ -464,11 +464,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'): @@ -487,12 +491,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/"): @@ -587,6 +596,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": @@ -619,19 +634,20 @@ class Builder(gtk.Window): if self.current_step == self.FAST_IMAGE_GENERATING: self.generate_image_async() + def show_error_dialog(self, msg): + lbl = "Error\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 = "Error\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) -- cgit v1.2.3-54-g00ecf