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
1=== modified file '_zeitgeist/engine/engine.py'
2--- _zeitgeist/engine/engine.py 2009-07-11 23:20:37 +0000
3+++ _zeitgeist/engine/engine.py 2009-07-13 18:00:06 +0000
4@@ -276,7 +276,7 @@
5 return self._format_result(item)
6
7 def find_events(self, min=0, max=sys.maxint, limit=0,
8- sorting_asc=True, mode="event", filters=(), only_count=False):
9+ sorting_asc=True, mode="event", filters=(), return_mode=0):
10 """
11 Returns all items from the database between the indicated
12 timestamps `min' and `max'. Optionally the argument `tags'
13@@ -296,6 +296,12 @@
14 between diferent structs it is OR-like (only the conditions
15 described in one of the structs need to match for the item to
16 be returned).
17+
18+ Possible values for return_mode, which is an internal variable
19+ not exposed in the API:
20+ - 0: Return the events/items.
21+ - 1: Return the amount of events/items which would be returned.
22+ - 2: Return only the applications for the matching events.
23 """
24
25 time1 = time.time()
26@@ -379,7 +385,11 @@
27 preexpressions += ", MAX(event.start)"
28 expressions += " GROUP BY event.subject_id"
29 if mode == "mostused":
30- additional_orderby = "COUNT(event.rowid) DESC,"
31+ additional_orderby += " COUNT(event.rowid) DESC,"
32+ elif return_mode == 2:
33+ preexpressions += " , COUNT(event.app_id) AS app_count"
34+ expressions += " GROUP BY event.app_id"
35+ additional_orderby += " app_count DESC,"
36
37 args = [ Content.BOOKMARK.id, Content.TAG.id, min, max ]
38 args += additional_args
39@@ -415,17 +425,19 @@
40 """ % (preexpressions, expressions, additional_orderby,
41 "ASC" if sorting_asc else "DESC"), args).get_all()
42
43- if not only_count:
44+ if return_mode == 0:
45 result = [self._format_result(event) for event in events]
46
47 time2 = time.time()
48 log.debug("Fetched %s items in %.5f s." % (len(result), time2 - time1))
49- else:
50+ elif return_mode == 1:
51 # We could change the query above to "SELECT COUNT(*) FROM (...)",
52 # where "..." is the complete query converted into a temporary
53 # table, and get the result directly but there isn't enough of
54 # a speed gain in doing that as that it'd be worth doing.
55 result = len(events)
56+ elif return_mode == 2:
57+ return [(event[10], event[13]) for event in events]
58
59 return result
60
61
62=== modified file '_zeitgeist/engine/remote.py'
63--- _zeitgeist/engine/remote.py 2009-07-11 23:20:37 +0000
64+++ _zeitgeist/engine/remote.py 2009-07-13 18:00:06 +0000
65@@ -85,7 +85,27 @@
66 # content: <str>
67 # bookmarked: <bool> (True means bookmarked items, and vice versa
68 return _engine.find_events(min_timestamp, max_timestamp, limit,
69- sorting_asc, mode, filters, False)
70+ sorting_asc, mode, filters, return_mode=0)
71+
72+ @dbus.service.method("org.gnome.zeitgeist",
73+ in_signature="iiaa{sv}", out_signature="a(si)")
74+ def FindApplications(self, min_timestamp, max_timestamp, filters):
75+ """This method takes a subset of the parameters from ``FindEvents()``
76+ and returns the path to the .desktop file of the applications which
77+ were used for the matching events.
78+
79+ :param min_timestamp: search for application beginning after this timestamp
80+ :type min_timestamp: integer
81+ :param max_timestamp: search for applications beginning before this timestamp;
82+ ``max_timestamp`` equals ``0`` means indefinite time
83+ :type max_timestamp: integer
84+ :param filters: list of filter, multiple filters are connected by an ``OR`` condition
85+ :type filters: list of tuples presenting a :ref:`filter-label`
86+ :returns: list of items
87+ :rtype: list of tuples presenting an :ref:`item-label`
88+ """
89+ return _engine.find_events(min_timestamp, max_timestamp, 0, True,
90+ u"event", filters, return_mode=2)
91
92 @dbus.service.method("org.gnome.zeitgeist",
93 in_signature="iisaa{sv}", out_signature="i")
94@@ -109,7 +129,7 @@
95 :rtype: list of tuples presenting an :ref:`item-label`
96 """
97 return _engine.find_events(min_timestamp, max_timestamp, 0, True,
98- mode, filters, True)
99+ mode, filters, return_mode=1)
100
101 @dbus.service.method("org.gnome.zeitgeist",
102 in_signature="siii", out_signature="a(si)")
103
104=== modified file 'test/engine-engine-test.py'
105--- test/engine-engine-test.py 2009-07-11 23:20:37 +0000
106+++ test/engine-engine-test.py 2009-07-13 18:00:06 +0000
107@@ -419,11 +419,33 @@
108 [{"content": [Content.IMAGE.uri]}], True)
109 self.assertEquals(result, 3)
110
111+ def testFindApplications(self):
112+ self._init_with_various_events()
113+ result = self.engine.find_events(0, 0, 0, True, u"event", [],
114+ return_mode=2)
115+ self.assertEquals(result, [(u"/usr/share/applications/eog.desktop", 3),
116+ (u"/usr/share/applications/firefox.desktop", 2)])
117+
118+ def testFindApplications(self):
119+ self._init_with_various_events()
120+ result = self.engine.find_events(0, 0, 0, True, u"event",
121+ [], return_mode=2)
122+ self.assertEquals(result, [(u"/usr/share/applications/eog.desktop", 3),
123+ (u"/usr/share/applications/firefox.desktop", 2)])
124+
125+ def testFindApplicationsTimestampMimetypeTags(self):
126+ self._init_with_various_events()
127+ result = self.engine.find_events(1219325, 4563533, 0, True, u"event",
128+ [{"mimetypes": [u"image/png"], "tags": [u"examples"]}],
129+ return_mode=2)
130+ self.assertEquals(result, [(u"/usr/share/applications/eog.desktop", 1),
131+ (u"/usr/share/applications/firefox.desktop", 1)])
132+
133 def testGetTagsNameFilter(self):
134 self._init_with_various_events()
135 result = self.engine.get_tags(u"f%")
136- self.assertEquals(result, [(u'filtertest', 1),
137- (u'files', 1)])
138+ self.assertEquals(result, [(u"filtertest", 1),
139+ (u"files", 1)])
140
141 def testGetTagsLimit(self):
142 self._init_with_various_events()

Subscribers

People subscribed via source and target branches