← Back to team overview

gtg team mailing list archive

[Merge] lp:~cassidy/gtg/bugzilla into lp:gtg

 

Guillaume Desmottes has proposed merging lp:~cassidy/gtg/bugzilla into lp:gtg.

    Requested reviews:
    Gtg developers (gtg)
Related bugs:
  #455593 Bugzilla plugin
  https://bugs.launchpad.net/bugs/455593

-- 
https://code.launchpad.net/~cassidy/gtg/bugzilla/+merge/13877
Your team Gtg developers is subscribed to branch lp:gtg.
=== modified file 'GTG/core/plugins/api.py'
--- GTG/core/plugins/api.py	2009-09-24 15:05:42 +0000
+++ GTG/core/plugins/api.py	2009-10-23 22:40:23 +0000
@@ -31,7 +31,7 @@
         
     def __init__(self, window, config, data_dir, wTree, requester,\
                  taskview, filter_cbs, tagpopup, tagview, task=None,\
-                 textview=None):
+                 textview=None, quick_add_cbs=[]):
         """Construct a L{PluginAPI} object.
         
         @param window: The window where the plugin API object is being 
@@ -59,6 +59,7 @@
         self.tagview = tagview
         
         self.__filter_cbs = filter_cbs
+        self.__quick_add_cbs = quick_add_cbs
         
         if task:
             self.task = task
@@ -431,3 +432,21 @@
         if func in self.__filter_cbs:
             self.__filter_cbs.remove(func)    
 #=== Filtering methods ========================================================
+
+    def register_quick_add_cb(self, func):
+        """Registers a callback that will be called each time a new task is
+        added using the "quick add" entry.
+
+        @param func: The function that is going to be registered.
+
+        """
+        if func not in self.__quick_add_cbs:
+            self.__quick_add_cbs.append(func)
+
+    def unregister_quick_add_cb(self, func):
+        """Unregisters a previously registered "quick add" callback.
+
+        @param func: The function that is going to be unregistered.
+        """
+        if func in self.__quick_add_cbs:
+            self.__quick_add_cbs.remove(func)

=== added directory 'GTG/plugins/bugzilla'
=== added file 'GTG/plugins/bugzilla.gtg-plugin'
--- GTG/plugins/bugzilla.gtg-plugin	1970-01-01 00:00:00 +0000
+++ GTG/plugins/bugzilla.gtg-plugin	2009-10-23 22:40:23 +0000
@@ -0,0 +1,8 @@
+[GTG Plugin]
+Module=bugzilla
+Name=Bugzilla
+Description=Bugzilla integration
+Authors=Guillaume Desmottes <gdesmott@xxxxxxxxx>
+Version=0.0.1
+Dependencies=bugz,
+Enabled=False

=== added file 'GTG/plugins/bugzilla/__init__.py'
--- GTG/plugins/bugzilla/__init__.py	1970-01-01 00:00:00 +0000
+++ GTG/plugins/bugzilla/__init__.py	2009-10-23 22:40:23 +0000
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2009 - Paulo Cabido <paulo.cabido@xxxxxxxxx>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import sys,os
+sys.path.insert(0,os.getcwd())
+#sys.path.insert(0,os.path.dirname(os.path.abspath(__file__)))
+from bugzilla import pluginBugzilla

=== added file 'GTG/plugins/bugzilla/bug.py'
--- GTG/plugins/bugzilla/bug.py	1970-01-01 00:00:00 +0000
+++ GTG/plugins/bugzilla/bug.py	2009-10-23 22:40:23 +0000
@@ -0,0 +1,46 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2009 - Guillaume Desmottes <gdesmott@xxxxxxxxx>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from bugz import Bugz
+
+class Bug:
+    def __init__(self, base, nb):
+        self.bug = Bugz(base).get(nb)
+        if self.bug is None:
+            raise Exception('Failed to create bug')
+
+    def _get_detail(self, detail):
+        tmp = self.bug.find('//%s' % detail)
+        if tmp is None:
+            return None
+
+        return tmp.text
+
+    def get_title(self):
+        return self._get_detail('short_desc')
+
+    def get_product(self):
+        return self._get_detail('product')
+
+    def get_component(self):
+        return self._get_detail('component')
+
+if __name__ == '__main__':
+     for bug in [Bug('http://bugzilla.gnome.org', '598354'),
+         Bug('http://bugs.freedesktop.org', '24120')]:
+        print "title:", bug.get_title()
+        print "product:", bug.get_product()
+        print "component:", bug.get_component()

=== added file 'GTG/plugins/bugzilla/bugzilla.py'
--- GTG/plugins/bugzilla/bugzilla.py	1970-01-01 00:00:00 +0000
+++ GTG/plugins/bugzilla/bugzilla.py	2009-10-23 22:40:23 +0000
@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2009 - Guillaume Desmottes <gdesmott@xxxxxxxxx>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from urlparse import urlparse
+from server import ServersStore
+from bug import Bug
+
+class pluginBugzilla:
+
+    def __init__(self):
+        self.servers = ServersStore()
+
+    def activate(self, plugin_api):
+        plugin_api.register_quick_add_cb(self.task_added_cb)
+
+    def task_added_cb(self, task):
+        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
+
+        task.set_title('#%s: %s' % (nb, title))
+        task.set_text(url)
+
+        tag = server.get_tag(bug)
+        if tag is not None:
+            task.add_tag('@%s' % tag)
+
+    def deactivate(self, plugin_api):
+        plugin_api.unregister_quick_add_cb(self.task_added_cb)
+
+    def onTaskOpened(self, plugin_api):
+        pass

=== added file 'GTG/plugins/bugzilla/server.py'
--- GTG/plugins/bugzilla/server.py	1970-01-01 00:00:00 +0000
+++ GTG/plugins/bugzilla/server.py	2009-10-23 22:40:23 +0000
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2009 - Guillaume Desmottes <gdesmott@xxxxxxxxx>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+SERVER_TAG_PRODUCT = 1
+SERVER_TAG_COMPONENT = 2
+
+class ServersStore:
+    def __init__(self):
+        self.servers = {}
+
+        # GNOME
+        server = Server('bugzilla.gnome.org')
+        server.tag = SERVER_TAG_PRODUCT
+        self.add(server)
+
+        # freedesktop.org
+        server = Server('bugs.freedesktop.org')
+        server.tag = SERVER_TAG_COMPONENT
+        self.add(server)
+
+    def add(self, server):
+        self.servers[server.name] = server
+
+    def get(self, name):
+        return self.servers.get(name)
+
+class Server:
+    def __init__(self, name):
+        self.name = name
+        self.tag = None
+
+    def get_tag(self, bug):
+        if self.tag is None:
+            return None
+        elif self.tag == SERVER_TAG_PRODUCT:
+            return bug.get_product()
+        elif self.tag == SERVER_TAG_COMPONENT:
+            return bug.get_component()

=== modified file 'GTG/taskbrowser/browser.py'
--- GTG/taskbrowser/browser.py	2009-10-06 15:05:20 +0000
+++ GTG/taskbrowser/browser.py	2009-10-23 22:40:23 +0000
@@ -149,6 +149,7 @@
         self.priv['workview']                 = False
         #self.priv['noteview']                = False
         self.priv['filter_cbs']               = []
+        self.priv['quick_add_cbs']            = []
 
     def _init_icon_theme(self):
         icon_dirs = [GTG.DATA_DIR, os.path.join(GTG.DATA_DIR, "icons")]
@@ -444,7 +445,8 @@
         # initializes the plugin api class
         self.plugin_api = PluginAPI(self.window, self.config, GTG.DATA_DIR, self.wTree,\
                                     self.req, self.task_tv, self.priv['filter_cbs'],\
-                                    self.tagpopup, self.tags_tv, None, None)
+                                    self.tagpopup, self.tags_tv, None, None,\
+                                    self.priv['quick_add_cbs'])
         
         if self.plugins:
             # checks the conf for user settings
@@ -1132,6 +1134,8 @@
             self.quickadd_entry.set_text('')
             # Refresh the treeview
             #self.do_refresh(toselect=id_toselect)
+            for f in self.priv['quick_add_cbs']:
+                f(task)
 
     def on_tag_treeview_button_press_event(self, treeview, event):
         if event.button == 3:


Follow ups