Siegfried Gevatter has proposed merging lp:~zeitgeist/zeitgeist/bug695363 into
lp:zeitgeist.
Requested reviews:
Zeitgeist Framework Team (zeitgeist)
Related bugs:
#695363 Python API doesn't expose DataSourceRegistry's enabled status
https://bugs.launchpad.net/bugs/695363
For more details, see:
https://code.launchpad.net/~zeitgeist/zeitgeist/bug695363/+merge/48950
Expose DataSourceRegistry's enabled status and callback in the Python API.
--
https://code.launchpad.net/~zeitgeist/zeitgeist/bug695363/+merge/48950
Your team Zeitgeist Framework Team is requested to review the proposed merge of
lp:~zeitgeist/zeitgeist/bug695363 into lp:zeitgeist.
=== modified file 'test/remote-test.py'
--- test/remote-test.py 2010-12-29 15:31:26 +
+++ test/remote-test.py 2011-02-08 17:24:45 +
@@ -447,6 +447,9 @@
self.assertEquals(len(datasources), 1)
self._assertDataSourceEquals(datasources[0], self._ds2)
+ def testRegisterDataSourceWithCallback(self):
+ self.client.register_data_source(*self._ds1, enabled_callback=lambda x: True)
+
def testRegisterDataSources(self):
# Insert two data-sources
self.client._registry.RegisterDataSource(*self._ds1)
@@ -485,8 +488,21 @@
ds = list(self.client._registry.GetDataSources())[0]
self.assertEquals(ds[DataSource.Enabled], True)
+ def _create_mainloop(self):
+ mainloop = gobject.MainLoop()
+
+ def cb_timeout():
+ mainloop.quit()
+ self.fail("Timed out -- operations not completed in reasonable time.")
+
+ # Add an arbitrary timeout so this test won't block if it fails
+ gobject.timeout_add_seconds(30, cb_timeout)
+
+ return mainloop
+
def testDataSourceSignals(self):
- mainloop = gobject.MainLoop()
+ mainloop = self._create_mainloop()
+
global hit
hit = 0
@@ -514,10 +530,6 @@
# self.assertEquals(hit, 3)
# mainloop.quit()
- def cb_timeout():
- mainloop.quit()
- self.fail("Timed out -- operations not completed in 1 minute.")
-
# Connect to signals
self.client._registry.connect('DataSourceRegistered', cb_registered)
self.client._registry.connect('DataSourceEnabled', cb_enabled)
@@ -526,11 +538,40 @@
# Register data-source, disable it, enable it again
gobject.idle_add(self.testSetDataSourceEnabled)
- # Add an arbitrary timeout so this test won't block if it fails
- gobject.timeout_add_seconds(30, cb_timeout)
-
- mainloop.run()
-
+ mainloop.run()
+
+ def testRegisterDataSourceEnabledCallbackOnRegister(self):
+ mainloop = self._create_mainloop()
+
+ def callback(enabled):
+ mainloop.quit()
+ self.client.register_data_source(*self._ds1, enabled_callback=callback)
+
+ mainloop.run()
+
+ def testRegisterDataSourceEnabledCallbackOnChange(self):
+ mainloop = self._create_mainloop()
+ global hit
+ hit = 0
+
+ # Register a callback
+ def callback(enabled):
+ global hit
+ if hit == 0:
+# Register callback
+hit = 1
+ elif hit == 1:
+# Disable callback
+mainloop.quit()
+ else:
+self.fail("Unexpected number of signals: %d." % hit)
+ self.client.register_data_source(*self._ds1)
+ self.client.set_data_source_enabled_callback(self._ds1[0], callback)
+
+ # Disable the data-source
+ self.client._registry.SetDataSourceEnabled(self._ds1[0], False)
+
+ mainloop.run()
class ZeitgeistRemotePropertiesTest(testutils.RemoteTestCase):
=== modified file 'zeitgeist/client.py'
--- zeitgeist/client.py 2011-02-08 12:54:20 +
+++ zeitgeist/client.py 2011-02-08 17:24:45 +
@@ -2,7 +2,7 @@
# Zeitgeist
#
-# Copyright © 2009-2010 Siegfried-Angel Gevatter Pujals
+# Copyright © 2009-2011 Siegfried-Angel Gevatter Pujals
# Copyright © 2009 Mikkel Kamstrup Erlandsen
# Copyright © 2009 Markus Korn
#
@@ -876,7 +876,12 @@
reply_handler=reply_handler,
error_handler=error_handler)
- def register_data_source(self, unique_id, name, description, event_templates):
+ # Data-source related class variables
+ _data_sources = {}
+ _data_sources_callback_installed = False
+
+ def register_data_source(self, unique_id, name, description,
+ event_templates, enabled_callback=None):
"""
Register a data-source as currently running. If the data-source was
already in the database, its metadata (name, description and
@@ -893,13 +898,58 @@
:param description: data-source description (may be translated)
:param event_templates: list of
:class:`Event ` templates.
+ :param enabled_callback: method to call as response with the `enabled'
+ status of the data-source, and after that every time said status
+ is toggled. See set_data_source_enabled_callback() for more
+ information.
"""
- # TODO: Make it possible to access the return value!
+
+ self._data_sources[unique_id] = {'enabled': None, 'callback': None}
+
+ if enabled_callback is not None:
+ self.set_data_source_enabled_callback(unique_id, enabled_callback)
+
+ def _data_source_enabled_cb(unique_id, enabled):
+ i