Merge lp:~manishsinha/cheers/fixed-award-unaward-trophy into lp:cheers

Status: Merged
Merged at revision: 26
Proposed branch: lp:~manishsinha/cheers/fixed-award-unaward-trophy
Merge into: lp:cheers
Diff against target: 271 lines (+97/-26)
7 files modified
LICENSE (+2/-1)
MAINTAINERS (+1/-1)
README (+12/-5)
cheers/config.py (+9/-0)
cheers/datastore.py (+35/-9)
cheers/logic.py (+3/-4)
cheers/server.py (+35/-6)
To merge this branch: bzr merge lp:~manishsinha/cheers/fixed-award-unaward-trophy
Reviewer Review Type Date Requested Status
Cheers Pending
Review via email: mp+54276@code.launchpad.net

Commit message

Fixed the UnawardTrophy and AwardTrophy functionality

* Implemented the AwardTrophy method
* Implement the UnawardTrophy method
* Updated the Copyright headers

Description of the change

Test out this branch
=====================
Start the daemon using
./cheers-daemon

Throw the file samples/valid.trophy under ~/.local/share/cheers/trophies

It should get picked up.

Open D-feet and search for com.cheersproject.cheers

Call GetTrophies() -- that trophy shpold show up. get it's id should be u'some-id-for-trophy'
call the method GetAwardedTrophies() - nothing should come

Try the method AwardTrophy() and pass this - u'some-id-for-trophy'
It should work without any issues

Now call the method GetAwardedTrophies() -- that trophy should show up

Now call UnawardTerophy() with u'some-id-for-trophy' -- it should work without any errors

now call GetAwardedTrophies() - nothing should show up

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'LICENSE'
2--- LICENSE 2010-11-04 20:47:04 +0000
3+++ LICENSE 2011-03-21 21:25:51 +0000
4@@ -1,6 +1,7 @@
5 # The MIT/X11/Expat License
6
7-# Copyright (c) 2010 Manish Sinha<mail@manishsinha.net>
8+# Copyright (c) 2010 Manish Sinha <manishsinha@ubuntu.com>
9+# Copyright (c) 2010 Seif Lotfy <seif@lotfy.com>
10
11 # Permission is hereby granted, free of charge, to any person obtaining a copy
12 # of this software and associated documentation files (the "Software"), to deal
13
14=== modified file 'MAINTAINERS'
15--- MAINTAINERS 2010-11-04 20:47:04 +0000
16+++ MAINTAINERS 2011-03-21 21:25:51 +0000
17@@ -1,1 +1,1 @@
18-Manish Sinha <mail@manishsinha.net>
19+Manish Sinha <manishsinha@ubuntu.com>
20
21=== modified file 'README'
22--- README 2010-11-04 20:47:04 +0000
23+++ README 2011-03-21 21:25:51 +0000
24@@ -1,11 +1,16 @@
25-Cheers is a trophy awarding framework. It runs as a daemon activating a DBus Session bus over which applications can talk to it.
26-The aim of cheers is to have a centralized system where all the trophies can be stored. This removes the reduendency of every application with requirements which sounds like trophjy/medal/badges to have their own implementation.
27+Cheers is a trophy awarding framework. It runs as a daemon activating a
28+DBus Session bus over which applications can talk to it.
29+The aim of cheers is to have a centralized system where all the trophies
30+can be stored. This removes the reduendency of every application with
31+requirements which sounds like trophjy/medal/badges to have their own
32+implementation.
33
34 It is written using python, desktopcouch, dbus
35
36 Prerequisties
37 ---------------
38-To get cheers up and running, you need the following packages. Please check your distribution for the exact name of the packages
39+To get cheers up and running, you need the following packages. Please
40+check your distribution for the exact name of the packages
41 * python
42 * python-dbus
43 * python-gio
44@@ -23,12 +28,14 @@
45 Registering a trophy
46 ---------------------
47
48-Cheers keeps a watch on three folders for new trophies when the server is running. These two folders are
49+Cheers keeps a watch on three folders for new trophies when the server
50+is running. These two folders are
51 * /usr/share/cheers/trophies
52 * /usr/local/share/cheers/trophies
53 * ~/.local/share/cheers/trophies
54
55-A sample trophy aa.trophy is provided. Put it under the folder ~/.local/share/cheers/trophies to register the trophy
56+A sample trophy aa.trophy is provided. Put it under the folder
57+~/.local/share/cheers/trophies to register the trophy
58
59
60 Debugging
61
62=== modified file 'cheers/config.py'
63--- cheers/config.py 2010-11-06 19:29:15 +0000
64+++ cheers/config.py 2011-03-21 21:25:51 +0000
65@@ -35,4 +35,13 @@
66
67 desktopcouch_db = "cheers"
68
69+# s - Id
70+# a(as) - Array of [lang, Title]
71+# a(as) - Array of [lang, Description]
72+# s - The set to which the trophy beldongs
73+# s - The icon for the trophy
74+# s - The stockicon for the Trophy
75+# s - The name of the application
76+# b - Has the trophy been awarded
77+TROPHY_SIG = "saasaasssssb"
78
79
80=== modified file 'cheers/datastore.py'
81--- cheers/datastore.py 2010-11-30 21:22:25 +0000
82+++ cheers/datastore.py 2011-03-21 21:25:51 +0000
83@@ -79,8 +79,8 @@
84 #FIXME: There must be a more elegant way of doing this
85 results = self._get_records("trophies", )
86 for rec in results:
87- if rec["value"].has_key("private_application_annotations") and \
88- rec["value"]["private_application_annotations"]["cheers"]["awarded"]:
89+ annot = CouchRecord(rec.value).application_annotations.get("cheers")
90+ if annot is not None and annot.has_key("awarded") and annot["awarded"]:
91 yield rec["value"]
92
93 def get_sets(self, ids=None):
94@@ -92,23 +92,48 @@
95
96 def delete_trophy(self, id):
97 """ Delete the trophy for the provided id """
98+ records = [rec for rec in self._get_records("trophies", [id])]
99+ if len(records) != 1:
100+ raise KeyError, 'No such trophy registered'
101 for rec in self._get_records("trophies", ids):
102 self.database.delete_record(rec["id"])
103
104 def award_trophies(self, ids):
105 """ Award the trophy with the provided trophy id """
106 #self.database.update_fields(record_id, fields, cached_record)
107- for rec in self._get_records("trophies", ids):
108- if rec["value"].has_key("private_application_annotations"):
109- rec["value"]["private_application_annotations"]["cheers"]["awarded"] = True
110+ records = [rec for rec in self._get_records("trophies", ids)]
111+ if len(records) != len(ids):
112+ raise KeyError, 'No such trophy registered'
113+ awarded = []
114+ for rec in records:
115+ record = CouchRecord(rec.value).application_annotations
116+ annot = record.get("cheers")
117+ if annot is not None and annot.has_key("awarded"):
118+ annot["awarded"] = True
119+ awarded.append(rec)
120+ elif annot is None:
121+ record.setdefault("cheers", {})["awarded"] = True
122+ awarded.append(rec)
123+
124 self.database.update_fields(rec["id"], rec["value"])
125+
126+ return awarded
127
128 def unaward_trophies(self, ids):
129 """ Unaward the trophy with the provided trophy id """
130- for rec in self._get_records("trophies", ids):
131- if rec["value"].has_key("private_application_annotations"):
132- rec["value"]["private_application_annotations"]["cheers"]["awarded"] = False
133- self.database.update_fields(rec["id"], rec["value"])
134+ print "unawarding", ids
135+ records = [rec for rec in self._get_records("trophies", ids)]
136+ if len(records) != len(ids):
137+ raise KeyError, 'No such trophy registered'
138+ unawarded = []
139+ for rec in records:
140+ annot = CouchRecord(rec.value).application_annotations.get("cheers")
141+ if annot is not None and annot.has_key("awarded"):
142+ annot["awarded"] = False
143+ unawarded.append(rec)
144+ self.database.update_fields(rec["id"], rec["value"])
145+
146+ return unawarded
147
148 def get_trophies_by_app(self, appname):
149 """ Get all the trophies associated with a particular application """
150@@ -122,3 +147,4 @@
151 if trophy.has_key("trophyset") and trophy["trophyset"] == setname:
152 yield trophy
153
154+
155
156=== modified file 'cheers/logic.py'
157--- cheers/logic.py 2010-11-30 21:22:25 +0000
158+++ cheers/logic.py 2011-03-21 21:25:51 +0000
159@@ -135,18 +135,17 @@
160 """ Get all the trophy sets in cheers """
161 return [i for i in self.__store.get_sets()]
162
163-
164 def delete_trophy(self, id):
165 """ Delete the trophy for the provided id """
166- pass
167+ self.__store.delete_trophy([id]);
168
169 def award_trophy(self, id):
170 """ Award the trophy with the provided trophy id """
171- pass
172+ return self.__store.award_trophies([id]);
173
174 def unaward_trophy(self, id):
175 """ Unaward the trophy with the provided trophy id """
176- pass
177+ return self.__store.unaward_trophies([id]);
178
179 def get_trophies_by_app(self, appname):
180 """ Get all the trophies associated with a particular application """
181
182=== modified file 'cheers/server.py'
183--- cheers/server.py 2010-11-30 21:22:25 +0000
184+++ cheers/server.py 2011-03-21 21:25:51 +0000
185@@ -51,10 +51,9 @@
186 and the connection to the datstore is closed """
187
188 print("Requested to stop the bus")
189- #self.__store.Quit()
190 os._exit(0)
191
192- @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a(saasaasssssb)')
193+ @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a('+config.TROPHY_SIG+')')
194 def GetTrophies(self):
195 """ Get the list of all the trophies registered in cheers """
196
197@@ -65,13 +64,13 @@
198 """ Get the list of all the trophy sets available in cheers """
199 return self.logic.get_sets()
200
201- @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a(saasaasssssb)')
202+ @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a('+config.TROPHY_SIG+')')
203 def GetAwardedTrophies(self):
204 """ Get the list of all the awarded trophies in cheers """
205
206 return self.logic.get_awarded_trophies()
207
208- @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='saasaasssssb')
209+ @dbus.service.method(config.CHEERS_BUS_NAME, out_signature=config.TROPHY_SIG)
210 def GetTrophy(self, id):
211 """ Get the trophy instance when the id is provided """
212
213@@ -83,26 +82,56 @@
214
215 res = self.logic.delete_trophy(id)
216
217+ for trophy in res:
218+ self.TrophyDeleted(trophy)
219+
220 @dbus.service.method(config.CHEERS_BUS_NAME)
221 def AwardTrophy(self, id):
222 """ Award the trophy for the provided trophy id """
223
224 res = self.logic.award_trophy(id)
225
226+ for trophy in res:
227+ self.TrophyAwarded(trophy)
228+
229 @dbus.service.method(config.CHEERS_BUS_NAME)
230 def UnawardTrophy(self, id):
231 """ Unaward the trophy for the provided id """
232
233 res = self.logic.unaward_trophy(id)
234
235- @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a(saasaasssssb)')
236+ for trophy in res:
237+ self.TrophyUnawarded(trophy)
238+
239+ @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a('+config.TROPHY_SIG+')')
240 def GetTrophiesByApp(self, appname):
241 """ Get all the trophies registered for a specific application """
242
243 return self.logic.get_trophies_by_app(appname)
244
245- @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a(saasaasssssb)')
246+ @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a('+config.TROPHY_SIG+')')
247 def GetTrophyBySet(self, setname):
248 """ Get all the trophies registsred for a specific set """
249
250 return self.logic.get_trophies_by_set(setname)
251+
252+ # @dbus.service.signal(config.CHEERS_BUS_NAME, signature=config.TROPHY_SIG)
253+ def TrophyAwarded(self, trophy):
254+ """ An event notifying that the trophy has been awarded """
255+
256+ print("Trophy %s awarded" %(trophy))
257+ return trophy
258+
259+ #@dbus.service.signal(config.CHEERS_BUS_NAME, ignature=config.TROPHY_SIG)
260+ def TrophyUnawarded(self, trophy):
261+ """ An event notifying that the trophy has been unawarded """
262+
263+ print("Trophy %s unawarded" %(trophy))
264+ return trophy
265+
266+ #@dbus.service.signal(config.CHEERS_BUS_NAME, signature=config.TROPHY_SIG)
267+ def TrophyDeleted(self, trophy):
268+ """ An event notifying that the trophy has been deleted """
269+
270+ print("Trophy %s deleted" %(trophy))
271+ return trophy

Subscribers

People subscribed via source and target branches