Merge lp:~zeitgeist/zeitgeist/find.applications into lp:zeitgeist/0.1

Proposed by Siegfried Gevatter
Status: Merged
Approved by: Siegfried Gevatter
Approved revision: 1021
Merged at revision: not available
Proposed branch: lp:~zeitgeist/zeitgeist/find.applications
Merge into: lp:zeitgeist/0.1
Diff against target: None lines
To merge this branch: bzr merge lp:~zeitgeist/zeitgeist/find.applications
Reviewer Review Type Date Requested Status
Markus Korn Approve
Seif Lotfy Pending
Zeitgeist Framework Team Pending
Review via email: mp+8707@code.launchpad.net

Commit message

Merge with trunk and address Markus Korn's comment about a wrong docstring.

To post a comment you must log in.
Revision history for this message
Markus Korn (thekorn) wrote :

docstring of FindApplications is not correct:
 """:rtype: list of tuples presenting an :ref:`item-label`"""
in fact it is a list of tuples containing the .desktop file and some counter

Apart from that, ACK, good work

review: Needs Fixing
1021. By Siegfried Gevatter

Merge with trunk and address Markus Korn's comment about a wrong docstring.

Revision history for this message
Markus Korn (thekorn) wrote :

full ACK with after the docstring change

review: Approve
Revision history for this message
Siegfried Gevatter (rainct) wrote :

text conflict in _zeitgeist/engine/engine.py
text conflict in _zeitgeist/engine/remote.py

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '_zeitgeist/engine/engine.py'
--- _zeitgeist/engine/engine.py 2009-07-11 23:20:37 +0000
+++ _zeitgeist/engine/engine.py 2009-07-13 18:00:06 +0000
@@ -276,7 +276,7 @@
276 return self._format_result(item)276 return self._format_result(item)
277 277
278 def find_events(self, min=0, max=sys.maxint, limit=0,278 def find_events(self, min=0, max=sys.maxint, limit=0,
279 sorting_asc=True, mode="event", filters=(), only_count=False):279 sorting_asc=True, mode="event", filters=(), return_mode=0):
280 """280 """
281 Returns all items from the database between the indicated281 Returns all items from the database between the indicated
282 timestamps `min' and `max'. Optionally the argument `tags'282 timestamps `min' and `max'. Optionally the argument `tags'
@@ -296,6 +296,12 @@
296 between diferent structs it is OR-like (only the conditions296 between diferent structs it is OR-like (only the conditions
297 described in one of the structs need to match for the item to297 described in one of the structs need to match for the item to
298 be returned).298 be returned).
299
300 Possible values for return_mode, which is an internal variable
301 not exposed in the API:
302 - 0: Return the events/items.
303 - 1: Return the amount of events/items which would be returned.
304 - 2: Return only the applications for the matching events.
299 """305 """
300 306
301 time1 = time.time()307 time1 = time.time()
@@ -379,7 +385,11 @@
379 preexpressions += ", MAX(event.start)"385 preexpressions += ", MAX(event.start)"
380 expressions += " GROUP BY event.subject_id"386 expressions += " GROUP BY event.subject_id"
381 if mode == "mostused":387 if mode == "mostused":
382 additional_orderby = "COUNT(event.rowid) DESC,"388 additional_orderby += " COUNT(event.rowid) DESC,"
389 elif return_mode == 2:
390 preexpressions += " , COUNT(event.app_id) AS app_count"
391 expressions += " GROUP BY event.app_id"
392 additional_orderby += " app_count DESC,"
383 393
384 args = [ Content.BOOKMARK.id, Content.TAG.id, min, max ]394 args = [ Content.BOOKMARK.id, Content.TAG.id, min, max ]
385 args += additional_args395 args += additional_args
@@ -415,17 +425,19 @@
415 """ % (preexpressions, expressions, additional_orderby,425 """ % (preexpressions, expressions, additional_orderby,
416 "ASC" if sorting_asc else "DESC"), args).get_all()426 "ASC" if sorting_asc else "DESC"), args).get_all()
417 427
418 if not only_count:428 if return_mode == 0:
419 result = [self._format_result(event) for event in events]429 result = [self._format_result(event) for event in events]
420 430
421 time2 = time.time()431 time2 = time.time()
422 log.debug("Fetched %s items in %.5f s." % (len(result), time2 - time1))432 log.debug("Fetched %s items in %.5f s." % (len(result), time2 - time1))
423 else:433 elif return_mode == 1:
424 # We could change the query above to "SELECT COUNT(*) FROM (...)",434 # We could change the query above to "SELECT COUNT(*) FROM (...)",
425 # where "..." is the complete query converted into a temporary435 # where "..." is the complete query converted into a temporary
426 # table, and get the result directly but there isn't enough of436 # table, and get the result directly but there isn't enough of
427 # a speed gain in doing that as that it'd be worth doing.437 # a speed gain in doing that as that it'd be worth doing.
428 result = len(events)438 result = len(events)
439 elif return_mode == 2:
440 return [(event[10], event[13]) for event in events]
429 441
430 return result442 return result
431 443
432444
=== modified file '_zeitgeist/engine/remote.py'
--- _zeitgeist/engine/remote.py 2009-07-11 23:20:37 +0000
+++ _zeitgeist/engine/remote.py 2009-07-13 18:00:06 +0000
@@ -85,7 +85,27 @@
85 # content: <str>85 # content: <str>
86 # bookmarked: <bool> (True means bookmarked items, and vice versa86 # bookmarked: <bool> (True means bookmarked items, and vice versa
87 return _engine.find_events(min_timestamp, max_timestamp, limit,87 return _engine.find_events(min_timestamp, max_timestamp, limit,
88 sorting_asc, mode, filters, False)88 sorting_asc, mode, filters, return_mode=0)
89
90 @dbus.service.method("org.gnome.zeitgeist",
91 in_signature="iiaa{sv}", out_signature="a(si)")
92 def FindApplications(self, min_timestamp, max_timestamp, filters):
93 """This method takes a subset of the parameters from ``FindEvents()``
94 and returns the path to the .desktop file of the applications which
95 were used for the matching events.
96
97 :param min_timestamp: search for application beginning after this timestamp
98 :type min_timestamp: integer
99 :param max_timestamp: search for applications beginning before this timestamp;
100 ``max_timestamp`` equals ``0`` means indefinite time
101 :type max_timestamp: integer
102 :param filters: list of filter, multiple filters are connected by an ``OR`` condition
103 :type filters: list of tuples presenting a :ref:`filter-label`
104 :returns: list of items
105 :rtype: list of tuples presenting an :ref:`item-label`
106 """
107 return _engine.find_events(min_timestamp, max_timestamp, 0, True,
108 u"event", filters, return_mode=2)
89 109
90 @dbus.service.method("org.gnome.zeitgeist",110 @dbus.service.method("org.gnome.zeitgeist",
91 in_signature="iisaa{sv}", out_signature="i")111 in_signature="iisaa{sv}", out_signature="i")
@@ -109,7 +129,7 @@
109 :rtype: list of tuples presenting an :ref:`item-label`129 :rtype: list of tuples presenting an :ref:`item-label`
110 """130 """
111 return _engine.find_events(min_timestamp, max_timestamp, 0, True,131 return _engine.find_events(min_timestamp, max_timestamp, 0, True,
112 mode, filters, True)132 mode, filters, return_mode=1)
113 133
114 @dbus.service.method("org.gnome.zeitgeist",134 @dbus.service.method("org.gnome.zeitgeist",
115 in_signature="siii", out_signature="a(si)")135 in_signature="siii", out_signature="a(si)")
116136
=== modified file 'test/engine-engine-test.py'
--- test/engine-engine-test.py 2009-07-11 23:20:37 +0000
+++ test/engine-engine-test.py 2009-07-13 18:00:06 +0000
@@ -419,11 +419,33 @@
419 [{"content": [Content.IMAGE.uri]}], True)419 [{"content": [Content.IMAGE.uri]}], True)
420 self.assertEquals(result, 3)420 self.assertEquals(result, 3)
421 421
422 def testFindApplications(self):
423 self._init_with_various_events()
424 result = self.engine.find_events(0, 0, 0, True, u"event", [],
425 return_mode=2)
426 self.assertEquals(result, [(u"/usr/share/applications/eog.desktop", 3),
427 (u"/usr/share/applications/firefox.desktop", 2)])
428
429 def testFindApplications(self):
430 self._init_with_various_events()
431 result = self.engine.find_events(0, 0, 0, True, u"event",
432 [], return_mode=2)
433 self.assertEquals(result, [(u"/usr/share/applications/eog.desktop", 3),
434 (u"/usr/share/applications/firefox.desktop", 2)])
435
436 def testFindApplicationsTimestampMimetypeTags(self):
437 self._init_with_various_events()
438 result = self.engine.find_events(1219325, 4563533, 0, True, u"event",
439 [{"mimetypes": [u"image/png"], "tags": [u"examples"]}],
440 return_mode=2)
441 self.assertEquals(result, [(u"/usr/share/applications/eog.desktop", 1),
442 (u"/usr/share/applications/firefox.desktop", 1)])
443
422 def testGetTagsNameFilter(self):444 def testGetTagsNameFilter(self):
423 self._init_with_various_events()445 self._init_with_various_events()
424 result = self.engine.get_tags(u"f%")446 result = self.engine.get_tags(u"f%")
425 self.assertEquals(result, [(u'filtertest', 1),447 self.assertEquals(result, [(u"filtertest", 1),
426 (u'files', 1)])448 (u"files", 1)])
427 449
428 def testGetTagsLimit(self):450 def testGetTagsLimit(self):
429 self._init_with_various_events()451 self._init_with_various_events()

Subscribers

People subscribed via source and target branches