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
=== modified file 'README'
--- README 2010-10-27 12:40:29 +0000
+++ README 2010-10-27 20:47:48 +0000
@@ -1,4 +1,5 @@
1Cheers is a trophya warding 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 DBus Session bus over which applications can talk to it.
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.
23
3It is written using python, sqlite, dbus4It is written using python, sqlite, dbus
45
56
=== modified file 'cheers/client.py'
--- cheers/client.py 2010-10-27 12:00:33 +0000
+++ cheers/client.py 2010-10-27 20:47:48 +0000
@@ -23,6 +23,9 @@
23from config import *23from config import *
24from datamodel import *24from datamodel import *
2525
26from dbus.mainloop.glib import DBusGMainLoop
27DBusGMainLoop(set_as_default=True)
28
26class Cheers(object):29class Cheers(object):
27 """ The actual client which interfaces with the OMG Daemon """30 """ The actual client which interfaces with the OMG Daemon """
2831
@@ -32,66 +35,87 @@
32 bus = dbus.SessionBus()35 bus = dbus.SessionBus()
33 self.__interface = bus.get_object(CHEERS_BUS_NAME, CHEERS_OBJECT_PATH)36 self.__interface = bus.get_object(CHEERS_BUS_NAME, CHEERS_OBJECT_PATH)
3437
35 def AwardTrophy(self, id, setname):38 def connect(self, signal, callback, **kwargs):
39 """Connect a callback to a signal of the current proxy instance."""
40 def _callback(*args, **kwargs):
41 callback(args)
42 self.__interface.connect_to_signal(signal, _callback, sender_keyword='sender')
43
44 def trophy_awarded(self, callback, **kwargs):
45 """ Connect the callback to TrophyAwarded signal """
46
47 self.connect("TrophyAwarded", callback)
48
49 def trophy_deleted(self, callback, **kwargs):
50 """ Connect the callback to TrophyDeleted signal """
51
52 self.connect("TrophyDeleted", callback)
53
54 def trophy_unawarded(self, callback, **kwargs):
55 """ Connect the callback to TrophyUnAwarded signal """
56
57 self.connect("TrophyUnAwarded", callback)
58
59 def award_trophy(self, id, setname):
36 """ Awards the trophy specified by it's id and the setName. 60 """ Awards the trophy specified by it's id and the setName.
3761
38 Even though the id contains the setname, it is required that setname be explicitly passed62 Even though the id contains the setname, it is required that setname be explicitly passed
39 If the trophy has been registered, then it is awarded a small notify-osd(libnotify) notification is shown.63 If the trophy has been registered, then a notify-osd(libnotify) notification is shown.
40 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.64 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.
41 """65 """
42 self.__interface.AwardTrophy(id)66 self.__interface.AwardTrophy(id)
4367
44 def DeleteTrophy(self, id, setname):68 def delete_trophy(self, id, setname):
45 """ Deletes the trophy permanently from the trophy store. 69 """ Deletes the trophy permanently from the trophy store.
46 70
47 This is reverse of registering a trophy. This action is irreversible. Use with caution """71 This is reverse of registering a trophy. This action is irreversible. Use with caution """
4872
49 self.__interface.DeleteTrophy(id)73 self.__interface.DeleteTrophy(id)
5074
51 def UnAwardTrophy(self, id):75 def unaward_trophy(self, id):
52 """ Do the reverse of awarding the trophy. Useful for debugging purposes """76 """ Do the reverse of awarding the trophy. Useful for debugging purposes """
53 77
54 self.__interface.UnAwardTrophy(id)78 self.__interface.UnAwardTrophy(id)
55 79
5680
57 def GetTrophies(self):81 def get_trophies(self):
58 """ Get all the trophies registsred by OMG """82 """ Get all the trophies registsred by OMG """
5983
60 trophy_list = self.__interface.GetTrophies()84 trophy_list = self.__interface.GetTrophies()
61 return [self.__UnwrapTrophy(trp) for trp in trophy_list]85 return [self.__UnwrapTrophy(trp) for trp in trophy_list]
6286
63 def GetTrophy(self, id):87 def get_trophy(self, id):
64 """ Get a trophy given it's id and setname """88 """ Get a trophy given it's id and setname """
6589
66 trophy = self.__interface.GetTrophy(str(id))90 trophy = self.__interface.GetTrophy(str(id))
67 return self.__UnwrapTrophy(trophy)91 return self.__UnwrapTrophy(trophy)
6892
69 def GetTrophyBySet(self, setname):93 def get_trophy_by_set(self, setname):
70 """ Get all the trophies for the supplied set """94 """ Get all the trophies for the supplied set """
7195
72 trophy_list = self.__interface.GetTrophyBySet(str(setname))96 trophy_list = self.__interface.GetTrophyBySet(str(setname))
73 return [self.__UnwrapTrophy(trp) for trp in trophy_list]97 return [self.__UnwrapTrophy(trp) for trp in trophy_list]
7498
75 def GetTrophyByApp(self, appname):99 def get_trophy_by_app(self, appname):
76 """ Get all the trophies registered by a specific application"""100 """ Get all the trophies registered by a specific application"""
77101
78 trophy_list = self.__interface.GetTrophyByApp(str(appname))102 trophy_list = self.__interface.GetTrophyByApp(str(appname))
79 return [self.__UnwrapTrophy(trp) for trp in trophy_list]103 return [self.__UnwrapTrophy(trp) for trp in trophy_list]
80104
81 def GetTrophy(self, id):105 def get_trophy(self, id):
82 """ Get the trophie registered by it's ID"""106 """ Get the trophie registered by it's ID"""
83107
84 trophy_list = self.__interface.GetTrophyById(str(id))108 trophy_list = self.__interface.GetTrophyById(str(id))
85 return [self.__UnwrapTrophy(trp) for trp in trophy_list]109 return [self.__UnwrapTrophy(trp) for trp in trophy_list]
86110
87 def GetAllSetNames(self):111 def get_all_setnames(self):
88 """ Get the name of all the Trophy sets """112 """ Get the name of all the Trophy sets """
89113
90 set_names = self.__interface.GetAllSetNames()114 set_names = self.__interface.GetAllSetNames()
91 return [str(name) for name in set_names]115 return [str(name) for name in set_names]
92116
93117
94 def Quit(self):118 def quit(self):
95 """ Exits the OMG Daemon """119 """ Exits the OMG Daemon """
96 try:120 try:
97 self.__interface.Quit()121 self.__interface.Quit()
98122
=== modified file 'cheers/config.py'
--- cheers/config.py 2010-10-27 12:40:29 +0000
+++ cheers/config.py 2010-10-27 20:47:48 +0000
@@ -62,6 +62,7 @@
62fetch_history = "SELECT * FROM history WHERE id=?"62fetch_history = "SELECT * FROM history WHERE id=?"
63fetch_set_byname = "SELECT * FROM appset WHERE setname=?"63fetch_set_byname = "SELECT * FROM appset WHERE setname=?"
64fetch_app_byapp = "SELECT * FROM app where app=?"64fetch_app_byapp = "SELECT * FROM app where app=?"
65fetch_sets = "SELECT setname FROM appset"
6566
66award_trophy_command = "UPDATE trophy SET unlocked=1 WHERE id=?"67award_trophy_command = "UPDATE trophy SET unlocked=1 WHERE id=?"
67unaward_trophy_command = "UPDATE trophy SET unlocked=0 WHERE id=?"68unaward_trophy_command = "UPDATE trophy SET unlocked=0 WHERE id=?"
6869
=== modified file 'cheers/datastore.py'
--- cheers/datastore.py 2010-10-27 12:00:33 +0000
+++ cheers/datastore.py 2010-10-27 20:47:48 +0000
@@ -130,7 +130,7 @@
130 appid, \130 appid, \
131 setid, \131 setid, \
132 int(json_data["priority"]), \132 int(json_data["priority"]), \
133 bool(json_data["unlocked"]), \133 0, \
134 timestamp, \134 timestamp, \
135 json_data["stockicon"]))135 json_data["stockicon"]))
136 136
@@ -196,6 +196,12 @@
196 196
197 return trophy_list197 return trophy_list
198 198
199 def GetSetList(self):
200 """ Get a list of app the sets present in the database """
201
202 set_list = self.__cur.execute(config.fetch_sets)
203 return [setname[0] for setname in set_list.fetchall()]
204
199 def _CreateTrophyDBus(self, desc_list, trp):205 def _CreateTrophyDBus(self, desc_list, trp):
200 """ Create the DBus representation of Trophy which is to be sent206 """ Create the DBus representation of Trophy which is to be sent
201 over DBus matching the signature a(ssaasssssisbxs) 207 over DBus matching the signature a(ssaasssssisbxs)
202208
=== modified file 'cheers/server.py'
--- cheers/server.py 2010-10-27 12:40:29 +0000
+++ cheers/server.py 2010-10-27 20:47:48 +0000
@@ -28,6 +28,7 @@
28import json28import json
29import gio29import gio
30import glib30import glib
31import pynotify
31import gtk32import gtk
32import threading33import threading
3334
@@ -200,13 +201,5 @@
200 201
201 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='as')202 @dbus.service.method(config.CHEERS_BUS_NAME, out_signature='as')
202 def GetAllSetNames(self):203 def GetAllSetNames(self):
203 pass204 """ Get the list of all the trophy set known by cheers """
204205 return self.__store.GetSetList()
205
206class MyThread(threading.Thread):
207 def __init__(self, notifier):
208 self.__notifier = notifier
209 threading.Thread.__init__ ( self )
210 def run(self):
211 print("inotify started")
212 self.__notifier.loop()
213206
=== added file 'cheers/test_client.py'
--- cheers/test_client.py 1970-01-01 00:00:00 +0000
+++ cheers/test_client.py 2010-10-27 20:47:48 +0000
@@ -0,0 +1,41 @@
1# The MIT/X11/Expat License
2# Copyright (c) 2010 Seif Lotfy<seiflotfy@googlemail.com>
3
4# Permission is hereby granted, free of charge, to any person obtaining a copy
5# of this software and associated documentation files (the "Software"), to deal
6# in the Software without restriction, including without limitation the rights
7# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8# copies of the Software, and to permit persons to whom the Software is
9# furnished to do so, subject to the following conditions:
10
11# The above copyright notice and this permission notice shall be included in
12# all copies or substantial portions of the Software.
13
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20# THE SOFTWARE.
21
22from client import Cheers
23import gtk
24
25
26def handle_awarded(trophies):
27 print "Awarded"
28
29def handle_deleted(trophies):
30 print "Deleted"
31
32def handle_unawarded(trophies):
33 print "Unawarded"
34
35cheers = Cheers()
36
37cheers.trophy_awarded(handle_awarded)
38cheers.trophy_deleted(handle_deleted)
39cheers.trophy_unawarded(handle_unawarded)
40
41gtk.main()
042
=== modified file 'setup.py'
--- setup.py 2010-10-03 18:20:14 +0000
+++ setup.py 2010-10-27 20:47:48 +0000
@@ -0,0 +1,22 @@
1#!/usr/bin/env python
2
3from distutils.core import setup
4
5setup(name='cheers',
6 version='0.1.0',
7 description='Trophy awarding framework',
8 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.',
9 author='Manish Sinha',
10 author_email='mail@manishsinha.net',
11 url='http://cheers-project.com/',
12 license='MIT/X11/Expat License',
13 platforms='Posix; MacOSX',
14 py_modules=['cheers.client',
15 'cheers.config',
16 'cheers.datamodel',
17 'cheers.datastore',
18 'cheers.server'],
19 scripts=['cheers-daemon'],
20 data_files=[('share/doc/apt-offline', ['LICENSE',
21 'MAINTAINERS', 'README'])]
22 )

Subscribers

People subscribed via source and target branches