Merge lp:~jplacerda/zeitgeist/691690 into lp:zeitgeist/0.1

Proposed by J.P. Lacerda
Status: Merged
Merged at revision: 1759
Proposed branch: lp:~jplacerda/zeitgeist/691690
Merge into: lp:zeitgeist/0.1
Diff against target: 101 lines (+40/-5)
2 files modified
_zeitgeist/engine/extensions/datasource_registry.py (+26/-3)
test/remote-test.py (+14/-2)
To merge this branch: bzr merge lp:~jplacerda/zeitgeist/691690
Reviewer Review Type Date Requested Status
Manish Sinha (मनीष सिन्हा) Needs Information
Seif Lotfy Pending
Review via email: mp+60502@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Siegfried Gevatter (rainct) wrote :

Looks good!

Can you please document GetDataSourceFromId like the other methods, though? (Ie. with description, :param, :type, :returns, :rtype; the documentation is automatically generated from that).

lp:~jplacerda/zeitgeist/691690 updated
1759. By J.P. Lacerda <email address hidden>

Add a method to the data-source registry to retrieve
the information for a particular data-source from its ID.

Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

This will break the API again in 0.8.1 ?

Should I wait for 0.8.1 and release zeitgeist-sharp or go ahead?

review: Needs Information
Revision history for this message
Manish Sinha (मनीष सिन्हा) (manishsinha) wrote :

Sorry I meant ABI

Revision history for this message
Seif Lotfy (seif) wrote :

release 0.8 then we release 0.8.1

2011/5/11 Manish Sinha (मनीष सिन्हा <email address hidden>

> Sorry I meant ABI
> --
> https://code.launchpad.net/~jplacerda/zeitgeist/691690/+merge/60502
> You are requested to review the proposed merge of
> lp:~jplacerda/zeitgeist/691690 into lp:zeitgeist.
>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_zeitgeist/engine/extensions/datasource_registry.py'
2--- _zeitgeist/engine/extensions/datasource_registry.py 2011-04-27 18:55:33 +0000
3+++ _zeitgeist/engine/extensions/datasource_registry.py 2011-05-11 08:53:32 +0000
4@@ -66,7 +66,7 @@
5 :const:`org.gnome.zeitgeist.DataSourceRegistry`.
6 """
7 PUBLIC_METHODS = ["register_data_source", "get_data_sources",
8- "set_data_source_enabled"]
9+ "set_data_source_enabled", "get_data_source_from_id"]
10
11 def __init__ (self, engine):
12
13@@ -125,7 +125,7 @@
14
15 def unload(self):
16 self._write_to_disk()
17-
18+
19 # PUBLIC
20 def register_data_source(self, unique_id, name, description, templates):
21 source = DataSource(str(unique_id), unicode(name), unicode(description),
22@@ -152,7 +152,14 @@
23 datasource.enabled = enabled
24 self.DataSourceEnabled(datasource.unique_id, enabled)
25 return True
26-
27+
28+ # PUBLIC
29+ def get_data_source_from_id(self, unique_id):
30+ if unique_id in self._registry:
31+ return self._registry[unique_id]
32+ else:
33+ raise KeyError("DataSource not found: %s" % unique_id)
34+
35 @dbus.service.method(REGISTRY_DBUS_INTERFACE,
36 in_signature="sssa("+constants.SIG_EVENT+")",
37 out_signature="b",
38@@ -211,6 +218,22 @@
39 """
40 self.set_data_source_enabled(unique_id, enabled)
41
42+ @dbus.service.method(REGISTRY_DBUS_INTERFACE,
43+ in_signature="s",
44+ out_signature=SIG_FULL_DATASOURCE,
45+ sender_keyword="sender")
46+ def GetDataSourceFromId(self, unique_id, sender):
47+ """
48+ Get a specific data-source from its unique id.
49+ If no data-source has been registered to the specified unique
50+ id, a KeyError is raised.
51+
52+ :param unique_id: unique string identifying a data-source
53+ :type unique_id: string
54+ :returns: class:`DataSource <zeitgeist.datamodel.DataSource>` object
55+ """
56+ return self.get_data_source_from_id(unique_id)
57+
58 @dbus.service.signal(REGISTRY_DBUS_INTERFACE,
59 signature="sb")
60 def DataSourceEnabled(self, value, enabled):
61
62=== modified file 'test/remote-test.py'
63--- test/remote-test.py 2011-05-07 12:48:06 +0000
64+++ test/remote-test.py 2011-05-11 08:53:32 +0000
65@@ -16,6 +16,7 @@
66 import gobject
67 from dbus.mainloop.glib import DBusGMainLoop
68 DBusGMainLoop(set_as_default=True)
69+from dbus.exceptions import DBusException
70
71 # Import local Zeitgeist modules
72 sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
73@@ -481,7 +482,18 @@
74 self.client._registry.SetDataSourceEnabled(self._ds1[0], True)
75 ds = list(self.client._registry.GetDataSources())[0]
76 self.assertEquals(ds[DataSource.Enabled], True)
77-
78+
79+ def testGetDataSourceFromId(self):
80+ # Insert a data-source -- and then retrieve it by id
81+ self.client._registry.RegisterDataSource(*self._ds1)
82+ ds = self.client._registry.GetDataSourceFromId(self._ds1[0])
83+ self._assertDataSourceEquals(ds, self._ds1)
84+
85+ # Retrieve a data-source from an id that has not been registered
86+ self.assertRaises(DBusException,
87+ self.client._registry.GetDataSourceFromId,
88+ self._ds2[0])
89+
90 def testDataSourceSignals(self):
91 mainloop = self.create_mainloop()
92
93@@ -552,7 +564,7 @@
94
95 # Disable the data-source
96 self.client._registry.SetDataSourceEnabled(self._ds1[0], False)
97-
98+
99 mainloop.run()
100
101 class ZeitgeistRemotePropertiesTest(testutils.RemoteTestCase):