Merge lp:~mfisch/ubuntu-accomplishments-daemon/cleanup into lp:ubuntu-accomplishments-daemon
- cleanup
- Merge into accomplishments-daemon
Proposed by
Matt Fischer
Status: | Merged |
---|---|
Merged at revision: | 178 |
Proposed branch: | lp:~mfisch/ubuntu-accomplishments-daemon/cleanup |
Merge into: | lp:ubuntu-accomplishments-daemon |
Diff against target: |
902 lines (+169/-170) 8 files modified
accomplishments/daemon/api.py (+110/-71) accomplishments/daemon/app.py (+0/-15) accomplishments/daemon/dbusapi.py (+3/-8) accomplishments/util/__init__.py (+4/-33) accomplishments/util/accomplishments-daemon-config.py (+1/-1) accomplishments/util/dist.py (+2/-1) accomplishments/util/paths.py (+3/-2) bin/accomplishments-daemon (+46/-39) |
To merge this branch: | bzr merge lp:~mfisch/ubuntu-accomplishments-daemon/cleanup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Accomplishments Daemon Developers | Pending | ||
Review via email: mp+141144@code.launchpad.net |
Commit message
Description of the change
This commit cleans up the remaining pep8 issues and also removes a bunch of unused imports. Lastly it removes the old logging code, this code was replaced by the twisted logging stuff.
I used pyflakes to find the unused imports.
Also there is a shorter (by 300 lines) diff that excludes all the whitespace changes available here:
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 'accomplishments/daemon/api.py' |
2 | --- accomplishments/daemon/api.py 2012-12-12 21:02:59 +0000 |
3 | +++ accomplishments/daemon/api.py 2012-12-22 03:54:22 +0000 |
4 | @@ -20,22 +20,14 @@ |
5 | import datetime |
6 | import getpass |
7 | import glob |
8 | -#import gobject |
9 | +# import gobject |
10 | import gpgme |
11 | -import json |
12 | import os |
13 | -import pwd |
14 | -import subprocess |
15 | import time |
16 | import locale |
17 | from collections import deque |
18 | |
19 | -import dbus |
20 | -import dbus.service |
21 | - |
22 | from twisted.internet import defer, reactor |
23 | -from twisted.internet.protocol import ProcessProtocol |
24 | -from twisted.python import filepath |
25 | from twisted.python import log |
26 | |
27 | import xdg.BaseDirectory |
28 | @@ -53,7 +45,7 @@ |
29 | import accomplishments |
30 | from accomplishments import exceptions |
31 | from accomplishments.daemon import dbusapi |
32 | -from accomplishments.util import get_data_file, SubprocessReturnCodeProtocol |
33 | +from accomplishments.util import SubprocessReturnCodeProtocol |
34 | from accomplishments.util.paths import daemon_exec_dir, media_dir, module_dir1, module_dir2, installed, locale_dir |
35 | |
36 | gettext.bindtextdomain('accomplishments-daemon', locale_dir) |
37 | @@ -64,7 +56,8 @@ |
38 | # may happen to be in a completely different directory, if the daemon was |
39 | # installed using a non-default prefix. |
40 | if installed: |
41 | - os.environ["PYTHONPATH"] = module_dir1 + ":" + module_dir2 + ":" + os.environ["PYTHONPATH"] |
42 | + os.environ["PYTHONPATH"] = module_dir1 + ":" + module_dir2 + ":" + \ |
43 | + os.environ["PYTHONPATH"] |
44 | |
45 | LOCAL_USERNAME = getpass.getuser() |
46 | SCRIPT_DELAY = 900 |
47 | @@ -72,7 +65,7 @@ |
48 | STAGING_ID = "openiduser204307" # staging ID |
49 | PRODUCTION_ID = "openiduser155707" # production ID |
50 | |
51 | -#flags used for scripts_state |
52 | +# flags used for scripts_state |
53 | NOT_RUNNING = 0 |
54 | RUNNING = 1 |
55 | |
56 | @@ -156,7 +149,8 @@ |
57 | signal_ok='FolderCreated', success_filter=success_filter) |
58 | |
59 | self.parent.sd.offer_share( |
60 | - trophydir, self.parent.matrix_username, LOCAL_USERNAME + " Trophies Folder" |
61 | + trophydir, self.parent.matrix_username, LOCAL_USERNAME + |
62 | + " Trophies Folder" |
63 | + " (" + timeid + ")", "Modify") |
64 | log.msg( |
65 | "...share has been offered (" + trophydir + "" + ", " |
66 | @@ -180,7 +174,8 @@ |
67 | # XXX let's break this out into a separate folder-sharing method |
68 | log.msg("...the '%s' folder is not shared" % trophydir) |
69 | self.parent.sd.offer_share( |
70 | - trophydir, self.parent.matrix_username, LOCAL_USERNAME + " Trophies Folder" |
71 | + trophydir, self.parent.matrix_username, LOCAL_USERNAME + |
72 | + " Trophies Folder" |
73 | + " (" + timeid + ")", "Modify") |
74 | log.msg("...share has been offered (" + trophydir + "" + ", " |
75 | + self.parent.matrix_username + ", " + LOCAL_USERNAME + ")") |
76 | @@ -203,7 +198,7 @@ |
77 | return |
78 | |
79 | self.scripts_state = RUNNING |
80 | - |
81 | + |
82 | if not dbusapi.daemon_is_registered(): |
83 | return |
84 | |
85 | @@ -213,7 +208,8 @@ |
86 | |
87 | queuesize = len(self.parent.scripts_queue) |
88 | |
89 | - log.msg("--- Starting Running Scripts - %d items on the queue ---" % (queuesize)) |
90 | + log.msg("--- Starting Running Scripts - %d items on the queue ---" % |
91 | + (queuesize)) |
92 | timestart = time.time() |
93 | if not self.parent.test_mode: |
94 | self.parent.service.scriptrunner_start() |
95 | @@ -257,7 +253,7 @@ |
96 | queuesize = len(self.parent.scripts_queue) |
97 | |
98 | log.msg("The queue is now empty - stopping the scriptrunner.") |
99 | - |
100 | + |
101 | # XXX eventually the code in this method will be rewritten using |
102 | # deferreds; as such, we're going to have to be more clever regarding |
103 | # timing things... |
104 | @@ -291,7 +287,7 @@ |
105 | self.lang = locale.getdefaultlocale()[0] |
106 | |
107 | # use this to override the language for testing |
108 | - #self.lang = "pt_BR" |
109 | + # self.lang = "pt_BR" |
110 | self.accomlangs = [] |
111 | self.service = service |
112 | self.asyncapi = AsyncAPI(self) |
113 | @@ -346,7 +342,8 @@ |
114 | self.reload_accom_database() |
115 | |
116 | if not self.test_mode: |
117 | - self.sd.connect_signal("DownloadFinished", self._process_received_trophy_file) |
118 | + self.sd.connect_signal( |
119 | + "DownloadFinished", self._process_received_trophy_file) |
120 | |
121 | self._refresh_share_data() |
122 | |
123 | @@ -556,7 +553,8 @@ |
124 | for s in shares: |
125 | if s["other_username"] == self.matrix_username: |
126 | if s["subscribed"] == "True": |
127 | - matchingshares.append({"name": s["name"], "share_id": s["volume_id"]}) |
128 | + matchingshares.append( |
129 | + {"name": s["name"], "share_id": s["volume_id"]}) |
130 | |
131 | if len(matchingshares) > 1: |
132 | log.msg("Could not find unique active share.") |
133 | @@ -626,7 +624,8 @@ |
134 | |
135 | infoneeded = [] |
136 | # and prepend the path to the directory, where all extra-information |
137 | - # is stored [like: ~/.local/share/accomplishments/trophies/.extrainformation/] |
138 | + # is stored [like: |
139 | + # ~/.local/share/accomplishments/trophies/.extrainformation/] |
140 | trophyextrainfo = os.path.join( |
141 | self.trophies_path, ".extrainformation/") |
142 | |
143 | @@ -640,9 +639,11 @@ |
144 | # get the path to the directory of accomplishments set's |
145 | # "extrainformation" dir - it is useful, because it contains |
146 | # translated labels and descriptions |
147 | - accomextrainfo = os.path.join(self.accomDB[accom]['base-path'], "extrainformation") |
148 | + accomextrainfo = os.path.join( |
149 | + self.accomDB[accom]['base-path'], "extrainformation") |
150 | |
151 | - # a temporary variable, representing a single entry of the list this function returns |
152 | + # a temporary variable, representing a single entry of the list |
153 | + # this function returns |
154 | d = {} |
155 | |
156 | # Get collection name from accomOD |
157 | @@ -653,23 +654,30 @@ |
158 | |
159 | # For each needed piece of information: |
160 | for i in ei: |
161 | - label = self.accomDB[collection]['extra-information'][i]['label'] |
162 | - desc = self.accomDB[collection]['extra-information'][i]['description'] |
163 | - example = self.accomDB[collection]['extra-information'][i].get('example') |
164 | + label = self.accomDB[collection][ |
165 | + 'extra-information'][i]['label'] |
166 | + desc = self.accomDB[collection][ |
167 | + 'extra-information'][i]['description'] |
168 | + example = self.accomDB[collection][ |
169 | + 'extra-information'][i].get('example') |
170 | if example is None: |
171 | example = '' |
172 | - regex = self.accomDB[collection]['extra-information'][i].get('regex') |
173 | + regex = self.accomDB[collection][ |
174 | + 'extra-information'][i].get('regex') |
175 | if regex is None: |
176 | regex = '' |
177 | # we also need to know whether user has already set this item's value. |
178 | - # to do this, simply check whether trophies/.extrainformation/<item> file exists. |
179 | + # to do this, simply check whether |
180 | + # trophies/.extrainformation/<item> file exists. |
181 | try: |
182 | valuefile = open(os.path.join(trophyextrainfo, i)) |
183 | # if we got here without an exception, it means that the file exists |
184 | # so, we can read it's value |
185 | value = valuefile.readline() |
186 | - value = value.rstrip() # get rid of the tailing newline |
187 | - # and build up the dictionary of all data for a single ExtraInformation field |
188 | + value = value.rstrip( |
189 | + ) # get rid of the tailing newline |
190 | + # and build up the dictionary of all data for a single |
191 | + # ExtraInformation field |
192 | d = { |
193 | "collection": collection, |
194 | "needs-information": i, |
195 | @@ -679,7 +687,9 @@ |
196 | "regex": regex, |
197 | "value": value} |
198 | except IOError as e: |
199 | - # we got an exception, so it seems that the file is not present - we'll use "" as the value, to indicate that it's empty |
200 | + # we got an exception, so it seems that the file is not |
201 | + # present - we'll use "" as the value, to indicate that |
202 | + # it's empty |
203 | d = { |
204 | "collection": collection, |
205 | "needs-information": i, |
206 | @@ -689,11 +699,13 @@ |
207 | "regex": regex, |
208 | "value": ""} |
209 | |
210 | - # since the collected all data related to this particular ExtraInformation field, append it to the list |
211 | + # since the collected all data related to this particular |
212 | + # ExtraInformation field, append it to the list |
213 | infoneeded.append(d) |
214 | |
215 | # at this moment the infoneeded list will be ready, but full of duplicates, |
216 | - # for the items have been added multiple times, if they are mentioned in more then one .accomplishment file |
217 | + # for the items have been added multiple times, if they are mentioned |
218 | + # in more then one .accomplishment file |
219 | final = [] |
220 | for x in infoneeded: # for each item in the original list... |
221 | if x not in final: # ...add it to the outputted list only if it hadn't been added yet. |
222 | @@ -713,16 +725,17 @@ |
223 | [{"collection" : "ubuntu-community", "needs-information" : "askubuntu-user-url", "label" : "AskUbuntu user profile URL", "description" : "The URL of your AskUbuntu usr profile page", "example" : "http://askubuntu.com/users/42/nick", "regex" : "", "value" : ""}] |
224 | |
225 | """ |
226 | - #fetch a full list of ExtraInformation |
227 | + # fetch a full list of ExtraInformation |
228 | data = self.get_all_extra_information() |
229 | - #now we need to unsort the data just to output these entries, that have value == "" |
230 | - #this way we can return a list of ExtraInformation fields, that have not been write_config_file_item |
231 | + # now we need to unsort the data just to output these entries, that have value == "" |
232 | + # this way we can return a list of ExtraInformation fields, that have |
233 | + # not been write_config_file_item |
234 | result = [] |
235 | for i in data: # for each ExtraInformation in the full list |
236 | if not i['value']: # if the value string is empty, so this ExtraInformation field have not been yet set |
237 | i.pop('value') # remove the 'value' field (it's empty anyway) |
238 | result.append(i) # add this entry to the resulting list |
239 | - #do not add these fields, that have some value |
240 | + # do not add these fields, that have some value |
241 | |
242 | return result |
243 | |
244 | @@ -732,14 +745,16 @@ |
245 | does not overwrite any existing data |
246 | """ |
247 | |
248 | - # XXX this should be removed as we are using write_extra_information_file |
249 | + # XXX this should be removed as we are using |
250 | + # write_extra_information_file |
251 | log.msg("Creating Extra Information file: %s, %s" % (item, data)) |
252 | extrainfodir = os.path.join(self.trophies_path, ".extrainformation/") |
253 | |
254 | if not os.path.isdir(extrainfodir): |
255 | os.makedirs(extrainfodir) |
256 | try: |
257 | - open(os.path.join(extrainfodir, item)) # if the file already exists, do not overwrite it |
258 | + open(os.path.join(extrainfodir, item)) |
259 | + # if the file already exists, do not overwrite it |
260 | pass |
261 | except IOError as e: |
262 | f = open(os.path.join(extrainfodir, item), 'w') |
263 | @@ -787,11 +802,12 @@ |
264 | os.makedirs(extrainfodir) |
265 | |
266 | if data: |
267 | - f = open(os.path.join(extrainfodir, item), 'w') # will trunkate the file, in case it exist |
268 | + f = open(os.path.join(extrainfodir, item), 'w') |
269 | + # will trunkate the file, in case it exist |
270 | f.write(data) |
271 | f.close() |
272 | else: |
273 | - #file would be empty, remove it instead |
274 | + # file would be empty, remove it instead |
275 | os.remove(os.path.join(extrainfodir, item)) |
276 | |
277 | # Returns True if all extra information is available for an accom, |
278 | @@ -864,7 +880,7 @@ |
279 | data = f.read() |
280 | final = [{item: data, "label": label}] |
281 | except IOError as e: |
282 | - #print "No data." |
283 | + # print "No data." |
284 | final = [{item: "", "label": label}] |
285 | return final |
286 | |
287 | @@ -905,7 +921,8 @@ |
288 | for collection in collections: |
289 | # For each collection... |
290 | if collection in self.accomDB: |
291 | - # This collection has already been loaded from another install path! |
292 | + # This collection has already been loaded from another |
293 | + # install path! |
294 | continue |
295 | |
296 | collpath = os.path.join(path, collection) |
297 | @@ -917,7 +934,8 @@ |
298 | |
299 | if not (cfg.has_option("general", "langdefault") and cfg.has_option("general", "name")): |
300 | print aboutpath |
301 | - raise LookupError("Accomplishment collection with invalid ABOUT file ") |
302 | + raise LookupError( |
303 | + "Accomplishment collection with invalid ABOUT file ") |
304 | |
305 | langdefault = cfg.get("general", "langdefault") |
306 | collectionname = cfg.get("general", "name") |
307 | @@ -934,14 +952,16 @@ |
308 | accompath = os.path.join(langdefaultpath, accomset) |
309 | accomcfg = ConfigParser.RawConfigParser() |
310 | # check if there is a translated version... |
311 | - translatedpath = os.path.join(os.path.join(collpath, self.lang), accomset) |
312 | + translatedpath = os.path.join( |
313 | + os.path.join(collpath, self.lang), accomset) |
314 | if os.path.exists(translatedpath): |
315 | # yes, so use the translated file |
316 | readpath = translatedpath |
317 | langused = self.lang |
318 | else: |
319 | # no. maybe there is a shorter language code? |
320 | - translatedpath = os.path.join(os.path.join(collpath, self.lang.split("_")[0]), accomset) |
321 | + translatedpath = os.path.join(os.path.join( |
322 | + collpath, self.lang.split("_")[0]), accomset) |
323 | if os.path.exists(translatedpath): |
324 | readpath = translatedpath |
325 | langused = self.lang.split("_")[0] |
326 | @@ -975,7 +995,8 @@ |
327 | accomdata['categories'] = [] |
328 | for cat in cats: |
329 | catsplitted = cat.rstrip().lstrip().split(":") |
330 | - accomdata['categories'].append(cat.rstrip().lstrip()) |
331 | + accomdata['categories'].append( |
332 | + cat.rstrip().lstrip()) |
333 | if catsplitted[0] in collcategories: |
334 | pass |
335 | else: |
336 | @@ -983,7 +1004,8 @@ |
337 | if len(catsplitted) > 1: |
338 | # category + subcategory |
339 | if catsplitted[1] not in collcategories[catsplitted[0]]: |
340 | - collcategories[catsplitted[0]].append(catsplitted[1]) |
341 | + collcategories[catsplitted[ |
342 | + 0]].append(catsplitted[1]) |
343 | del accomdata['category'] |
344 | else: |
345 | accomdata['categories'] = [] |
346 | @@ -1025,7 +1047,8 @@ |
347 | "Parse error is: %s" % (readpath, e.message)) |
348 | continue |
349 | |
350 | - accomdata = dict(accomcfg._sections["accomplishment"]) |
351 | + accomdata = dict( |
352 | + accomcfg._sections["accomplishment"]) |
353 | accomID = collection + "/" + accomfile[:-15] |
354 | if 'author' in accomdata: |
355 | collauthors.add(accomdata['author']) |
356 | @@ -1041,8 +1064,10 @@ |
357 | categories = [] |
358 | accomdata['categories'] = [] |
359 | for cat in cats: |
360 | - catsplitted = cat.rstrip().lstrip().split(":") |
361 | - accomdata['categories'].append(cat.rstrip().lstrip()) |
362 | + catsplitted = cat.rstrip( |
363 | + ).lstrip().split(":") |
364 | + accomdata['categories'].append( |
365 | + cat.rstrip().lstrip()) |
366 | if catsplitted[0] in collcategories: |
367 | pass |
368 | else: |
369 | @@ -1050,7 +1075,8 @@ |
370 | if len(catsplitted) > 1: |
371 | # category + subcategory |
372 | if catsplitted[1] not in collcategories[catsplitted[0]]: |
373 | - collcategories[catsplitted[0]].append(catsplitted[1]) |
374 | + collcategories[catsplitted[ |
375 | + 0]].append(catsplitted[1]) |
376 | del accomdata['category'] |
377 | else: |
378 | accomdata['categories'] = [] |
379 | @@ -1076,7 +1102,8 @@ |
380 | if eicfg.has_option("description", self.lang): |
381 | description = eicfg.get("description", self.lang) |
382 | elif eicfg.has_option("description", self.lang.split("_")[0]): |
383 | - description = eicfg.get("description", self.lang.split("_")[0]) |
384 | + description = eicfg.get( |
385 | + "description", self.lang.split("_")[0]) |
386 | else: |
387 | description = eicfg.get("description", langdefault) |
388 | |
389 | @@ -1108,7 +1135,7 @@ |
390 | self._update_all_locked_and_accomplished_statuses() |
391 | |
392 | self.create_all_trophy_icons() |
393 | - |
394 | + |
395 | if not self.test_mode: |
396 | self.service.accoms_collections_reloaded() |
397 | # Uncomment following for debugging |
398 | @@ -1553,7 +1580,8 @@ |
399 | |
400 | # Check if is hasn't been already accomplished |
401 | if self.get_accom_is_accomplished(accomID): |
402 | - log.msg("Not accomplishing " + accomID + ", it has already been accomplished.") |
403 | + log.msg("Not accomplishing " + accomID + |
404 | + ", it has already been accomplished.") |
405 | return True # success |
406 | |
407 | # Check if this accomplishment is unlocked |
408 | @@ -1641,23 +1669,28 @@ |
409 | log.msg(type(value)) |
410 | if value == True: |
411 | log.msg("setting") |
412 | - command = os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --start" |
413 | + command = os.path.join( |
414 | + daemon_exec_dir, "accomplishments-daemon") + " --start" |
415 | filetext = "[Desktop Entry]\n\ |
416 | Type=Application\n\ |
417 | Encoding=UTF-8\n\ |
418 | Name=Accomplishments Daemon\n\ |
419 | Exec=" + command + "\n\ |
420 | NoDisplay=true" |
421 | - filename = os.path.join(self.dir_autostart, "accomplishments-daemon.desktop") |
422 | + filename = os.path.join( |
423 | + self.dir_autostart, "accomplishments-daemon.desktop") |
424 | file = open(filename, "w") |
425 | file.write(filetext) |
426 | file.close |
427 | - self.write_config_file_item("config", "daemon_sessionstart", "true") |
428 | + self.write_config_file_item( |
429 | + "config", "daemon_sessionstart", "true") |
430 | elif value == False: |
431 | - filename = os.path.join(self.dir_autostart, "accomplishments-daemon.desktop") |
432 | + filename = os.path.join( |
433 | + self.dir_autostart, "accomplishments-daemon.desktop") |
434 | if os.path.exists(filename): |
435 | os.remove(filename) |
436 | - self.write_config_file_item("config", "daemon_sessionstart", "false") |
437 | + self.write_config_file_item( |
438 | + "config", "daemon_sessionstart", "false") |
439 | |
440 | def get_daemon_session_start(self): |
441 | return self.get_config_value("config", "daemon_sessionstart") |
442 | @@ -1685,7 +1718,8 @@ |
443 | with open(cfile, 'wb') as configfile: |
444 | config.write(configfile) |
445 | |
446 | - # restart SyncDaemonTool to use new settings immediately, fixes LP#1011903 |
447 | + # restart SyncDaemonTool to use new settings immediately, fixes |
448 | + # LP#1011903 |
449 | self.ubuntuone_restart_syncdaemontool() |
450 | |
451 | # XXX - NEEDS UNIT TEST |
452 | @@ -1724,7 +1758,7 @@ |
453 | |
454 | def _display_accomplished_bubble(self, accomID): |
455 | if self.show_notifications == True and useNotify and ( |
456 | - Notify.is_initted() or Notify.init("icon-summary-body")): |
457 | + Notify.is_initted() or Notify.init("icon-summary-body")): |
458 | n = Notify.Notification.new( |
459 | _("You have accomplished something!"), |
460 | self.get_accom_title(accomID), |
461 | @@ -1736,7 +1770,7 @@ |
462 | unlocked = len(self.list_depending_on(accomID)) |
463 | if unlocked is not 0: |
464 | if self.show_notifications == True and useNotify and ( |
465 | - Notify.is_initted() or Notify.init("icon-summary-body")): |
466 | + Notify.is_initted() or Notify.init("icon-summary-body")): |
467 | message = (N_("You have unlocked %s new opportunity.", "You have unlocked %s new opportunities.", unlocked) % str(unlocked)) |
468 | n = Notify.Notification.new( |
469 | _("Opportunities Unlocked!"), message, |
470 | @@ -1750,11 +1784,11 @@ |
471 | |
472 | def _get_is_asc_correct(self, filepath): |
473 | if not os.path.exists(filepath): |
474 | - log.msg("Cannot check if signature is correct, because file"\ |
475 | + log.msg("Cannot check if signature is correct, because file" |
476 | "%s does not exist" % filepath) |
477 | return False |
478 | elif not os.path.exists(filepath[:-4]): |
479 | - log.msg("Cannot check if signature is correct, because file"\ |
480 | + log.msg("Cannot check if signature is correct, because file" |
481 | "%s does not exist" % filepath[:-4]) |
482 | return False |
483 | else: |
484 | @@ -1782,7 +1816,8 @@ |
485 | return False |
486 | else: |
487 | # Correct! |
488 | - # result = {'timestamp': sig[0].timestamp, 'signer': sig[0].fpr} |
489 | + # result = {'timestamp': sig[0].timestamp, 'signer': |
490 | + # sig[0].fpr} |
491 | return True |
492 | |
493 | def _check_if_accom_is_accomplished(self, accomID): |
494 | @@ -1817,13 +1852,15 @@ |
495 | def _update_all_locked_and_accomplished_statuses(self): |
496 | accoms = self.list_accoms() |
497 | for accom in accoms: |
498 | - self.accomDB[accom]['accomplished'] = self._check_if_accom_is_accomplished(accom) |
499 | + self.accomDB[accom][ |
500 | + 'accomplished'] = self._check_if_accom_is_accomplished(accom) |
501 | if self.accomDB[accom]['accomplished'] == True: |
502 | self.accomDB[accom]['date-accomplished'] = self._get_trophy_date_accomplished(accom) |
503 | else: |
504 | self.accomDB[accom]['date-accomplished'] = "None" |
505 | for accom in accoms: |
506 | - self.accomDB[accom]['locked'] = self._check_if_accom_is_locked(accom) |
507 | + self.accomDB[accom][ |
508 | + 'locked'] = self._check_if_accom_is_locked(accom) |
509 | |
510 | # XXX - NEEDS UNIT TEST |
511 | def _get_trophy_date_accomplished(self, accomID): |
512 | @@ -1844,18 +1881,20 @@ |
513 | # Marks accomplishments as accomplished in the accomDB, and |
514 | # returns a list of accomIDs that just got unlocked. |
515 | self.accomDB[accomID]['accomplished'] = True |
516 | - self.accomDB[accomID]['date-accomplished'] = self._get_trophy_date_accomplished(accomID) |
517 | + self.accomDB[accomID][ |
518 | + 'date-accomplished'] = self._get_trophy_date_accomplished(accomID) |
519 | accoms = self.list_depending_on(accomID) |
520 | res = [] |
521 | for accom in accoms: |
522 | before = self.accomDB[accom]['locked'] |
523 | - self.accomDB[accom]['locked'] = self._check_if_accom_is_locked(accom) |
524 | + self.accomDB[accom][ |
525 | + 'locked'] = self._check_if_accom_is_locked(accom) |
526 | # If it just got unlocked... |
527 | if (before == True and self.accomDB[accom]['locked'] == False): |
528 | res.append(accom) |
529 | return res |
530 | |
531 | - #Other significant system functions |
532 | + # Other significant system functions |
533 | |
534 | def get_API_version(self): |
535 | return "0.2" |
536 | |
537 | === modified file 'accomplishments/daemon/app.py' |
538 | --- accomplishments/daemon/app.py 2012-08-17 18:22:47 +0000 |
539 | +++ accomplishments/daemon/app.py 2012-12-22 03:54:22 +0000 |
540 | @@ -1,24 +1,9 @@ |
541 | from optparse import OptionParser |
542 | |
543 | -from twisted.application.internet import TimerService |
544 | from twisted.application.service import Application |
545 | |
546 | from accomplishments.daemon import dbusapi |
547 | from accomplishments.daemon import service |
548 | -from accomplishments.daemon import api |
549 | - |
550 | - |
551 | -# XXX these won't work with twistd; we need to write a twistd plugin to support |
552 | -# additional command line options. |
553 | -def parse_options(): |
554 | - parser = OptionParser() |
555 | - parser.set_defaults(suppress_notifications=False) |
556 | - parser.add_option("--trophies-path", dest="trophies_path", default=None) |
557 | - parser.add_option("--accomplishments-path", dest="accomplishments_installpaths", |
558 | - default=None) |
559 | - parser.add_option("--suppress-notifications", action="store_true", |
560 | - dest="suppress_notifications") |
561 | - return parser.parse_args() |
562 | |
563 | |
564 | def applicationFactory(app_name="", bus_name="", main_loop=None, |
565 | |
566 | === modified file 'accomplishments/daemon/dbusapi.py' |
567 | --- accomplishments/daemon/dbusapi.py 2012-11-29 19:33:30 +0000 |
568 | +++ accomplishments/daemon/dbusapi.py 2012-12-22 03:54:22 +0000 |
569 | @@ -11,12 +11,8 @@ |
570 | """ |
571 | |
572 | import dbus |
573 | - |
574 | -from twisted.python import log |
575 | - |
576 | from accomplishments.daemon import service |
577 | |
578 | - |
579 | def daemon_is_registered(): |
580 | try: |
581 | obj = dbus.SessionBus().get_object( |
582 | @@ -408,10 +404,10 @@ |
583 | ["Launchpad"] |
584 | """ |
585 | return self.api.get_accom_categories(accomID) |
586 | - |
587 | + |
588 | @dbus.service.method(dbus_interface='org.ubuntu.accomplishments', |
589 | in_signature="s", out_signature="as") |
590 | - def get_accom_keywords(self,accomID): |
591 | + def get_accom_keywords(self, accomID): |
592 | return self.api.get_accom_keywords(accomID) |
593 | |
594 | @dbus.service.method(dbus_interface='org.ubuntu.accomplishments', |
595 | @@ -911,12 +907,11 @@ |
596 | def create_all_trophy_icons(self): |
597 | return self.api.create_all_trophy_icons() |
598 | |
599 | - |
600 | # XXX this looks like an unintentional duplicate of the "other" |
601 | # trophy_received... I've moved them here together so that someone in the |
602 | # know (Jono?) can clarify and remove the one that's not needed |
603 | #@dbus.service.signal(dbus_interface='org.ubuntu.accomplishments') |
604 | - #def trophy_received(self, trophy): |
605 | + # def trophy_received(self, trophy): |
606 | # pass |
607 | @dbus.service.signal(dbus_interface='org.ubuntu.accomplishments') |
608 | def trophy_received(self, trophy): |
609 | |
610 | === modified file 'accomplishments/util/__init__.py' |
611 | --- accomplishments/util/__init__.py 2012-08-17 18:22:47 +0000 |
612 | +++ accomplishments/util/__init__.py 2012-12-22 03:54:22 +0000 |
613 | @@ -1,4 +1,3 @@ |
614 | -import logging |
615 | import optparse |
616 | import os |
617 | |
618 | @@ -22,40 +21,11 @@ |
619 | def get_version(): |
620 | return config.__version__ |
621 | |
622 | - |
623 | -class NullHandler(logging.Handler): |
624 | - """ |
625 | - """ |
626 | - def emit(self, record): |
627 | - pass |
628 | - |
629 | - |
630 | -def set_up_logging(opts): |
631 | - # add a handler to prevent basicConfig |
632 | - root = logging.getLogger() |
633 | - null_handler = NullHandler() |
634 | - root.addHandler(null_handler) |
635 | - |
636 | - formatter = logging.Formatter( |
637 | - "%(levelname)s:%(name)s: %(funcName)s() '%(message)s'") |
638 | - |
639 | - logger = logging.getLogger('accomplishments-daemon') |
640 | - logger_sh = logging.StreamHandler() |
641 | - logger_sh.setFormatter(formatter) |
642 | - logger.addHandler(logger_sh) |
643 | - |
644 | - # Set the logging level to show debug messages. |
645 | - if opts.verbose: |
646 | - logger.setLevel(logging.DEBUG) |
647 | - logger.debug('logging enabled') |
648 | - if opts.verbose > 1: |
649 | - logger.setLevel(logging.DEBUG) |
650 | - |
651 | - |
652 | def get_data_path(): |
653 | # XXX: NOTE: This function will most likely work incorrectly when daemon is installed in non-default path. |
654 | # Luckily, this function is no longer used anywhere. |
655 | - # If you feel you need to get this path, please refer to utils/paths.py instead. |
656 | + # If you feel you need to get this path, please refer to utils/paths.py |
657 | + # instead. |
658 | """Retrieve accomplishments-daemon data path |
659 | |
660 | This path is by default <accomplishments_daemon_lib_path>/../data/ in trunk |
661 | @@ -64,7 +34,8 @@ |
662 | """ |
663 | |
664 | # Get pathname absolute or relative. |
665 | - path = os.path.join(accomplishments.__path__[0], config.__accomplishments_daemon_data_directory__) |
666 | + path = os.path.join(accomplishments.__path__[0], |
667 | + config.__accomplishments_daemon_data_directory__) |
668 | abs_data_path = os.path.abspath(path) |
669 | log.msg("MODULE DIR") |
670 | log.msg(accomplishments.__path__[0]) |
671 | |
672 | === modified file 'accomplishments/util/accomplishments-daemon-config.py' |
673 | --- accomplishments/util/accomplishments-daemon-config.py 2012-08-17 18:37:28 +0000 |
674 | +++ accomplishments/util/accomplishments-daemon-config.py 2012-12-22 03:54:22 +0000 |
675 | @@ -18,7 +18,7 @@ |
676 | # files). By default, this is ../data, relative your trunk layout |
677 | __accomplishments_daemon_data_directory__ = '../data/' |
678 | __license__ = '' |
679 | -__version__ = '0.1' |
680 | +__version__ = '0.3' |
681 | |
682 | import os |
683 | |
684 | |
685 | === modified file 'accomplishments/util/dist.py' |
686 | --- accomplishments/util/dist.py 2012-08-17 18:37:28 +0000 |
687 | +++ accomplishments/util/dist.py 2012-12-22 03:54:22 +0000 |
688 | @@ -21,7 +21,8 @@ |
689 | def update_config(values={}): |
690 | oldvalues = {} |
691 | try: |
692 | - fin = file('accomplishments/util/accomplishments-daemon-config.py', 'r') |
693 | + fin = file( |
694 | + 'accomplishments/util/accomplishments-daemon-config.py', 'r') |
695 | fout = file(fin.name + '.new', 'w') |
696 | |
697 | for line in fin: |
698 | |
699 | === modified file 'accomplishments/util/paths.py' |
700 | --- accomplishments/util/paths.py 2012-08-17 18:37:28 +0000 |
701 | +++ accomplishments/util/paths.py 2012-12-22 03:54:22 +0000 |
702 | @@ -20,7 +20,7 @@ |
703 | basepath = os.path.split(os.path.split(os.path.split(branchpath)[0])[0])[0] |
704 | # basepath should equal to prefix given on installation. |
705 | |
706 | - #print "Daemon seems to be installed to: " + basepath |
707 | + # print "Daemon seems to be installed to: " + basepath |
708 | |
709 | # finally, setting these significant data directories... |
710 | systemdata_dir = os.path.join(basepath, 'share/accomplishments-daemon') |
711 | @@ -41,7 +41,8 @@ |
712 | # using branch root directory as the base path |
713 | basepath = branchpath |
714 | |
715 | - #print "Daemon seems to be run not installed, branch base path used: " + basepath |
716 | + # print "Daemon seems to be run not installed, branch base path used: " + |
717 | + # basepath |
718 | |
719 | # finally, setting these significant data directories... |
720 | systemdata_dir = os.path.join(basepath, 'data/daemon') |
721 | |
722 | === modified file 'bin/accomplishments-daemon' |
723 | --- bin/accomplishments-daemon 2012-11-21 06:46:02 +0000 |
724 | +++ bin/accomplishments-daemon 2012-12-22 03:54:22 +0000 |
725 | @@ -3,12 +3,13 @@ |
726 | import sys |
727 | import os |
728 | |
729 | -# Importing from accomplishments.{daemon,util} would fail, if the path |
730 | +# Importing from accomplishments.{daemon,util} would fail, if the path |
731 | # is set incorrectly. |
732 | # We need to ensure that the script will load the correct version of |
733 | # accomplishment.* that is installed with this script. |
734 | scriptpath = os.path.abspath(__file__) |
735 | -# basepaths shall be equal to prefix used while installing - if the application is run from source, it does not really matter. |
736 | +# basepaths shall be equal to prefix used while installing - if the |
737 | +# application is run from source, it does not really matter. |
738 | basepath = os.path.split(os.path.split(scriptpath)[0])[0] |
739 | sys.path.insert(0, basepath) |
740 | sys.path.insert(0, basepath + "/lib/python2.7") |
741 | @@ -18,18 +19,23 @@ |
742 | # This is a global variable |
743 | pidfile_path = None |
744 | |
745 | + |
746 | def main(): |
747 | # This part of code is executed if the script is run directly. |
748 | import argparse |
749 | - parser = argparse.ArgumentParser(description='Launches the accomplishments daemon.') |
750 | + parser = argparse.ArgumentParser( |
751 | + description='Launches the accomplishments daemon.') |
752 | mode = parser.add_mutually_exclusive_group() |
753 | - mode.add_argument('--start',action='store_true',help="Launch the accomplishments daemon (default option when run without arguments).") |
754 | - mode.add_argument('--stop',action='store_true',help="Stop the daemon gracefully.") |
755 | - mode.add_argument('--restart','-r',action='store_true',help="Restart the daemon.") |
756 | - mode.add_argument('--reload',action='store_true',help="Reload accomplishments collections.") |
757 | - parser.add_argument('-f','--foreground',action='store_true',help="When starting the daemon, run it in the foreground, with logs directed to stdout.") |
758 | + mode.add_argument('--start', action='store_true', help="Launch the accomplishments daemon (default option when run without arguments).") |
759 | + mode.add_argument( |
760 | + '--stop', action='store_true', help="Stop the daemon gracefully.") |
761 | + mode.add_argument( |
762 | + '--restart', '-r', action='store_true', help="Restart the daemon.") |
763 | + mode.add_argument('--reload', action='store_true', |
764 | + help="Reload accomplishments collections.") |
765 | + parser.add_argument('-f', '--foreground', action='store_true', help="When starting the daemon, run it in the foreground, with logs directed to stdout.") |
766 | args = parser.parse_args() |
767 | - |
768 | + |
769 | import xdg.BaseDirectory |
770 | try: |
771 | rootdir = os.environ['ACCOMPLISHMENTS_ROOT_DIR'] |
772 | @@ -38,44 +44,44 @@ |
773 | except KeyError: |
774 | cache_dir = os.path.join( |
775 | xdg.BaseDirectory.xdg_cache_home, "accomplishments") |
776 | - |
777 | + |
778 | global pidfile_path |
779 | - pidfile_path = os.path.join(cache_dir,"accomplishments-daemon.pid") |
780 | - |
781 | - launchdaemon = False |
782 | + pidfile_path = os.path.join(cache_dir, "accomplishments-daemon.pid") |
783 | + |
784 | + launchdaemon = False |
785 | if args.start or not (args.start or args.stop or args.reload or args.restart): |
786 | # Start the daemon. |
787 | - |
788 | + |
789 | from accomplishments.util.paths import daemon_exec_dir |
790 | # Check if the daemon is already running. |
791 | if is_daemon_running(): |
792 | print "The daemon is already running." |
793 | return |
794 | - |
795 | + |
796 | # The daemon is not running. |
797 | launchdaemon = True |
798 | - |
799 | + |
800 | elif args.stop: |
801 | # Stop the daemon |
802 | if not is_daemon_running(): |
803 | print "The daemon is not running." |
804 | return |
805 | print "Stopping the daemon..." |
806 | - |
807 | + |
808 | from accomplishments.daemon import dbusapi |
809 | api = dbusapi.Accomplishments() |
810 | api.stop_daemon() |
811 | - |
812 | + |
813 | elif args.reload: |
814 | if not is_daemon_running(): |
815 | print "The daemon is not running." |
816 | return |
817 | print "Reloading accomplishments collections." |
818 | - |
819 | + |
820 | from accomplishments.daemon import dbusapi |
821 | api = dbusapi.Accomplishments() |
822 | api.reload_accom_database() |
823 | - |
824 | + |
825 | elif args.restart: |
826 | from accomplishments.util.paths import daemon_exec_dir |
827 | # Check if the daemon is already running. |
828 | @@ -86,54 +92,55 @@ |
829 | from accomplishments.daemon import dbusapi |
830 | api = dbusapi.Accomplishments() |
831 | api.stop_daemon() |
832 | - |
833 | + |
834 | launchdaemon = True |
835 | - |
836 | + |
837 | if launchdaemon: |
838 | print "Launching the daemon..." |
839 | # Create the cache directories. |
840 | if not os.path.exists(cache_dir): |
841 | os.makedirs(cache_dir) |
842 | - if not os.path.exists(os.path.join(cache_dir,"logs")): |
843 | - os.makedirs(os.path.join(cache_dir,"logs")) |
844 | - |
845 | + if not os.path.exists(os.path.join(cache_dir, "logs")): |
846 | + os.makedirs(os.path.join(cache_dir, "logs")) |
847 | + |
848 | # Remove the pid file if for some reasons it's still present. |
849 | if os.path.exists(pidfile_path): |
850 | - os.remove(pidfile_path) |
851 | - |
852 | + os.remove(pidfile_path) |
853 | + |
854 | if not args.foreground: |
855 | command = "twistd -y " + os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --logfile=" + os.path.join(cache_dir, "logs", "daemon.log") + " --pidfile=" + pidfile_path |
856 | else: |
857 | command = "twistd -noy " + os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --pidfile=" + pidfile_path |
858 | - |
859 | - #print command |
860 | - |
861 | + |
862 | + # print command |
863 | + |
864 | os.system(command) |
865 | - |
866 | + |
867 | + |
868 | def is_daemon_running(): |
869 | from accomplishments.daemon.dbusapi import daemon_is_registered |
870 | return daemon_is_registered() |
871 | - |
872 | - |
873 | -if __name__=="__main__": |
874 | + |
875 | + |
876 | +if __name__ == "__main__": |
877 | # If run directly... |
878 | main() |
879 | - |
880 | -if __name__=="__builtin__": |
881 | + |
882 | +if __name__ == "__builtin__": |
883 | # This part of code is executed only if the script is run by twistd. |
884 | # It is responsible for setting up and launching the twistd daemon. |
885 | - |
886 | + |
887 | # This piece of code cannot be wrapped inside a function, as silly |
888 | # twistd blindly searches fora global variable named "application", |
889 | # and therefore while this code must be exposed. |
890 | - |
891 | + |
892 | # Reactor has to be installed before any import statements. |
893 | from twisted.internet import gireactor |
894 | gireactor.install() |
895 | |
896 | from accomplishments.daemon import app |
897 | from accomplishments.util import paths |
898 | - |
899 | + |
900 | # Ensure the sync daemon is running. The following command can be run in the |
901 | # background (&), because it would block the daemon from running for few |
902 | # seconds, while the syncdaemon will not be needed immediatelly after |