def register_action(self): if self.direct_register: # register to running instance if self.plugin_task.stock: self.plugin_task.register_action() else: try: self.plugin_task.register_action() except Exception: if PLUGIN_TEMP_FOLDER: _x_info = sys.exc_info() sys.stderr.write( "%s: %s\n" % (_x_info[0].__name__, _x_info[1])) traceback.print_tb(_x_info[2]) if self.plugin_cond.stock: self.plugin_cond.register_action() else: try: self.plugin_cond.register_action() except Exception: if PLUGIN_TEMP_FOLDER: _x_info = sys.exc_info() sys.stderr.write( "%s: %s\n" % (_x_info[0].__name__, _x_info[1])) traceback.print_tb(_x_info[2]) if not register_plugin_data(self.plugin_task): return False if not register_plugin_data(self.plugin_cond): unregister_plugin_data(self.plugin_task) return False else: t = time.localtime() l = (self.plugin_task.basename, self.plugin_cond.basename) filename = time.strftime(RESOURCES.IDF_FILENAME_FORMAT, t) filepath = os.path.join(USER_STORE_FOLDER, filename) with open(filepath, 'w') as f: f.write(RESOURCES.IDF_PREAMBLE_START % time.strftime(RESOURCES.FORMAT_TIMESTAMP, t)) f.write(RESOURCES.IDF_PREAMBLE_EXPLAIN_TASK % self.plugin_task.summary_description) f.write(RESOURCES.IDF_PREAMBLE_EXPLAIN_CONDITION % self.plugin_cond.summary_description) f.write(RESOURCES.IDF_PREAMBLE_EXPLAIN_PLUGINS % ", ".join(l)) f.write(RESOURCES.IDF_PREAMBLE_END % filename) add_to_file(self.plugin_cond, f) add_to_file(self.plugin_task, f) f.write(RESOURCES.IDF_FOOTER) try: ret = subprocess.call('%s --item-add %s' % (APP_WHEN, filepath), shell=True) if ret != 0: return False except OSError: return False store_plugin(self.plugin_cond) store_plugin(self.plugin_task) store_association(self.plugin_cond, self.plugin_task) return True
def click_btnDeleteAll(self, obj): o = self.builder.get_object confirmbox = Gtk.MessageDialog(type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.YES_NO) confirmbox.set_markup( RESOURCES.MSGBOX_CONFIRM_DELETE_ALL_ASSOCIATIONS) ret = confirmbox.run() confirmbox.hide() confirmbox.destroy() if ret == Gtk.ResponseType.YES: association_ids = retrieve_association_ids() for x in association_ids: li = retrieve_association(x) plugin_cond = retrieve_plugin(li[0]) plugin_task = retrieve_plugin(li[1]) unregister_plugin_data(plugin_cond) unregister_plugin_data(plugin_task) if plugin_cond.stock: plugin_cond.remove_action() else: try: plugin_cond.remove_action() except Exception: if PLUGIN_TEMP_FOLDER: _x_info = sys.exc_info() sys.stderr.write( "%s: %s\n" % (_x_info[0].__name__, _x_info[1])) traceback.print_tb(_x_info[2]) if plugin_task.stock: plugin_task.remove_action() else: try: plugin_task.remove_action() except Exception: if PLUGIN_TEMP_FOLDER: _x_info = sys.exc_info() sys.stderr.write( "%s: %s\n" % (_x_info[0].__name__, _x_info[1])) traceback.print_tb(_x_info[2]) unstore_association(x) self.selected_association = None self.fill_listAssociations(None) self.fill_cbSelectUninstallPlugin(None) o('txtCondition').set_text("") o('txtConsequence').set_text("")