~saurabhanandiit/gtg/exportFixed

« back to all changes in this revision

Viewing changes to GTG/plugins/bugzilla/bugzilla.py

Merge of my work on liblarch newbase and all the backends ported to liblarch
(which mainly means porting the datastore).
One failing test, will check it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# You should have received a copy of the GNU General Public License along with
15
15
# this program.  If not, see <http://www.gnu.org/licenses/>.
16
16
 
 
17
import gobject
 
18
import threading
17
19
from urlparse import urlparse
18
20
 
19
21
from GTG.plugins.bugzilla.server import ServersStore
20
22
from GTG.plugins.bugzilla.bug import Bug
21
23
 
 
24
 
 
25
 
22
26
class pluginBugzilla:
23
27
 
 
28
 
24
29
    def __init__(self):
25
30
        self.servers = ServersStore()
26
31
 
27
32
    def activate(self, plugin_api):
28
 
        plugin_api.register_quick_add_cb(self.task_added_cb)
29
 
 
30
 
    def task_added_cb(self, task):
 
33
        self.plugin_api = plugin_api
 
34
        self.connect_id = plugin_api.get_ui().connect("task-added-via-quick-add", \
 
35
                                      self.task_added_cb)
 
36
 
 
37
    def task_added_cb(self, sender, task_id):
 
38
        #this is a gobject callback that will block the Browser.
 
39
        #decoupling with a thread. All interaction with task and tags objects
 
40
        #(anything in a Tree) must be done with gobject.idle_add (invernizzi)
 
41
        thread = threading.Thread(target = self.__analyze_task,
 
42
                                  args = (task_id, ))
 
43
        thread.setDaemon(True)
 
44
        thread.start()
 
45
 
 
46
    def __analyze_task(self, task_id):
 
47
        task = self.plugin_api.get_requester().get_task(task_id)
31
48
        url = task.get_title()
32
49
        r = urlparse(url)
33
50
        if r.hostname is None:
55
72
            # can't find the title of the bug
56
73
            return
57
74
 
58
 
        task.set_title('#%s: %s' % (nb, title))
 
75
        gobject.idle_add(task.set_title, '#%s: %s' % (nb, title))
59
76
 
60
77
        text = "%s\n\n%s" % (url, bug.get_description())
61
 
        task.set_text(text)
 
78
        gobject.idle_add(task.set_text, text)
62
79
 
63
80
        tag = server.get_tag(bug)
64
81
        if tag is not None:
65
 
            task.add_tag('@%s' % tag)
 
82
            gobject.idle_add(task.add_tag, '@%s' % tag)
66
83
 
67
84
    def deactivate(self, plugin_api):
68
 
        plugin_api.unregister_quick_add_cb(self.task_added_cb)
69
 
 
70
 
    def onTaskOpened(self, plugin_api):
71
 
        pass
 
85
        plugin_api.get_ui().disconnect(self.connect_id)