Merge lp:~dobey/desktopcouch/fix-696968 into lp:desktopcouch

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: 244
Merged at revision: 249
Proposed branch: lp:~dobey/desktopcouch/fix-696968
Merge into: lp:desktopcouch
Diff against target: 233 lines (+59/-34)
6 files modified
desktopcouch/application/platform/linux/__init__.py (+0/-3)
desktopcouch/application/plugins/__init__.py (+7/-6)
desktopcouch/application/plugins/tests/test_plugins.py (+44/-0)
desktopcouch/application/plugins/ubuntuone_pairing.py (+3/-2)
desktopcouch/application/service.py (+3/-10)
desktopcouch/application/tests/test_service.py (+2/-13)
To merge this branch: bzr merge lp:~dobey/desktopcouch/fix-696968
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+45252@code.launchpad.net

Commit message

Fix the issues with the plug-in loader to actually load the plug-ins
Move the plug-in loading call to the dbus service startup
Remove the old entry_points code using pkg_resources

Description of the change

This fixes the loading of the plug-ins and adds a bit more testing for it.

However, it is not easily testable at the moment, due to further reaching issues with interaction between dbus, main loops, and os.fork in desktopcouch.

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks good

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Code looks good though I couldn't make a fieldtest.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/application/platform/linux/__init__.py'
2--- desktopcouch/application/platform/linux/__init__.py 2010-12-16 21:13:00 +0000
3+++ desktopcouch/application/platform/linux/__init__.py 2011-01-05 15:54:30 +0000
4@@ -20,8 +20,6 @@
5 import re
6 import logging
7
8-from desktopcouch.application.plugins import load_plugins
9-
10
11 def process_is_couchdb(pid):
12 """Find if the process with the given pid is couchdb."""
13@@ -190,6 +188,5 @@
14 from dbus.mainloop.glib import DBusGMainLoop
15 DBusGMainLoop(set_as_default=True)
16 set_application_name('desktopcouch service')
17- load_plugins()
18 from twisted.internet import reactor
19 return reactor
20
21=== modified file 'desktopcouch/application/plugins/__init__.py'
22--- desktopcouch/application/plugins/__init__.py 2010-12-16 22:08:22 +0000
23+++ desktopcouch/application/plugins/__init__.py 2011-01-05 15:54:30 +0000
24@@ -13,10 +13,10 @@
25 # along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
26 """Desktopcouch application plugins."""
27
28+import logging
29 import os
30
31-DESKTOPCOUCH_PLUGIN_PATHS = [os.path.join(
32- os.path.dirname(__file__), 'plugins')]
33+DESKTOPCOUCH_PLUGIN_PATHS = [os.path.join(os.path.dirname(__file__))]
34
35
36 def load_plugins():
37@@ -28,14 +28,15 @@
38 if _file == '__init__':
39 continue
40 elif _file.endswith('.py') and _file != '__init__.py':
41- plugin_names.add(os.path.join(path, _file))
42+ plugin_names.add(os.path.join(
43+ 'desktopcouch', 'application', 'plugins', _file))
44 except OSError:
45 continue
46
47 for name in plugin_names:
48+ modpath = name.replace(os.path.sep, '.')[:-3]
49 try:
50- modpath = name.replace(os.path.sep, '.')[:-3]
51 plugin = __import__(modpath, None, None, [''])
52 plugin.plugin_init()
53- except ImportError:
54- pass
55+ except (ImportError, AttributeError):
56+ logging.warning('Failed to load plug-in: %s', modpath)
57
58=== added file 'desktopcouch/application/plugins/tests/test_plugins.py'
59--- desktopcouch/application/plugins/tests/test_plugins.py 1970-01-01 00:00:00 +0000
60+++ desktopcouch/application/plugins/tests/test_plugins.py 2011-01-05 15:54:30 +0000
61@@ -0,0 +1,44 @@
62+# Copyright 2011 Canonical Ltd.
63+#
64+# This file is part of desktopcouch.
65+#
66+# desktopcouch is free software: you can redistribute it and/or modify
67+# it under the terms of the GNU Lesser General Public License version 3
68+# as published by the Free Software Foundation.
69+#
70+# desktopcouch is distributed in the hope that it will be useful,
71+# but WITHOUT ANY WARRANTY; without even the implied warranty of
72+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73+# GNU Lesser General Public License for more details.
74+#
75+# You should have received a copy of the GNU Lesser General Public License
76+# along with desktopcouch. If not, see <http://www.gnu.org/licenses/>.
77+"""Tests for the plug-ins loading."""
78+
79+import os
80+
81+from desktopcouch.application import plugins
82+from unittest import TestCase
83+
84+
85+class TestLoadPlugins(TestCase):
86+ """Tests for loading plug-ins."""
87+
88+ def test_load_plugins(self):
89+ """Test that plug-ins are loaded correctly."""
90+ # pylint: disable=W0201
91+ old_paths = plugins.DESKTOPCOUCH_PLUGIN_PATHS
92+ plugins.DESKTOPCOUCH_PLUGIN_PATHS = [os.path.join(
93+ os.path.dirname(__file__))]
94+ self._imported = None
95+ def _fake_import(name, *args, **kwargs):
96+ """Fake import to check that we get imported."""
97+ modname = name.replace('.test_', '.tests.test_')
98+ if modname == __name__:
99+ self._imported = modname
100+ old_import = __import__
101+ __builtins__['__import__'] = _fake_import
102+ plugins.load_plugins()
103+ __builtins__['__import__'] = old_import
104+ plugins.DESKTOPCOUCH_PLUGIN_PATHS = old_paths
105+ self.assertEqual(self._imported, __name__)
106
107=== modified file 'desktopcouch/application/plugins/ubuntuone_pairing.py'
108--- desktopcouch/application/plugins/ubuntuone_pairing.py 2011-01-03 13:31:57 +0000
109+++ desktopcouch/application/plugins/ubuntuone_pairing.py 2011-01-05 15:54:30 +0000
110@@ -88,14 +88,15 @@
111 follow_name_owner_changes=True)
112 sso_backend = dbus.Interface(obj, dbus_interface=iface)
113 sso_backend.find_credentials(APP_NAME, {})
114-
115 except ImportError:
116 logging.info('Ubuntu SSO is not available.')
117
118
119 def plugin_init():
120 """Set up the signal handler for pairing with Ubuntu One."""
121+ logging.info('Loaded Ubuntu One extension for desktopcouch.')
122 if sys.platform == 'win32':
123 logging.warning('Windows support for Ubuntu One is not yet ready.')
124 else:
125- listen_to_dbus()
126+ import gobject
127+ gobject.idle_add(listen_to_dbus)
128
129=== modified file 'desktopcouch/application/service.py'
130--- desktopcouch/application/service.py 2010-11-26 23:11:50 +0000
131+++ desktopcouch/application/service.py 2011-01-05 15:54:30 +0000
132@@ -35,7 +35,6 @@
133 """
134
135 import os
136-import pkg_resources
137 import time
138 import logging
139 import logging.handlers
140@@ -46,8 +45,7 @@
141 from desktopcouch.application import stop_local_couchdb
142 from desktopcouch.application.platform import (
143 PortAdvertiser, find_pid, direct_access_find_port, CACHE_HOME)
144-
145-MAIN_START_EXTENSION_ENTRY_POINT = "desktopcouch.service.start"
146+from desktopcouch.application.plugins import load_plugins
147
148
149 def set_up_logging(name):
150@@ -84,7 +82,7 @@
151 stop_couchdb=stop_local_couchdb.stop_couchdb,
152 replication_actions=replication,
153 advertiser_factory=PortAdvertiser, set_logging=set_up_logging,
154- resources=pkg_resources, fork=os.fork, nice=os.nice,
155+ fork=os.fork, nice=os.nice,
156 kill=os.kill, sleep=time.sleep):
157 self._mainloop = main_loop
158 self._pid_finder = pid_finder
159@@ -94,7 +92,6 @@
160 self._replication = replication_actions
161 self._advertiser_factory = advertiser_factory
162 self._logging = set_logging
163- self._resources = resources
164 self._fork = fork
165 self._nice = nice
166 self._kill = kill
167@@ -118,11 +115,7 @@
168 self._advertiser_factory(self._mainloop.stop, self._ctx)
169 logging.debug("starting dbus main loop")
170 try:
171- # we execute the extensions that have been registered
172- for entrypoint in self._resources.iter_entry_points(
173- group=MAIN_START_EXTENSION_ENTRY_POINT):
174- plugin = entrypoint.load()
175- plugin.execute()
176+ load_plugins()
177 self._mainloop.run()
178 finally:
179 logging.debug("ending dbus main loop")
180
181=== modified file 'desktopcouch/application/tests/test_service.py'
182--- desktopcouch/application/tests/test_service.py 2010-11-24 19:55:53 +0000
183+++ desktopcouch/application/tests/test_service.py 2011-01-05 15:54:30 +0000
184@@ -6,7 +6,7 @@
185 from mocker import MockerTestCase, ANY
186
187 from desktopcouch.application.service import (
188- DesktopcouchService, MAIN_START_EXTENSION_ENTRY_POINT)
189+ DesktopcouchService)
190
191 logging.basicConfig(level=logging.ERROR)
192
193@@ -36,7 +36,6 @@
194 self._replication = self.mocker.mock()
195 self._advertiser = self.mocker.mock()
196 self._resources = self.mocker.mock()
197- self._start_extension = self.mocker.mock()
198 self._service = DesktopcouchService(self._mainloop,
199 pid_finder=self._pid_finder,
200 port_finder=self._port_finder,
201@@ -48,8 +47,7 @@
202 fork=self._fork,
203 nice=self._nice,
204 kill=self._kill,
205- sleep=self._sleep,
206- resources=self._resources)
207+ sleep=self._sleep)
208
209 def test_start_new_desktopcouch_no_extensions(self):
210 """Test that desktopcouch is started.
211@@ -70,9 +68,6 @@
212 self._mainloop.stop # pylint: disable=W0104
213 self.mocker.result(ANY)
214 self._advertiser(ANY, self._ctx)
215- self._resources.iter_entry_points(
216- group=MAIN_START_EXTENSION_ENTRY_POINT)
217- self.mocker.result([])
218 self._mainloop.run()
219 self._stop_couchdb(ctx=self._ctx)
220 self._kill(234, signal.SIGTERM)
221@@ -100,12 +95,6 @@
222 self._mainloop.stop # pylint: disable=W0104
223 self.mocker.result(ANY)
224 self._advertiser(ANY, self._ctx)
225- self._resources.iter_entry_points(
226- group=MAIN_START_EXTENSION_ENTRY_POINT)
227- self.mocker.result([self._start_extension])
228- self._start_extension.load()
229- self.mocker.result(self._start_extension)
230- self._start_extension.execute()
231 self._mainloop.run()
232 self._stop_couchdb(ctx=self._ctx)
233 self._kill(234, signal.SIGTERM)

Subscribers

People subscribed via source and target branches