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
=== modified file 'LICENSE'
--- LICENSE 2010-11-04 20:47:04 +0000
+++ LICENSE 2011-03-21 21:25:51 +0000
@@ -1,6 +1,7 @@
1# The MIT/X11/Expat License1# The MIT/X11/Expat License
22
3# Copyright (c) 2010 Manish Sinha<mail@manishsinha.net>3# Copyright (c) 2010 Manish Sinha <manishsinha@ubuntu.com>
4# Copyright (c) 2010 Seif Lotfy <seif@lotfy.com>
45
5# Permission is hereby granted, free of charge, to any person obtaining a copy6# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to deal7# of this software and associated documentation files (the "Software"), to deal
78
=== modified file 'MAINTAINERS'
--- MAINTAINERS 2010-11-04 20:47:04 +0000
+++ MAINTAINERS 2011-03-21 21:25:51 +0000
@@ -1,1 +1,1 @@
1Manish Sinha <mail@manishsinha.net>1Manish Sinha <manishsinha@ubuntu.com>
22
=== modified file 'README'
--- README 2010-11-04 20:47:04 +0000
+++ README 2011-03-21 21:25:51 +0000
@@ -1,11 +1,16 @@
1Cheers is a trophy awarding framework. It runs as a daemon activating a DBus Session bus over which applications can talk to it.1Cheers is a trophy awarding framework. It runs as a daemon activating a
2The 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.2DBus Session bus over which applications can talk to it.
3The aim of cheers is to have a centralized system where all the trophies
4can be stored. This removes the reduendency of every application with
5requirements which sounds like trophjy/medal/badges to have their own
6implementation.
37
4It is written using python, desktopcouch, dbus8It is written using python, desktopcouch, dbus
59
6Prerequisties10Prerequisties
7---------------11---------------
8To get cheers up and running, you need the following packages. Please check your distribution for the exact name of the packages12To get cheers up and running, you need the following packages. Please
13check your distribution for the exact name of the packages
9* python14* python
10* python-dbus15* python-dbus
11* python-gio16* python-gio
@@ -23,12 +28,14 @@
23Registering a trophy28Registering a trophy
24---------------------29---------------------
2530
26Cheers keeps a watch on three folders for new trophies when the server is running. These two folders are31Cheers keeps a watch on three folders for new trophies when the server
32is running. These two folders are
27* /usr/share/cheers/trophies33* /usr/share/cheers/trophies
28* /usr/local/share/cheers/trophies34* /usr/local/share/cheers/trophies
29* ~/.local/share/cheers/trophies35* ~/.local/share/cheers/trophies
3036
31A sample trophy aa.trophy is provided. Put it under the folder ~/.local/share/cheers/trophies to register the trophy37A sample trophy aa.trophy is provided. Put it under the folder
38~/.local/share/cheers/trophies to register the trophy
3239
3340
34Debugging41Debugging
3542
=== modified file 'cheers/config.py'
--- cheers/config.py 2010-11-06 19:29:15 +0000
+++ cheers/config.py 2011-03-21 21:25:51 +0000
@@ -35,4 +35,13 @@
3535
36desktopcouch_db = "cheers"36desktopcouch_db = "cheers"
3737
38# s - Id
39# a(as) - Array of [lang, Title]
40# a(as) - Array of [lang, Description]
41# s - The set to which the trophy beldongs
42# s - The icon for the trophy
43# s - The stockicon for the Trophy
44# s - The name of the application
45# b - Has the trophy been awarded
46TROPHY_SIG = "saasaasssssb"
3847
3948
=== modified file 'cheers/datastore.py'
--- cheers/datastore.py 2010-11-30 21:22:25 +0000
+++ cheers/datastore.py 2011-03-21 21:25:51 +0000
@@ -79,8 +79,8 @@
79 #FIXME: There must be a more elegant way of doing this79 #FIXME: There must be a more elegant way of doing this
80 results = self._get_records("trophies", )80 results = self._get_records("trophies", )
81 for rec in results:81 for rec in results:
82 if rec["value"].has_key("private_application_annotations") and \82 annot = CouchRecord(rec.value).application_annotations.get("cheers")
83 rec["value"]["private_application_annotations"]["cheers"]["awarded"]:83 if annot is not None and annot.has_key("awarded") and annot["awarded"]:
84 yield rec["value"]84 yield rec["value"]
8585
86 def get_sets(self, ids=None):86 def get_sets(self, ids=None):
@@ -92,23 +92,48 @@
9292
93 def delete_trophy(self, id):93 def delete_trophy(self, id):
94 """ Delete the trophy for the provided id """94 """ Delete the trophy for the provided id """
95 records = [rec for rec in self._get_records("trophies", [id])]
96 if len(records) != 1:
97 raise KeyError, 'No such trophy registered'
95 for rec in self._get_records("trophies", ids):98 for rec in self._get_records("trophies", ids):
96 self.database.delete_record(rec["id"]) 99 self.database.delete_record(rec["id"])
97100
98 def award_trophies(self, ids):101 def award_trophies(self, ids):
99 """ Award the trophy with the provided trophy id """102 """ Award the trophy with the provided trophy id """
100 #self.database.update_fields(record_id, fields, cached_record)103 #self.database.update_fields(record_id, fields, cached_record)
101 for rec in self._get_records("trophies", ids):104 records = [rec for rec in self._get_records("trophies", ids)]
102 if rec["value"].has_key("private_application_annotations"):105 if len(records) != len(ids):
103 rec["value"]["private_application_annotations"]["cheers"]["awarded"] = True 106 raise KeyError, 'No such trophy registered'
107 awarded = []
108 for rec in records:
109 record = CouchRecord(rec.value).application_annotations
110 annot = record.get("cheers")
111 if annot is not None and annot.has_key("awarded"):
112 annot["awarded"] = True
113 awarded.append(rec)
114 elif annot is None:
115 record.setdefault("cheers", {})["awarded"] = True
116 awarded.append(rec)
117
104 self.database.update_fields(rec["id"], rec["value"]) 118 self.database.update_fields(rec["id"], rec["value"])
119
120 return awarded
105 121
106 def unaward_trophies(self, ids):122 def unaward_trophies(self, ids):
107 """ Unaward the trophy with the provided trophy id """123 """ Unaward the trophy with the provided trophy id """
108 for rec in self._get_records("trophies", ids):124 print "unawarding", ids
109 if rec["value"].has_key("private_application_annotations"):125 records = [rec for rec in self._get_records("trophies", ids)]
110 rec["value"]["private_application_annotations"]["cheers"]["awarded"] = False126 if len(records) != len(ids):
111 self.database.update_fields(rec["id"], rec["value"]) 127 raise KeyError, 'No such trophy registered'
128 unawarded = []
129 for rec in records:
130 annot = CouchRecord(rec.value).application_annotations.get("cheers")
131 if annot is not None and annot.has_key("awarded"):
132 annot["awarded"] = False
133 unawarded.append(rec)
134 self.database.update_fields(rec["id"], rec["value"])
135
136 return unawarded
112137
113 def get_trophies_by_app(self, appname):138 def get_trophies_by_app(self, appname):
114 """ Get all the trophies associated with a particular application """139 """ Get all the trophies associated with a particular application """
@@ -122,3 +147,4 @@
122 if trophy.has_key("trophyset") and trophy["trophyset"] == setname:147 if trophy.has_key("trophyset") and trophy["trophyset"] == setname:
123 yield trophy148 yield trophy
124149
150
125151
=== modified file 'cheers/logic.py'
--- cheers/logic.py 2010-11-30 21:22:25 +0000
+++ cheers/logic.py 2011-03-21 21:25:51 +0000
@@ -135,18 +135,17 @@
135 """ Get all the trophy sets in cheers """135 """ Get all the trophy sets in cheers """
136 return [i for i in self.__store.get_sets()]136 return [i for i in self.__store.get_sets()]
137137
138
139 def delete_trophy(self, id):138 def delete_trophy(self, id):
140 """ Delete the trophy for the provided id """139 """ Delete the trophy for the provided id """
141 pass140 self.__store.delete_trophy([id]);
142141
143 def award_trophy(self, id):142 def award_trophy(self, id):
144 """ Award the trophy with the provided trophy id """143 """ Award the trophy with the provided trophy id """
145 pass144 return self.__store.award_trophies([id]);
146145
147 def unaward_trophy(self, id):146 def unaward_trophy(self, id):
148 """ Unaward the trophy with the provided trophy id """147 """ Unaward the trophy with the provided trophy id """
149 pass148 return self.__store.unaward_trophies([id]);
150149
151 def get_trophies_by_app(self, appname):150 def get_trophies_by_app(self, appname):
152 """ Get all the trophies associated with a particular application """151 """ Get all the trophies associated with a particular application """
153152
=== modified file 'cheers/server.py'
--- cheers/server.py 2010-11-30 21:22:25 +0000
+++ cheers/server.py 2011-03-21 21:25:51 +0000
@@ -51,10 +51,9 @@
51 and the connection to the datstore is closed """51 and the connection to the datstore is closed """
52 52
53 print("Requested to stop the bus")53 print("Requested to stop the bus")
54 #self.__store.Quit()
55 os._exit(0)54 os._exit(0)
56 55
57 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a(saasaasssssb)') 56 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a('+config.TROPHY_SIG+')')
58 def GetTrophies(self):57 def GetTrophies(self):
59 """ Get the list of all the trophies registered in cheers """58 """ Get the list of all the trophies registered in cheers """
6059
@@ -65,13 +64,13 @@
65 """ Get the list of all the trophy sets available in cheers """64 """ Get the list of all the trophy sets available in cheers """
66 return self.logic.get_sets()65 return self.logic.get_sets()
67 66
68 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a(saasaasssssb)')67 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a('+config.TROPHY_SIG+')')
69 def GetAwardedTrophies(self):68 def GetAwardedTrophies(self):
70 """ Get the list of all the awarded trophies in cheers """69 """ Get the list of all the awarded trophies in cheers """
7170
72 return self.logic.get_awarded_trophies()71 return self.logic.get_awarded_trophies()
7372
74 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='saasaasssssb')73 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature=config.TROPHY_SIG)
75 def GetTrophy(self, id):74 def GetTrophy(self, id):
76 """ Get the trophy instance when the id is provided """75 """ Get the trophy instance when the id is provided """
7776
@@ -83,26 +82,56 @@
8382
84 res = self.logic.delete_trophy(id)83 res = self.logic.delete_trophy(id)
8584
85 for trophy in res:
86 self.TrophyDeleted(trophy)
87
86 @dbus.service.method(config.CHEERS_BUS_NAME)88 @dbus.service.method(config.CHEERS_BUS_NAME)
87 def AwardTrophy(self, id):89 def AwardTrophy(self, id):
88 """ Award the trophy for the provided trophy id """90 """ Award the trophy for the provided trophy id """
8991
90 res = self.logic.award_trophy(id)92 res = self.logic.award_trophy(id)
9193
94 for trophy in res:
95 self.TrophyAwarded(trophy)
96
92 @dbus.service.method(config.CHEERS_BUS_NAME)97 @dbus.service.method(config.CHEERS_BUS_NAME)
93 def UnawardTrophy(self, id):98 def UnawardTrophy(self, id):
94 """ Unaward the trophy for the provided id """99 """ Unaward the trophy for the provided id """
95100
96 res = self.logic.unaward_trophy(id)101 res = self.logic.unaward_trophy(id)
97102
98 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a(saasaasssssb)')103 for trophy in res:
104 self.TrophyUnawarded(trophy)
105
106 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a('+config.TROPHY_SIG+')')
99 def GetTrophiesByApp(self, appname):107 def GetTrophiesByApp(self, appname):
100 """ Get all the trophies registered for a specific application """108 """ Get all the trophies registered for a specific application """
101109
102 return self.logic.get_trophies_by_app(appname)110 return self.logic.get_trophies_by_app(appname)
103111
104 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a(saasaasssssb)')112 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='a('+config.TROPHY_SIG+')')
105 def GetTrophyBySet(self, setname):113 def GetTrophyBySet(self, setname):
106 """ Get all the trophies registsred for a specific set """114 """ Get all the trophies registsred for a specific set """
107115
108 return self.logic.get_trophies_by_set(setname)116 return self.logic.get_trophies_by_set(setname)
117
118 # @dbus.service.signal(config.CHEERS_BUS_NAME, signature=config.TROPHY_SIG)
119 def TrophyAwarded(self, trophy):
120 """ An event notifying that the trophy has been awarded """
121
122 print("Trophy %s awarded" %(trophy))
123 return trophy
124
125 #@dbus.service.signal(config.CHEERS_BUS_NAME, ignature=config.TROPHY_SIG)
126 def TrophyUnawarded(self, trophy):
127 """ An event notifying that the trophy has been unawarded """
128
129 print("Trophy %s unawarded" %(trophy))
130 return trophy
131
132 #@dbus.service.signal(config.CHEERS_BUS_NAME, signature=config.TROPHY_SIG)
133 def TrophyDeleted(self, trophy):
134 """ An event notifying that the trophy has been deleted """
135
136 print("Trophy %s deleted" %(trophy))
137 return trophy

Subscribers

People subscribed via source and target branches