Merge lp:~manishsinha/cheers/signals-handled into lp:~manishsinha/cheers/insertion

Status: Rejected
Rejected by: Manish Sinha (मनीष सिन्हा)
Proposed branch: lp:~manishsinha/cheers/signals-handled
Merge into: lp:~manishsinha/cheers/insertion
Diff against target: 262 lines (+111/-23)
7 files modified
README (+2/-1)
cheers/client.py (+35/-11)
cheers/config.py (+1/-0)
cheers/datastore.py (+7/-1)
cheers/server.py (+3/-10)
cheers/test_client.py (+41/-0)
setup.py (+22/-0)
To merge this branch: bzr merge lp:~manishsinha/cheers/signals-handled
Reviewer Review Type Date Requested Status
Manish Sinha (मनीष सिन्हा) Disapprove
Stuart Langridge (community) Approve
Review via email: mp+39477@code.launchpad.net
To post a comment you must log in.
21. By Manish Sinha (मनीष सिन्हा)

Changed all the wrapper methods in lower case _ seperated names and set the default awarded state to 0

Revision history for this message
Stuart Langridge (sil) wrote :

Broadly looks OK to me, although I'm not hugely familiar with the code yet.

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

The code in this merge is already present in the trunk via some weird graph like merges. So this hardly makes much sense.

review: Disapprove

Unmerged revisions

21. By Manish Sinha (मनीष सिन्हा)

Changed all the wrapper methods in lower case _ seperated names and set the default awarded state to 0

20. By Manish Sinha (मनीष सिन्हा)

Added event TrophyAwarded, TrophyDeleted and TrophyUnAwarded

19. By Manish Sinha (मनीष सिन्हा)

Added event callback support, Implemented GetAllSetNames DBus API method and added a test file to run for event handling

18. By Manish Sinha (मनीष सिन्हा)

Implemented setup script using distutils

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2010-10-27 12:40:29 +0000
3+++ README 2010-10-27 20:47:48 +0000
4@@ -1,4 +1,5 @@
5-Cheers is a trophya warding framework. It runs as a daemon activating a DBus Session bus over which applications can talk to it.
6+Cheers is a trophy awarding framework. It runs as a daemon activating a DBus Session bus over which applications can talk to it.
7+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.
8
9 It is written using python, sqlite, dbus
10
11
12=== modified file 'cheers/client.py'
13--- cheers/client.py 2010-10-27 12:00:33 +0000
14+++ cheers/client.py 2010-10-27 20:47:48 +0000
15@@ -23,6 +23,9 @@
16 from config import *
17 from datamodel import *
18
19+from dbus.mainloop.glib import DBusGMainLoop
20+DBusGMainLoop(set_as_default=True)
21+
22 class Cheers(object):
23 """ The actual client which interfaces with the OMG Daemon """
24
25@@ -32,66 +35,87 @@
26 bus = dbus.SessionBus()
27 self.__interface = bus.get_object(CHEERS_BUS_NAME, CHEERS_OBJECT_PATH)
28
29- def AwardTrophy(self, id, setname):
30+ def connect(self, signal, callback, **kwargs):
31+ """Connect a callback to a signal of the current proxy instance."""
32+ def _callback(*args, **kwargs):
33+ callback(args)
34+ self.__interface.connect_to_signal(signal, _callback, sender_keyword='sender')
35+
36+ def trophy_awarded(self, callback, **kwargs):
37+ """ Connect the callback to TrophyAwarded signal """
38+
39+ self.connect("TrophyAwarded", callback)
40+
41+ def trophy_deleted(self, callback, **kwargs):
42+ """ Connect the callback to TrophyDeleted signal """
43+
44+ self.connect("TrophyDeleted", callback)
45+
46+ def trophy_unawarded(self, callback, **kwargs):
47+ """ Connect the callback to TrophyUnAwarded signal """
48+
49+ self.connect("TrophyUnAwarded", callback)
50+
51+ def award_trophy(self, id, setname):
52 """ Awards the trophy specified by it's id and the setName.
53
54 Even though the id contains the setname, it is required that setname be explicitly passed
55- If the trophy has been registered, then it is awarded a small notify-osd(libnotify) notification is shown.
56+ If the trophy has been registered, then a notify-osd(libnotify) notification is shown.
57 If the trophy is not registered or has already been awarded, then nothing happens. Call GetTrophy(id,set) to check whether it trophy exists or has already been awarded.
58 """
59 self.__interface.AwardTrophy(id)
60
61- def DeleteTrophy(self, id, setname):
62+ def delete_trophy(self, id, setname):
63 """ Deletes the trophy permanently from the trophy store.
64
65 This is reverse of registering a trophy. This action is irreversible. Use with caution """
66
67 self.__interface.DeleteTrophy(id)
68
69- def UnAwardTrophy(self, id):
70+ def unaward_trophy(self, id):
71 """ Do the reverse of awarding the trophy. Useful for debugging purposes """
72
73 self.__interface.UnAwardTrophy(id)
74
75
76- def GetTrophies(self):
77+ def get_trophies(self):
78 """ Get all the trophies registsred by OMG """
79
80 trophy_list = self.__interface.GetTrophies()
81 return [self.__UnwrapTrophy(trp) for trp in trophy_list]
82
83- def GetTrophy(self, id):
84+ def get_trophy(self, id):
85 """ Get a trophy given it's id and setname """
86
87 trophy = self.__interface.GetTrophy(str(id))
88 return self.__UnwrapTrophy(trophy)
89
90- def GetTrophyBySet(self, setname):
91+ def get_trophy_by_set(self, setname):
92 """ Get all the trophies for the supplied set """
93
94 trophy_list = self.__interface.GetTrophyBySet(str(setname))
95 return [self.__UnwrapTrophy(trp) for trp in trophy_list]
96
97- def GetTrophyByApp(self, appname):
98+ def get_trophy_by_app(self, appname):
99 """ Get all the trophies registered by a specific application"""
100
101 trophy_list = self.__interface.GetTrophyByApp(str(appname))
102 return [self.__UnwrapTrophy(trp) for trp in trophy_list]
103
104- def GetTrophy(self, id):
105+ def get_trophy(self, id):
106 """ Get the trophie registered by it's ID"""
107
108 trophy_list = self.__interface.GetTrophyById(str(id))
109 return [self.__UnwrapTrophy(trp) for trp in trophy_list]
110
111- def GetAllSetNames(self):
112+ def get_all_setnames(self):
113 """ Get the name of all the Trophy sets """
114
115 set_names = self.__interface.GetAllSetNames()
116 return [str(name) for name in set_names]
117
118
119- def Quit(self):
120+ def quit(self):
121 """ Exits the OMG Daemon """
122 try:
123 self.__interface.Quit()
124
125=== modified file 'cheers/config.py'
126--- cheers/config.py 2010-10-27 12:40:29 +0000
127+++ cheers/config.py 2010-10-27 20:47:48 +0000
128@@ -62,6 +62,7 @@
129 fetch_history = "SELECT * FROM history WHERE id=?"
130 fetch_set_byname = "SELECT * FROM appset WHERE setname=?"
131 fetch_app_byapp = "SELECT * FROM app where app=?"
132+fetch_sets = "SELECT setname FROM appset"
133
134 award_trophy_command = "UPDATE trophy SET unlocked=1 WHERE id=?"
135 unaward_trophy_command = "UPDATE trophy SET unlocked=0 WHERE id=?"
136
137=== modified file 'cheers/datastore.py'
138--- cheers/datastore.py 2010-10-27 12:00:33 +0000
139+++ cheers/datastore.py 2010-10-27 20:47:48 +0000
140@@ -130,7 +130,7 @@
141 appid, \
142 setid, \
143 int(json_data["priority"]), \
144- bool(json_data["unlocked"]), \
145+ 0, \
146 timestamp, \
147 json_data["stockicon"]))
148
149@@ -196,6 +196,12 @@
150
151 return trophy_list
152
153+ def GetSetList(self):
154+ """ Get a list of app the sets present in the database """
155+
156+ set_list = self.__cur.execute(config.fetch_sets)
157+ return [setname[0] for setname in set_list.fetchall()]
158+
159 def _CreateTrophyDBus(self, desc_list, trp):
160 """ Create the DBus representation of Trophy which is to be sent
161 over DBus matching the signature a(ssaasssssisbxs)
162
163=== modified file 'cheers/server.py'
164--- cheers/server.py 2010-10-27 12:40:29 +0000
165+++ cheers/server.py 2010-10-27 20:47:48 +0000
166@@ -28,6 +28,7 @@
167 import json
168 import gio
169 import glib
170+import pynotify
171 import gtk
172 import threading
173
174@@ -200,13 +201,5 @@
175
176 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='as')
177 def GetAllSetNames(self):
178- pass
179-
180-
181-class MyThread(threading.Thread):
182- def __init__(self, notifier):
183- self.__notifier = notifier
184- threading.Thread.__init__ ( self )
185- def run(self):
186- print("inotify started")
187- self.__notifier.loop()
188+ """ Get the list of all the trophy set known by cheers """
189+ return self.__store.GetSetList()
190
191=== added file 'cheers/test_client.py'
192--- cheers/test_client.py 1970-01-01 00:00:00 +0000
193+++ cheers/test_client.py 2010-10-27 20:47:48 +0000
194@@ -0,0 +1,41 @@
195+# The MIT/X11/Expat License
196+# Copyright (c) 2010 Seif Lotfy<seiflotfy@googlemail.com>
197+
198+# Permission is hereby granted, free of charge, to any person obtaining a copy
199+# of this software and associated documentation files (the "Software"), to deal
200+# in the Software without restriction, including without limitation the rights
201+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
202+# copies of the Software, and to permit persons to whom the Software is
203+# furnished to do so, subject to the following conditions:
204+
205+# The above copyright notice and this permission notice shall be included in
206+# all copies or substantial portions of the Software.
207+
208+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
209+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
210+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
211+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
212+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
213+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
214+# THE SOFTWARE.
215+
216+from client import Cheers
217+import gtk
218+
219+
220+def handle_awarded(trophies):
221+ print "Awarded"
222+
223+def handle_deleted(trophies):
224+ print "Deleted"
225+
226+def handle_unawarded(trophies):
227+ print "Unawarded"
228+
229+cheers = Cheers()
230+
231+cheers.trophy_awarded(handle_awarded)
232+cheers.trophy_deleted(handle_deleted)
233+cheers.trophy_unawarded(handle_unawarded)
234+
235+gtk.main()
236
237=== modified file 'setup.py'
238--- setup.py 2010-10-03 18:20:14 +0000
239+++ setup.py 2010-10-27 20:47:48 +0000
240@@ -0,0 +1,22 @@
241+#!/usr/bin/env python
242+
243+from distutils.core import setup
244+
245+setup(name='cheers',
246+ version='0.1.0',
247+ description='Trophy awarding framework',
248+ long_description='Cheers is a trophy awarding framework. It runs as a daemon activating a DBus Session bus over which applications can talk to it. 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.',
249+ author='Manish Sinha',
250+ author_email='mail@manishsinha.net',
251+ url='http://cheers-project.com/',
252+ license='MIT/X11/Expat License',
253+ platforms='Posix; MacOSX',
254+ py_modules=['cheers.client',
255+ 'cheers.config',
256+ 'cheers.datamodel',
257+ 'cheers.datastore',
258+ 'cheers.server'],
259+ scripts=['cheers-daemon'],
260+ data_files=[('share/doc/apt-offline', ['LICENSE',
261+ 'MAINTAINERS', 'README'])]
262+ )

Subscribers

People subscribed via source and target branches