class pluginBugzilla: def __init__(self): self.servers = ServersStore() def activate(self, plugin_api): self.plugin_api = plugin_api self.connect_id = plugin_api.get_ui().connect("task-added-via-quick-add", \ self.task_added_cb) def task_added_cb(self, sender, task_id): #this is a gobject callback that will block the Browser. #decoupling with a thread. All interaction with task and tags objects #(anything in a Tree) must be done with gobject.idle_add (invernizzi) thread = threading.Thread(target = self.__analyze_task, args = (task_id, )) thread.setDaemon(True) thread.start() def __analyze_task(self, task_id): task = self.plugin_api.get_requester().get_task(task_id) url = task.get_title() r = urlparse(url) if r.hostname is None: return server = self.servers.get(r.hostname) if server is None: return base = '%s://%s' % (r.scheme, server.name) # get the number of the bug try: nb = r.query.split('id=')[1] except IndexError: return try: bug = Bug(base, nb) except: return title = bug.get_title() if title is None: # can't find the title of the bug return gobject.idle_add(task.set_title, '#%s: %s' % (nb, title)) text = "%s\n\n%s" % (url, bug.get_description()) gobject.idle_add(task.set_text, text) tag = server.get_tag(bug) if tag is not None: gobject.idle_add(task.add_tag, '@%s' % tag) def deactivate(self, plugin_api): plugin_api.get_ui().disconnect(self.connect_id)
def __init__(self): self.servers = ServersStore()