Merge lp:~manishsinha/cheers/insertion into lp:~cheers/cheers/trunk
- insertion
- Merge into trunk
Proposed by
Manish Sinha (मनीष सिन्हा)
Status: | Merged |
---|---|
Merged at revision: | 17 |
Proposed branch: | lp:~manishsinha/cheers/insertion |
Merge into: | lp:~cheers/cheers/trunk |
Diff against target: |
464 lines (+222/-51) 10 files modified
LICENSE (+21/-0) MAINTAINERS (+1/-0) README (+38/-0) aa.trophy (+1/-0) cheers-daemon (+29/-0) cheers-daemon.py (+0/-27) cheers/client.py (+14/-15) cheers/config.py (+11/-0) cheers/datastore.py (+96/-4) cheers/server.py (+11/-5) |
To merge this branch: | bzr merge lp:~manishsinha/cheers/insertion |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Cheers | Pending | ||
Review via email: mp+39438@code.launchpad.net |
Commit message
Description of the change
Implemented the insertion of trophies and fixed the client python bindings
To post a comment you must log in.
lp:~manishsinha/cheers/insertion
updated
- 17. By Manish Sinha (मनीष सिन्हा)
-
Updated README, LICENSE, MAINTAINERS and fixed the name of the daemon file
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'LICENSE' | |||
2 | --- LICENSE 2010-10-03 18:20:14 +0000 | |||
3 | +++ LICENSE 2010-10-27 12:43:44 +0000 | |||
4 | @@ -0,0 +1,21 @@ | |||
5 | 1 | # The MIT/X11/Expat License | ||
6 | 2 | |||
7 | 3 | # Copyright (c) 2010 Manish Sinha<mail@manishsinha.net> | ||
8 | 4 | |||
9 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
10 | 6 | # of this software and associated documentation files (the "Software"), to deal | ||
11 | 7 | # in the Software without restriction, including without limitation the rights | ||
12 | 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
13 | 9 | # copies of the Software, and to permit persons to whom the Software is | ||
14 | 10 | # furnished to do so, subject to the following conditions: | ||
15 | 11 | |||
16 | 12 | # The above copyright notice and this permission notice shall be included in | ||
17 | 13 | # all copies or substantial portions of the Software. | ||
18 | 14 | |||
19 | 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
20 | 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
21 | 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
22 | 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
23 | 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
24 | 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
25 | 21 | # THE SOFTWARE. | ||
26 | 0 | 22 | ||
27 | === modified file 'MAINTAINERS' | |||
28 | --- MAINTAINERS 2010-10-03 18:20:14 +0000 | |||
29 | +++ MAINTAINERS 2010-10-27 12:43:44 +0000 | |||
30 | @@ -0,0 +1,1 @@ | |||
31 | 1 | Manish Sinha <mail@manishsinha.net> | ||
32 | 0 | 2 | ||
33 | === modified file 'README' | |||
34 | --- README 2010-10-03 18:20:14 +0000 | |||
35 | +++ README 2010-10-27 12:43:44 +0000 | |||
36 | @@ -0,0 +1,38 @@ | |||
37 | 1 | Cheers is a trophya warding framework. It runs as a daemon activating a DBus Session bus over which applications can talk to it. | ||
38 | 2 | |||
39 | 3 | It is written using python, sqlite, dbus | ||
40 | 4 | |||
41 | 5 | Prerequisties | ||
42 | 6 | --------------- | ||
43 | 7 | To get cheers up and running, you need the following packages. Please check your distribution for the exact name of the packages | ||
44 | 8 | * python | ||
45 | 9 | * python-dbus | ||
46 | 10 | * python-sqlite | ||
47 | 11 | * python-gio | ||
48 | 12 | * python-glib | ||
49 | 13 | * python-gtk | ||
50 | 14 | |||
51 | 15 | |||
52 | 16 | |||
53 | 17 | Running | ||
54 | 18 | --------- | ||
55 | 19 | Execute cheers-daemon using the command | ||
56 | 20 | |||
57 | 21 | ./cheers-daemon.py | ||
58 | 22 | |||
59 | 23 | |||
60 | 24 | Registering a trophy | ||
61 | 25 | --------------------- | ||
62 | 26 | |||
63 | 27 | Cheers keeps a watch on three folders for new trophies when the server is running. These two folders are | ||
64 | 28 | * /usr/share/cheers/trophies | ||
65 | 29 | * /usr/local/share/cheers/trophies | ||
66 | 30 | * ~/.local/share/cheers/trophies | ||
67 | 31 | |||
68 | 32 | A sample trophy aa.trophy is provided. Put it under the folder ~/.local/share/cheers/trophies to register the trophy | ||
69 | 33 | |||
70 | 34 | |||
71 | 35 | Debugging | ||
72 | 36 | ------------ | ||
73 | 37 | |||
74 | 38 | Use D-feet DBus debugger to have a look at the DBus API | ||
75 | 0 | 39 | ||
76 | === added file 'aa.trophy' | |||
77 | --- aa.trophy 1970-01-01 00:00:00 +0000 | |||
78 | +++ aa.trophy 2010-10-27 12:43:44 +0000 | |||
79 | @@ -0,0 +1,1 @@ | |||
80 | 1 | {"id":"Name","setname":"Music", "seticon": "", "app":"application://banshee.desktop", "appname":"Banshee Music Player", "title":"FM Junkie", "iconpath":"", "priority": 1, "unlocked": "False", "stockicon":"", "desc": {"1": {"lang":"en-us", "desc": "Listen to Music alot"}, "2": {"lang":"en-uk", "desc": "Listen to Music a lot, a lot"}}} | ||
81 | 0 | 2 | ||
82 | === added file 'cheers-daemon' | |||
83 | --- cheers-daemon 1970-01-01 00:00:00 +0000 | |||
84 | +++ cheers-daemon 2010-10-27 12:43:44 +0000 | |||
85 | @@ -0,0 +1,29 @@ | |||
86 | 1 | #! /usr/bin/env python | ||
87 | 2 | |||
88 | 3 | # The MIT/X11/Expat License | ||
89 | 4 | # Copyright (c) 2010 Manish Sinha<mail@manishsinha.net> | ||
90 | 5 | |||
91 | 6 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
92 | 7 | # of this software and associated documentation files (the "Software"), to deal | ||
93 | 8 | # in the Software without restriction, including without limitation the rights | ||
94 | 9 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
95 | 10 | # copies of the Software, and to permit persons to whom the Software is | ||
96 | 11 | # furnished to do so, subject to the following conditions: | ||
97 | 12 | |||
98 | 13 | # The above copyright notice and this permission notice shall be included in | ||
99 | 14 | # all copies or substantial portions of the Software. | ||
100 | 15 | |||
101 | 16 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
102 | 17 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
103 | 18 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
104 | 19 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
105 | 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
106 | 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
107 | 22 | # THE SOFTWARE. | ||
108 | 23 | |||
109 | 24 | |||
110 | 25 | from cheers import server | ||
111 | 26 | |||
112 | 27 | if __name__ == "__main__": | ||
113 | 28 | |||
114 | 29 | server.TrophyServer() | ||
115 | 0 | 30 | ||
116 | === removed file 'cheers-daemon.py' | |||
117 | --- cheers-daemon.py 2010-10-17 20:31:25 +0000 | |||
118 | +++ cheers-daemon.py 1970-01-01 00:00:00 +0000 | |||
119 | @@ -1,27 +0,0 @@ | |||
120 | 1 | # The MIT/X11/Expat License | ||
121 | 2 | # Copyright (c) 2010 Manish Sinha<mail@manishsinha.net> | ||
122 | 3 | |||
123 | 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy | ||
124 | 5 | # of this software and associated documentation files (the "Software"), to deal | ||
125 | 6 | # in the Software without restriction, including without limitation the rights | ||
126 | 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
127 | 8 | # copies of the Software, and to permit persons to whom the Software is | ||
128 | 9 | # furnished to do so, subject to the following conditions: | ||
129 | 10 | |||
130 | 11 | # The above copyright notice and this permission notice shall be included in | ||
131 | 12 | # all copies or substantial portions of the Software. | ||
132 | 13 | |||
133 | 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
134 | 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
135 | 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
136 | 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
137 | 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
138 | 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
139 | 20 | # THE SOFTWARE. | ||
140 | 21 | |||
141 | 22 | |||
142 | 23 | from cheers import server | ||
143 | 24 | |||
144 | 25 | |||
145 | 26 | if __name__ == "__main__": | ||
146 | 27 | cheers_server = server.TrophyServer() | ||
147 | 28 | 0 | ||
148 | === modified file 'cheers/client.py' | |||
149 | --- cheers/client.py 2010-10-03 19:24:44 +0000 | |||
150 | +++ cheers/client.py 2010-10-27 12:43:44 +0000 | |||
151 | @@ -30,7 +30,7 @@ | |||
152 | 30 | 30 | ||
153 | 31 | def __init__(self): | 31 | def __init__(self): |
154 | 32 | bus = dbus.SessionBus() | 32 | bus = dbus.SessionBus() |
156 | 33 | self.__interface = bus.get_object(OMG_BUS_NAME, OMG_OBJECT_PATH) | 33 | self.__interface = bus.get_object(CHEERS_BUS_NAME, CHEERS_OBJECT_PATH) |
157 | 34 | 34 | ||
158 | 35 | def AwardTrophy(self, id, setname): | 35 | def AwardTrophy(self, id, setname): |
159 | 36 | """ Awards the trophy specified by it's id and the setName. | 36 | """ Awards the trophy specified by it's id and the setName. |
160 | @@ -39,23 +39,19 @@ | |||
161 | 39 | If the trophy has been registered, then it is awarded a small notify-osd(libnotify) notification is shown. | 39 | If the trophy has been registered, then it is awarded a small notify-osd(libnotify) notification is shown. |
162 | 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. | 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. |
163 | 41 | """ | 41 | """ |
165 | 42 | self.__interface.AwardTrophy(id, setname) | 42 | self.__interface.AwardTrophy(id) |
166 | 43 | 43 | ||
167 | 44 | def DeleteTrophy(self, id, setname): | 44 | def DeleteTrophy(self, id, setname): |
168 | 45 | """ Deletes the trophy permanently from the trophy store. | 45 | """ Deletes the trophy permanently from the trophy store. |
169 | 46 | 46 | ||
170 | 47 | This is reverse of registering a trophy. This action is irreversible. Use with caution """ | 47 | This is reverse of registering a trophy. This action is irreversible. Use with caution """ |
171 | 48 | 48 | ||
177 | 49 | res = self.__interface.DeleteTrophy(id, setname) | 49 | self.__interface.DeleteTrophy(id) |
178 | 50 | 50 | ||
179 | 51 | return Response(res[0], res[1], res[2]) | 51 | def UnAwardTrophy(self, id): |
175 | 52 | |||
176 | 53 | def UnAwardTrophy(self, id, setname): | ||
180 | 54 | """ Do the reverse of awarding the trophy. Useful for debugging purposes """ | 52 | """ Do the reverse of awarding the trophy. Useful for debugging purposes """ |
181 | 55 | 53 | ||
185 | 56 | res = self.__interface.UnAwardTrophy(id, setname) | 54 | self.__interface.UnAwardTrophy(id) |
183 | 57 | |||
184 | 58 | return Response(res[0], res[1], res[2]) | ||
186 | 59 | 55 | ||
187 | 60 | 56 | ||
188 | 61 | def GetTrophies(self): | 57 | def GetTrophies(self): |
189 | @@ -64,10 +60,10 @@ | |||
190 | 64 | trophy_list = self.__interface.GetTrophies() | 60 | trophy_list = self.__interface.GetTrophies() |
191 | 65 | return [self.__UnwrapTrophy(trp) for trp in trophy_list] | 61 | return [self.__UnwrapTrophy(trp) for trp in trophy_list] |
192 | 66 | 62 | ||
194 | 67 | def GetTrophy(self, id, setname): | 63 | def GetTrophy(self, id): |
195 | 68 | """ Get a trophy given it's id and setname """ | 64 | """ Get a trophy given it's id and setname """ |
196 | 69 | 65 | ||
198 | 70 | trophy = self.__interface.GetTrophy(str(id), str(setname)) | 66 | trophy = self.__interface.GetTrophy(str(id)) |
199 | 71 | return self.__UnwrapTrophy(trophy) | 67 | return self.__UnwrapTrophy(trophy) |
200 | 72 | 68 | ||
201 | 73 | def GetTrophyBySet(self, setname): | 69 | def GetTrophyBySet(self, setname): |
202 | @@ -82,7 +78,7 @@ | |||
203 | 82 | trophy_list = self.__interface.GetTrophyByApp(str(appname)) | 78 | trophy_list = self.__interface.GetTrophyByApp(str(appname)) |
204 | 83 | return [self.__UnwrapTrophy(trp) for trp in trophy_list] | 79 | return [self.__UnwrapTrophy(trp) for trp in trophy_list] |
205 | 84 | 80 | ||
207 | 85 | def GetTrophyById(self, id): | 81 | def GetTrophy(self, id): |
208 | 86 | """ Get the trophie registered by it's ID""" | 82 | """ Get the trophie registered by it's ID""" |
209 | 87 | 83 | ||
210 | 88 | trophy_list = self.__interface.GetTrophyById(str(id)) | 84 | trophy_list = self.__interface.GetTrophyById(str(id)) |
211 | @@ -97,12 +93,15 @@ | |||
212 | 97 | 93 | ||
213 | 98 | def Quit(self): | 94 | def Quit(self): |
214 | 99 | """ Exits the OMG Daemon """ | 95 | """ Exits the OMG Daemon """ |
217 | 100 | 96 | try: | |
218 | 101 | self.__interface.Quit() | 97 | self.__interface.Quit() |
219 | 98 | except dbus.DBusException: | ||
220 | 99 | pass | ||
221 | 102 | 100 | ||
222 | 103 | def __UnwrapTrophy(self, trophy): | 101 | def __UnwrapTrophy(self, trophy): |
223 | 104 | """ Unwraps the trophy instances as per the positions """ | 102 | """ Unwraps the trophy instances as per the positions """ |
224 | 105 | 103 | ||
225 | 104 | print(trophy) | ||
226 | 106 | return Trophy(trophy[0], trophy [1], trophy [2], trophy [4], \ | 105 | return Trophy(trophy[0], trophy [1], trophy [2], trophy [4], \ |
227 | 107 | trophy[5], trophy[6], trophy[7], trophy[3], \ | 106 | trophy[5], trophy[6], trophy[7], trophy[3], \ |
228 | 108 | trophy[8], trophy[9], trophy[10], trophy[11]) | 107 | trophy[8], trophy[9], trophy[10], trophy[11]) |
229 | 109 | 108 | ||
230 | === modified file 'cheers/config.py' | |||
231 | --- cheers/config.py 2010-10-12 19:29:39 +0000 | |||
232 | +++ cheers/config.py 2010-10-27 12:43:44 +0000 | |||
233 | @@ -31,6 +31,7 @@ | |||
234 | 31 | 31 | ||
235 | 32 | trophy_dump_path = os.path.join(cheers_data_path, "trophies") | 32 | trophy_dump_path = os.path.join(cheers_data_path, "trophies") |
236 | 33 | global_trophy_path = "/usr/share/cheers/trophies" | 33 | global_trophy_path = "/usr/share/cheers/trophies" |
237 | 34 | global_trophy_path_local = "/usr/local/share/cheers/trophies" | ||
238 | 34 | 35 | ||
239 | 35 | DATA_STORE_TYPE = "sqlite" | 36 | DATA_STORE_TYPE = "sqlite" |
240 | 36 | 37 | ||
241 | @@ -47,10 +48,20 @@ | |||
242 | 47 | create_desc_command = "CREATE TABLE description (id TEXT, language TEXT, desc TEXT)" | 48 | create_desc_command = "CREATE TABLE description (id TEXT, language TEXT, desc TEXT)" |
243 | 48 | create_app_command = "CREATE TABLE app(appid INTEGER, app TEXT, appname TEXT)" | 49 | create_app_command = "CREATE TABLE app(appid INTEGER, app TEXT, appname TEXT)" |
244 | 49 | create_set_command = "CREATE TABLE appset(setid INTEGER, setname TEXT, seticon TEXT)" | 50 | create_set_command = "CREATE TABLE appset(setid INTEGER, setname TEXT, seticon TEXT)" |
245 | 51 | create_history_command = "CREATE TABLE history(id TEXT, timestamp INTEGER)" | ||
246 | 52 | |||
247 | 53 | insert_history_command = "INSERT INTO history VALUES(?,?)" | ||
248 | 54 | insert_trophy_command = "INSERT INTO trophy VALUES(?,?,?,?,?,?,?,?,?)" | ||
249 | 55 | insert_desc_command = "INSERT INTO description VALUES(?,?,?)" | ||
250 | 56 | insert_app_command = "INSERT INTO app VALUES(?,?,?)" | ||
251 | 57 | insert_set_command = "INSERT INTO appset VALUES(?,?,?)" | ||
252 | 50 | 58 | ||
253 | 51 | fetch_trophy_where = "SELECT trophy.id, trophy.title, trophy.iconpath, app.app, app.appname, appset.setname, appset.seticon, trophy.priority, trophy.unlocked, trophy.timestamp, trophy.stockicon FROM trophy, app,appset WHERE trophy.app=app.appid and trophy.appset=appset.setid and %s=:value" | 59 | fetch_trophy_where = "SELECT trophy.id, trophy.title, trophy.iconpath, app.app, app.appname, appset.setname, appset.seticon, trophy.priority, trophy.unlocked, trophy.timestamp, trophy.stockicon FROM trophy, app,appset WHERE trophy.app=app.appid and trophy.appset=appset.setid and %s=:value" |
254 | 52 | fetch_trophy_all = "select trophy.id, trophy.title, trophy.iconpath, app.app, app.appname, appset.setname, appset.seticon, trophy.priority, trophy.unlocked, trophy.timestamp, trophy.stockicon FROM trophy, app,appset WHERE trophy.app=app.appid and trophy.appset=appset.setid" | 60 | fetch_trophy_all = "select trophy.id, trophy.title, trophy.iconpath, app.app, app.appname, appset.setname, appset.seticon, trophy.priority, trophy.unlocked, trophy.timestamp, trophy.stockicon FROM trophy, app,appset WHERE trophy.app=app.appid and trophy.appset=appset.setid" |
255 | 53 | fetch_description = "SELECT language, desc FROM description WHERE id=:Id" | 61 | fetch_description = "SELECT language, desc FROM description WHERE id=:Id" |
256 | 62 | fetch_history = "SELECT * FROM history WHERE id=?" | ||
257 | 63 | fetch_set_byname = "SELECT * FROM appset WHERE setname=?" | ||
258 | 64 | fetch_app_byapp = "SELECT * FROM app where app=?" | ||
259 | 54 | 65 | ||
260 | 55 | award_trophy_command = "UPDATE trophy SET unlocked=1 WHERE id=?" | 66 | award_trophy_command = "UPDATE trophy SET unlocked=1 WHERE id=?" |
261 | 56 | unaward_trophy_command = "UPDATE trophy SET unlocked=0 WHERE id=?" | 67 | unaward_trophy_command = "UPDATE trophy SET unlocked=0 WHERE id=?" |
262 | 57 | 68 | ||
263 | === modified file 'cheers/datastore.py' | |||
264 | --- cheers/datastore.py 2010-10-12 19:29:39 +0000 | |||
265 | +++ cheers/datastore.py 2010-10-27 12:43:44 +0000 | |||
266 | @@ -22,6 +22,8 @@ | |||
267 | 22 | import os | 22 | import os |
268 | 23 | import sqlite3 | 23 | import sqlite3 |
269 | 24 | import config | 24 | import config |
270 | 25 | import random | ||
271 | 26 | import datetime | ||
272 | 25 | 27 | ||
273 | 26 | class SqliteStore(): | 28 | class SqliteStore(): |
274 | 27 | """ Implement the data storage based using sqlite as backend | 29 | """ Implement the data storage based using sqlite as backend |
275 | @@ -46,27 +48,116 @@ | |||
276 | 46 | # Try creating the tables | 48 | # Try creating the tables |
277 | 47 | try: | 49 | try: |
278 | 48 | self.__cur.execute(config.create_trophy_command) | 50 | self.__cur.execute(config.create_trophy_command) |
279 | 51 | except sqlite3.OperationalError: | ||
280 | 52 | print("Trophy Table existed") | ||
281 | 53 | |||
282 | 54 | try: | ||
283 | 49 | self.__cur.execute(config.create_desc_command) | 55 | self.__cur.execute(config.create_desc_command) |
284 | 56 | except sqlite3.OperationalError: | ||
285 | 57 | print("Description Table existed") | ||
286 | 58 | |||
287 | 59 | try: | ||
288 | 50 | self.__cur.execute(config.create_app_command) | 60 | self.__cur.execute(config.create_app_command) |
289 | 61 | except sqlite3.OperationalError: | ||
290 | 62 | print("App Table existed") | ||
291 | 63 | |||
292 | 64 | try: | ||
293 | 51 | self.__cur.execute(config.create_set_command) | 65 | self.__cur.execute(config.create_set_command) |
297 | 52 | print("All tables create successfully") | 66 | except sqlite3.OperationalError: |
298 | 53 | except sqlite3.OperationalError: | 67 | print("Set Table existed") |
299 | 54 | print("Table existed") | 68 | |
300 | 69 | try: | ||
301 | 70 | self.__cur.execute(config.create_history_command) | ||
302 | 71 | except sqlite3.OperationalError: | ||
303 | 72 | print("History Table existed") | ||
304 | 73 | |||
305 | 55 | 74 | ||
306 | 56 | self.__res_cursor=None | 75 | self.__res_cursor=None |
307 | 57 | 76 | ||
308 | 77 | def AddTrophy(self, json_data): | ||
309 | 78 | """ Add the trophy to the database from the JSON data passed """ | ||
310 | 79 | |||
311 | 80 | res_history = self.__cur.execute(config.fetch_history, (json_data["id"],)) | ||
312 | 81 | fetch_trp = config.fetch_trophy_where %("id",) | ||
313 | 82 | res_trophy = self.__cur.execute(fetch_trp, { "value":json_data["id"] }) | ||
314 | 83 | if(len(res_history.fetchall()) == 0 and len(res_trophy.fetchall()) == 0): | ||
315 | 84 | |||
316 | 85 | # Searching and Inserting Sets | ||
317 | 86 | set_list = self.__cur.execute(config.fetch_set_byname, (json_data["setname"],)) | ||
318 | 87 | matched_set = set_list.fetchone() | ||
319 | 88 | if matched_set is None: | ||
320 | 89 | # Does not exist, create one | ||
321 | 90 | print("Set '%s' does not exist. Creating." %(json_data["setname"],)) | ||
322 | 91 | setid = int(random.random()*10000000) | ||
323 | 92 | self.__cur.execute(config.insert_set_command, (setid, json_data["setname"], json_data["seticon"])) | ||
324 | 93 | else: | ||
325 | 94 | # Exists. Use it | ||
326 | 95 | print("Set '%s' already exists. Will be reused" %(matched_set[1],)) | ||
327 | 96 | setid = matched_set[0] | ||
328 | 97 | |||
329 | 98 | # Searching and Inserting Apps | ||
330 | 99 | app_list = self.__cur.execute(config.fetch_app_byapp, (json_data["app"],)) | ||
331 | 100 | matched_app = app_list.fetchone() | ||
332 | 101 | if matched_app is None: | ||
333 | 102 | # Does not exist, create one | ||
334 | 103 | print("App '%s' does not exist. Creating." %(json_data["app"],)) | ||
335 | 104 | appid = int(random.random()*10000000) | ||
336 | 105 | self.__cur.execute(config.insert_app_command, (appid, json_data["app"], json_data["appname"])) | ||
337 | 106 | else: | ||
338 | 107 | # Exists. Use it | ||
339 | 108 | print("App '%s' already exists. Will be reused" %(matched_app[1],)) | ||
340 | 109 | appid = matched_app[0] | ||
341 | 110 | |||
342 | 111 | |||
343 | 112 | # Remove all description for this Id if present | ||
344 | 113 | desc_list = self.__cur.execute(config.remove_desc_command, (json_data["id"],)) | ||
345 | 114 | # Inserting Description | ||
346 | 115 | desc_list = json_data["desc"] | ||
347 | 116 | for desc in desc_list.values(): | ||
348 | 117 | self.__cur.execute(config.insert_desc_command, (json_data["id"], desc["lang"], desc["desc"])) | ||
349 | 118 | |||
350 | 119 | timestamp = int(datetime.datetime(1970,01,01).today().strftime("%s")) | ||
351 | 120 | |||
352 | 121 | try: | ||
353 | 122 | # Inserting Trophy | ||
354 | 123 | is_present = self.Search("trophy.id", json_data["id"]) | ||
355 | 124 | if len(is_present) > 0: | ||
356 | 125 | print("The trophy '%s' already exists" %(json_data["id"], )) | ||
357 | 126 | else: | ||
358 | 127 | self.__cur.execute(config.insert_trophy_command, ( json_data["id"], \ | ||
359 | 128 | json_data["title"], \ | ||
360 | 129 | json_data["iconpath"], \ | ||
361 | 130 | appid, \ | ||
362 | 131 | setid, \ | ||
363 | 132 | int(json_data["priority"]), \ | ||
364 | 133 | bool(json_data["unlocked"]), \ | ||
365 | 134 | timestamp, \ | ||
366 | 135 | json_data["stockicon"])) | ||
367 | 136 | |||
368 | 137 | # Inserting History | ||
369 | 138 | self.__cur.execute(config.insert_history_command, (json_data["id"], timestamp)) | ||
370 | 139 | |||
371 | 140 | self.__conn.commit() | ||
372 | 141 | pass | ||
373 | 142 | except: | ||
374 | 143 | raise | ||
375 | 144 | |||
376 | 145 | |||
377 | 58 | def AwardTrophy(self, id): | 146 | def AwardTrophy(self, id): |
378 | 59 | """ Award the trophy """ | 147 | """ Award the trophy """ |
379 | 148 | |||
380 | 60 | self.__cur.execute(config.award_trophy_command, (id,)) | 149 | self.__cur.execute(config.award_trophy_command, (id,)) |
381 | 61 | self.__conn.commit() | 150 | self.__conn.commit() |
382 | 62 | 151 | ||
383 | 63 | def UnAwardTrophy(self, id): | 152 | def UnAwardTrophy(self, id): |
384 | 64 | """ Un-Award the trophy """ | 153 | """ Un-Award the trophy """ |
385 | 154 | |||
386 | 65 | self.__cur.execute(config.unaward_trophy_command, (id,)) | 155 | self.__cur.execute(config.unaward_trophy_command, (id,)) |
387 | 66 | self.__conn.commit() | 156 | self.__conn.commit() |
388 | 67 | 157 | ||
389 | 68 | def DeleteTrophy(self, id): | 158 | def DeleteTrophy(self, id): |
390 | 69 | """ Un-Award the trophy """ | 159 | """ Un-Award the trophy """ |
391 | 160 | |||
392 | 70 | self.__cur.execute(config.remove_trophy_command, (id,)) | 161 | self.__cur.execute(config.remove_trophy_command, (id,)) |
393 | 71 | self.__cur.execute(config.remove_desc_command, (id,)) | 162 | self.__cur.execute(config.remove_desc_command, (id,)) |
394 | 72 | self.__conn.commit() | 163 | self.__conn.commit() |
395 | @@ -94,6 +185,7 @@ | |||
396 | 94 | 185 | ||
397 | 95 | for val in self.__res_cursor: | 186 | for val in self.__res_cursor: |
398 | 96 | desc_cursor = self.__cur.execute(config.fetch_description, {"Id": val[0]}) | 187 | desc_cursor = self.__cur.execute(config.fetch_description, {"Id": val[0]}) |
399 | 188 | print(desc_cursor) | ||
400 | 97 | # Create the Localization Description | 189 | # Create the Localization Description |
401 | 98 | desc_list = [[desc[0], desc[1]] for desc in desc_cursor] | 190 | desc_list = [[desc[0], desc[1]] for desc in desc_cursor] |
402 | 99 | 191 | ||
403 | @@ -102,13 +194,13 @@ | |||
404 | 102 | 194 | ||
405 | 103 | trophy_list.append(trp) | 195 | trophy_list.append(trp) |
406 | 104 | 196 | ||
407 | 105 | print(trophy_list) | ||
408 | 106 | return trophy_list | 197 | return trophy_list |
409 | 107 | 198 | ||
410 | 108 | def _CreateTrophyDBus(self, desc_list, trp): | 199 | def _CreateTrophyDBus(self, desc_list, trp): |
411 | 109 | """ Create the DBus representation of Trophy which is to be sent | 200 | """ Create the DBus representation of Trophy which is to be sent |
412 | 110 | over DBus matching the signature a(ssaasssssisbxs) | 201 | over DBus matching the signature a(ssaasssssisbxs) |
413 | 111 | """ | 202 | """ |
414 | 203 | |||
415 | 112 | if trp[8] == 0: | 204 | if trp[8] == 0: |
416 | 113 | unlocked = 0 | 205 | unlocked = 0 |
417 | 114 | else: | 206 | else: |
418 | 115 | 207 | ||
419 | === modified file 'cheers/server.py' | |||
420 | --- cheers/server.py 2010-10-17 20:31:25 +0000 | |||
421 | +++ cheers/server.py 2010-10-27 12:43:44 +0000 | |||
422 | @@ -63,15 +63,20 @@ | |||
423 | 63 | global_monitor = global_dump.monitor_directory(gio.FILE_MONITOR_NONE, None) | 63 | global_monitor = global_dump.monitor_directory(gio.FILE_MONITOR_NONE, None) |
424 | 64 | global_monitor.connect("changed", self.directory_changed) | 64 | global_monitor.connect("changed", self.directory_changed) |
425 | 65 | 65 | ||
426 | 66 | if os.path.exists(config.global_trophy_path_local): | ||
427 | 67 | global_dump_local = gio.File(config.global_trophy_path_local) | ||
428 | 68 | global_monitor_local = global_dump_local.monitor_directory(gio.FILE_MONITOR_NONE, None) | ||
429 | 69 | global_monitor_local.connect("changed", self.directory_changed) | ||
430 | 70 | |||
431 | 66 | # Start the MainLoop | 71 | # Start the MainLoop |
432 | 67 | glib.MainLoop().run() | 72 | glib.MainLoop().run() |
433 | 68 | 73 | ||
434 | 69 | def directory_changed(self, monitor, file1, file2, evt_type): | 74 | def directory_changed(self, monitor, file1, file2, evt_type): |
435 | 70 | """ The callback for handling the directory changes notification """ | 75 | """ The callback for handling the directory changes notification """ |
436 | 71 | 76 | ||
440 | 72 | if (evt_type in (gio.FILE_MONITOR_EVENT_CREATED,)): | 77 | if (evt_type in (gio.FILE_MONITOR_EVENT_CREATED,)): |
441 | 73 | print "Changed:", file1, file2, evt_type | 78 | print "Changed:", file1, file2, evt_type |
442 | 74 | self.AddTrophy(file1.get_path()) | 79 | self.AddTrophy(file1.get_path()) |
443 | 75 | 80 | ||
444 | 76 | def AddTrophy(self, trophy_file): | 81 | def AddTrophy(self, trophy_file): |
445 | 77 | """ Read the JSON trophy files and register it """ | 82 | """ Read the JSON trophy files and register it """ |
446 | @@ -81,6 +86,7 @@ | |||
447 | 81 | json_data = json.load(fs) | 86 | json_data = json.load(fs) |
448 | 82 | fs.close() | 87 | fs.close() |
449 | 83 | 88 | ||
450 | 89 | self.__store.AddTrophy(json_data) | ||
451 | 84 | 90 | ||
452 | 85 | @dbus.service.method(config.CHEERS_BUS_NAME, in_signature='s') | 91 | @dbus.service.method(config.CHEERS_BUS_NAME, in_signature='s') |
453 | 86 | def DeleteTrophy(self, id): | 92 | def DeleteTrophy(self, id): |
454 | @@ -135,8 +141,8 @@ | |||
455 | 135 | 141 | ||
456 | 136 | 142 | ||
457 | 137 | 143 | ||
460 | 138 | @dbus.service.method(config.CHEERS_BUS_NAME, in_signature='ss') | 144 | @dbus.service.method(config.CHEERS_BUS_NAME, in_signature='s') |
461 | 139 | def UnAwardTrophy(self, id, setname): | 145 | def UnAwardTrophy(self, id): |
462 | 140 | """ Find the trophy to be unawarded, unaward it and send a async reply via event """ | 146 | """ Find the trophy to be unawarded, unaward it and send a async reply via event """ |
463 | 141 | 147 | ||
464 | 142 | trophies = self.__store.Search("trophy.id", id) | 148 | trophies = self.__store.Search("trophy.id", id) |