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 | 20 | import datetime | 20 | import datetime |
6 | 21 | import getpass | 21 | import getpass |
7 | 22 | import glob | 22 | import glob |
9 | 23 | #import gobject | 23 | # import gobject |
10 | 24 | import gpgme | 24 | import gpgme |
11 | 25 | import json | ||
12 | 26 | import os | 25 | import os |
13 | 27 | import pwd | ||
14 | 28 | import subprocess | ||
15 | 29 | import time | 26 | import time |
16 | 30 | import locale | 27 | import locale |
17 | 31 | from collections import deque | 28 | from collections import deque |
18 | 32 | 29 | ||
19 | 33 | import dbus | ||
20 | 34 | import dbus.service | ||
21 | 35 | |||
22 | 36 | from twisted.internet import defer, reactor | 30 | from twisted.internet import defer, reactor |
23 | 37 | from twisted.internet.protocol import ProcessProtocol | ||
24 | 38 | from twisted.python import filepath | ||
25 | 39 | from twisted.python import log | 31 | from twisted.python import log |
26 | 40 | 32 | ||
27 | 41 | import xdg.BaseDirectory | 33 | import xdg.BaseDirectory |
28 | @@ -53,7 +45,7 @@ | |||
29 | 53 | import accomplishments | 45 | import accomplishments |
30 | 54 | from accomplishments import exceptions | 46 | from accomplishments import exceptions |
31 | 55 | from accomplishments.daemon import dbusapi | 47 | from accomplishments.daemon import dbusapi |
33 | 56 | from accomplishments.util import get_data_file, SubprocessReturnCodeProtocol | 48 | from accomplishments.util import SubprocessReturnCodeProtocol |
34 | 57 | from accomplishments.util.paths import daemon_exec_dir, media_dir, module_dir1, module_dir2, installed, locale_dir | 49 | from accomplishments.util.paths import daemon_exec_dir, media_dir, module_dir1, module_dir2, installed, locale_dir |
35 | 58 | 50 | ||
36 | 59 | gettext.bindtextdomain('accomplishments-daemon', locale_dir) | 51 | gettext.bindtextdomain('accomplishments-daemon', locale_dir) |
37 | @@ -64,7 +56,8 @@ | |||
38 | 64 | # may happen to be in a completely different directory, if the daemon was | 56 | # may happen to be in a completely different directory, if the daemon was |
39 | 65 | # installed using a non-default prefix. | 57 | # installed using a non-default prefix. |
40 | 66 | if installed: | 58 | if installed: |
42 | 67 | os.environ["PYTHONPATH"] = module_dir1 + ":" + module_dir2 + ":" + os.environ["PYTHONPATH"] | 59 | os.environ["PYTHONPATH"] = module_dir1 + ":" + module_dir2 + ":" + \ |
43 | 60 | os.environ["PYTHONPATH"] | ||
44 | 68 | 61 | ||
45 | 69 | LOCAL_USERNAME = getpass.getuser() | 62 | LOCAL_USERNAME = getpass.getuser() |
46 | 70 | SCRIPT_DELAY = 900 | 63 | SCRIPT_DELAY = 900 |
47 | @@ -72,7 +65,7 @@ | |||
48 | 72 | STAGING_ID = "openiduser204307" # staging ID | 65 | STAGING_ID = "openiduser204307" # staging ID |
49 | 73 | PRODUCTION_ID = "openiduser155707" # production ID | 66 | PRODUCTION_ID = "openiduser155707" # production ID |
50 | 74 | 67 | ||
52 | 75 | #flags used for scripts_state | 68 | # flags used for scripts_state |
53 | 76 | NOT_RUNNING = 0 | 69 | NOT_RUNNING = 0 |
54 | 77 | RUNNING = 1 | 70 | RUNNING = 1 |
55 | 78 | 71 | ||
56 | @@ -156,7 +149,8 @@ | |||
57 | 156 | signal_ok='FolderCreated', success_filter=success_filter) | 149 | signal_ok='FolderCreated', success_filter=success_filter) |
58 | 157 | 150 | ||
59 | 158 | self.parent.sd.offer_share( | 151 | self.parent.sd.offer_share( |
61 | 159 | trophydir, self.parent.matrix_username, LOCAL_USERNAME + " Trophies Folder" | 152 | trophydir, self.parent.matrix_username, LOCAL_USERNAME + |
62 | 153 | " Trophies Folder" | ||
63 | 160 | + " (" + timeid + ")", "Modify") | 154 | + " (" + timeid + ")", "Modify") |
64 | 161 | log.msg( | 155 | log.msg( |
65 | 162 | "...share has been offered (" + trophydir + "" + ", " | 156 | "...share has been offered (" + trophydir + "" + ", " |
66 | @@ -180,7 +174,8 @@ | |||
67 | 180 | # XXX let's break this out into a separate folder-sharing method | 174 | # XXX let's break this out into a separate folder-sharing method |
68 | 181 | log.msg("...the '%s' folder is not shared" % trophydir) | 175 | log.msg("...the '%s' folder is not shared" % trophydir) |
69 | 182 | self.parent.sd.offer_share( | 176 | self.parent.sd.offer_share( |
71 | 183 | trophydir, self.parent.matrix_username, LOCAL_USERNAME + " Trophies Folder" | 177 | trophydir, self.parent.matrix_username, LOCAL_USERNAME + |
72 | 178 | " Trophies Folder" | ||
73 | 184 | + " (" + timeid + ")", "Modify") | 179 | + " (" + timeid + ")", "Modify") |
74 | 185 | log.msg("...share has been offered (" + trophydir + "" + ", " | 180 | log.msg("...share has been offered (" + trophydir + "" + ", " |
75 | 186 | + self.parent.matrix_username + ", " + LOCAL_USERNAME + ")") | 181 | + self.parent.matrix_username + ", " + LOCAL_USERNAME + ")") |
76 | @@ -203,7 +198,7 @@ | |||
77 | 203 | return | 198 | return |
78 | 204 | 199 | ||
79 | 205 | self.scripts_state = RUNNING | 200 | self.scripts_state = RUNNING |
81 | 206 | 201 | ||
82 | 207 | if not dbusapi.daemon_is_registered(): | 202 | if not dbusapi.daemon_is_registered(): |
83 | 208 | return | 203 | return |
84 | 209 | 204 | ||
85 | @@ -213,7 +208,8 @@ | |||
86 | 213 | 208 | ||
87 | 214 | queuesize = len(self.parent.scripts_queue) | 209 | queuesize = len(self.parent.scripts_queue) |
88 | 215 | 210 | ||
90 | 216 | log.msg("--- Starting Running Scripts - %d items on the queue ---" % (queuesize)) | 211 | log.msg("--- Starting Running Scripts - %d items on the queue ---" % |
91 | 212 | (queuesize)) | ||
92 | 217 | timestart = time.time() | 213 | timestart = time.time() |
93 | 218 | if not self.parent.test_mode: | 214 | if not self.parent.test_mode: |
94 | 219 | self.parent.service.scriptrunner_start() | 215 | self.parent.service.scriptrunner_start() |
95 | @@ -257,7 +253,7 @@ | |||
96 | 257 | queuesize = len(self.parent.scripts_queue) | 253 | queuesize = len(self.parent.scripts_queue) |
97 | 258 | 254 | ||
98 | 259 | log.msg("The queue is now empty - stopping the scriptrunner.") | 255 | log.msg("The queue is now empty - stopping the scriptrunner.") |
100 | 260 | 256 | ||
101 | 261 | # XXX eventually the code in this method will be rewritten using | 257 | # XXX eventually the code in this method will be rewritten using |
102 | 262 | # deferreds; as such, we're going to have to be more clever regarding | 258 | # deferreds; as such, we're going to have to be more clever regarding |
103 | 263 | # timing things... | 259 | # timing things... |
104 | @@ -291,7 +287,7 @@ | |||
105 | 291 | self.lang = locale.getdefaultlocale()[0] | 287 | self.lang = locale.getdefaultlocale()[0] |
106 | 292 | 288 | ||
107 | 293 | # use this to override the language for testing | 289 | # use this to override the language for testing |
109 | 294 | #self.lang = "pt_BR" | 290 | # self.lang = "pt_BR" |
110 | 295 | self.accomlangs = [] | 291 | self.accomlangs = [] |
111 | 296 | self.service = service | 292 | self.service = service |
112 | 297 | self.asyncapi = AsyncAPI(self) | 293 | self.asyncapi = AsyncAPI(self) |
113 | @@ -346,7 +342,8 @@ | |||
114 | 346 | self.reload_accom_database() | 342 | self.reload_accom_database() |
115 | 347 | 343 | ||
116 | 348 | if not self.test_mode: | 344 | if not self.test_mode: |
118 | 349 | self.sd.connect_signal("DownloadFinished", self._process_received_trophy_file) | 345 | self.sd.connect_signal( |
119 | 346 | "DownloadFinished", self._process_received_trophy_file) | ||
120 | 350 | 347 | ||
121 | 351 | self._refresh_share_data() | 348 | self._refresh_share_data() |
122 | 352 | 349 | ||
123 | @@ -556,7 +553,8 @@ | |||
124 | 556 | for s in shares: | 553 | for s in shares: |
125 | 557 | if s["other_username"] == self.matrix_username: | 554 | if s["other_username"] == self.matrix_username: |
126 | 558 | if s["subscribed"] == "True": | 555 | if s["subscribed"] == "True": |
128 | 559 | matchingshares.append({"name": s["name"], "share_id": s["volume_id"]}) | 556 | matchingshares.append( |
129 | 557 | {"name": s["name"], "share_id": s["volume_id"]}) | ||
130 | 560 | 558 | ||
131 | 561 | if len(matchingshares) > 1: | 559 | if len(matchingshares) > 1: |
132 | 562 | log.msg("Could not find unique active share.") | 560 | log.msg("Could not find unique active share.") |
133 | @@ -626,7 +624,8 @@ | |||
134 | 626 | 624 | ||
135 | 627 | infoneeded = [] | 625 | infoneeded = [] |
136 | 628 | # and prepend the path to the directory, where all extra-information | 626 | # and prepend the path to the directory, where all extra-information |
138 | 629 | # is stored [like: ~/.local/share/accomplishments/trophies/.extrainformation/] | 627 | # is stored [like: |
139 | 628 | # ~/.local/share/accomplishments/trophies/.extrainformation/] | ||
140 | 630 | trophyextrainfo = os.path.join( | 629 | trophyextrainfo = os.path.join( |
141 | 631 | self.trophies_path, ".extrainformation/") | 630 | self.trophies_path, ".extrainformation/") |
142 | 632 | 631 | ||
143 | @@ -640,9 +639,11 @@ | |||
144 | 640 | # get the path to the directory of accomplishments set's | 639 | # get the path to the directory of accomplishments set's |
145 | 641 | # "extrainformation" dir - it is useful, because it contains | 640 | # "extrainformation" dir - it is useful, because it contains |
146 | 642 | # translated labels and descriptions | 641 | # translated labels and descriptions |
148 | 643 | accomextrainfo = os.path.join(self.accomDB[accom]['base-path'], "extrainformation") | 642 | accomextrainfo = os.path.join( |
149 | 643 | self.accomDB[accom]['base-path'], "extrainformation") | ||
150 | 644 | 644 | ||
152 | 645 | # a temporary variable, representing a single entry of the list this function returns | 645 | # a temporary variable, representing a single entry of the list |
153 | 646 | # this function returns | ||
154 | 646 | d = {} | 647 | d = {} |
155 | 647 | 648 | ||
156 | 648 | # Get collection name from accomOD | 649 | # Get collection name from accomOD |
157 | @@ -653,23 +654,30 @@ | |||
158 | 653 | 654 | ||
159 | 654 | # For each needed piece of information: | 655 | # For each needed piece of information: |
160 | 655 | for i in ei: | 656 | for i in ei: |
164 | 656 | label = self.accomDB[collection]['extra-information'][i]['label'] | 657 | label = self.accomDB[collection][ |
165 | 657 | desc = self.accomDB[collection]['extra-information'][i]['description'] | 658 | 'extra-information'][i]['label'] |
166 | 658 | example = self.accomDB[collection]['extra-information'][i].get('example') | 659 | desc = self.accomDB[collection][ |
167 | 660 | 'extra-information'][i]['description'] | ||
168 | 661 | example = self.accomDB[collection][ | ||
169 | 662 | 'extra-information'][i].get('example') | ||
170 | 659 | if example is None: | 663 | if example is None: |
171 | 660 | example = '' | 664 | example = '' |
173 | 661 | regex = self.accomDB[collection]['extra-information'][i].get('regex') | 665 | regex = self.accomDB[collection][ |
174 | 666 | 'extra-information'][i].get('regex') | ||
175 | 662 | if regex is None: | 667 | if regex is None: |
176 | 663 | regex = '' | 668 | regex = '' |
177 | 664 | # we also need to know whether user has already set this item's value. | 669 | # we also need to know whether user has already set this item's value. |
179 | 665 | # to do this, simply check whether trophies/.extrainformation/<item> file exists. | 670 | # to do this, simply check whether |
180 | 671 | # trophies/.extrainformation/<item> file exists. | ||
181 | 666 | try: | 672 | try: |
182 | 667 | valuefile = open(os.path.join(trophyextrainfo, i)) | 673 | valuefile = open(os.path.join(trophyextrainfo, i)) |
183 | 668 | # if we got here without an exception, it means that the file exists | 674 | # if we got here without an exception, it means that the file exists |
184 | 669 | # so, we can read it's value | 675 | # so, we can read it's value |
185 | 670 | value = valuefile.readline() | 676 | value = valuefile.readline() |
188 | 671 | value = value.rstrip() # get rid of the tailing newline | 677 | value = value.rstrip( |
189 | 672 | # and build up the dictionary of all data for a single ExtraInformation field | 678 | ) # get rid of the tailing newline |
190 | 679 | # and build up the dictionary of all data for a single | ||
191 | 680 | # ExtraInformation field | ||
192 | 673 | d = { | 681 | d = { |
193 | 674 | "collection": collection, | 682 | "collection": collection, |
194 | 675 | "needs-information": i, | 683 | "needs-information": i, |
195 | @@ -679,7 +687,9 @@ | |||
196 | 679 | "regex": regex, | 687 | "regex": regex, |
197 | 680 | "value": value} | 688 | "value": value} |
198 | 681 | except IOError as e: | 689 | except IOError as e: |
200 | 682 | # 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 | 690 | # we got an exception, so it seems that the file is not |
201 | 691 | # present - we'll use "" as the value, to indicate that | ||
202 | 692 | # it's empty | ||
203 | 683 | d = { | 693 | d = { |
204 | 684 | "collection": collection, | 694 | "collection": collection, |
205 | 685 | "needs-information": i, | 695 | "needs-information": i, |
206 | @@ -689,11 +699,13 @@ | |||
207 | 689 | "regex": regex, | 699 | "regex": regex, |
208 | 690 | "value": ""} | 700 | "value": ""} |
209 | 691 | 701 | ||
211 | 692 | # since the collected all data related to this particular ExtraInformation field, append it to the list | 702 | # since the collected all data related to this particular |
212 | 703 | # ExtraInformation field, append it to the list | ||
213 | 693 | infoneeded.append(d) | 704 | infoneeded.append(d) |
214 | 694 | 705 | ||
215 | 695 | # at this moment the infoneeded list will be ready, but full of duplicates, | 706 | # at this moment the infoneeded list will be ready, but full of duplicates, |
217 | 696 | # for the items have been added multiple times, if they are mentioned in more then one .accomplishment file | 707 | # for the items have been added multiple times, if they are mentioned |
218 | 708 | # in more then one .accomplishment file | ||
219 | 697 | final = [] | 709 | final = [] |
220 | 698 | for x in infoneeded: # for each item in the original list... | 710 | for x in infoneeded: # for each item in the original list... |
221 | 699 | if x not in final: # ...add it to the outputted list only if it hadn't been added yet. | 711 | 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 | 713 | [{"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" : ""}] | 725 | [{"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 | 714 | 726 | ||
225 | 715 | """ | 727 | """ |
227 | 716 | #fetch a full list of ExtraInformation | 728 | # fetch a full list of ExtraInformation |
228 | 717 | data = self.get_all_extra_information() | 729 | data = self.get_all_extra_information() |
231 | 718 | #now we need to unsort the data just to output these entries, that have value == "" | 730 | # now we need to unsort the data just to output these entries, that have value == "" |
232 | 719 | #this way we can return a list of ExtraInformation fields, that have not been write_config_file_item | 731 | # this way we can return a list of ExtraInformation fields, that have |
233 | 732 | # not been write_config_file_item | ||
234 | 720 | result = [] | 733 | result = [] |
235 | 721 | for i in data: # for each ExtraInformation in the full list | 734 | for i in data: # for each ExtraInformation in the full list |
236 | 722 | if not i['value']: # if the value string is empty, so this ExtraInformation field have not been yet set | 735 | if not i['value']: # if the value string is empty, so this ExtraInformation field have not been yet set |
237 | 723 | i.pop('value') # remove the 'value' field (it's empty anyway) | 736 | i.pop('value') # remove the 'value' field (it's empty anyway) |
238 | 724 | result.append(i) # add this entry to the resulting list | 737 | result.append(i) # add this entry to the resulting list |
240 | 725 | #do not add these fields, that have some value | 738 | # do not add these fields, that have some value |
241 | 726 | 739 | ||
242 | 727 | return result | 740 | return result |
243 | 728 | 741 | ||
244 | @@ -732,14 +745,16 @@ | |||
245 | 732 | does not overwrite any existing data | 745 | does not overwrite any existing data |
246 | 733 | """ | 746 | """ |
247 | 734 | 747 | ||
249 | 735 | # XXX this should be removed as we are using write_extra_information_file | 748 | # XXX this should be removed as we are using |
250 | 749 | # write_extra_information_file | ||
251 | 736 | log.msg("Creating Extra Information file: %s, %s" % (item, data)) | 750 | log.msg("Creating Extra Information file: %s, %s" % (item, data)) |
252 | 737 | extrainfodir = os.path.join(self.trophies_path, ".extrainformation/") | 751 | extrainfodir = os.path.join(self.trophies_path, ".extrainformation/") |
253 | 738 | 752 | ||
254 | 739 | if not os.path.isdir(extrainfodir): | 753 | if not os.path.isdir(extrainfodir): |
255 | 740 | os.makedirs(extrainfodir) | 754 | os.makedirs(extrainfodir) |
256 | 741 | try: | 755 | try: |
258 | 742 | open(os.path.join(extrainfodir, item)) # if the file already exists, do not overwrite it | 756 | open(os.path.join(extrainfodir, item)) |
259 | 757 | # if the file already exists, do not overwrite it | ||
260 | 743 | pass | 758 | pass |
261 | 744 | except IOError as e: | 759 | except IOError as e: |
262 | 745 | f = open(os.path.join(extrainfodir, item), 'w') | 760 | f = open(os.path.join(extrainfodir, item), 'w') |
263 | @@ -787,11 +802,12 @@ | |||
264 | 787 | os.makedirs(extrainfodir) | 802 | os.makedirs(extrainfodir) |
265 | 788 | 803 | ||
266 | 789 | if data: | 804 | if data: |
268 | 790 | f = open(os.path.join(extrainfodir, item), 'w') # will trunkate the file, in case it exist | 805 | f = open(os.path.join(extrainfodir, item), 'w') |
269 | 806 | # will trunkate the file, in case it exist | ||
270 | 791 | f.write(data) | 807 | f.write(data) |
271 | 792 | f.close() | 808 | f.close() |
272 | 793 | else: | 809 | else: |
274 | 794 | #file would be empty, remove it instead | 810 | # file would be empty, remove it instead |
275 | 795 | os.remove(os.path.join(extrainfodir, item)) | 811 | os.remove(os.path.join(extrainfodir, item)) |
276 | 796 | 812 | ||
277 | 797 | # Returns True if all extra information is available for an accom, | 813 | # Returns True if all extra information is available for an accom, |
278 | @@ -864,7 +880,7 @@ | |||
279 | 864 | data = f.read() | 880 | data = f.read() |
280 | 865 | final = [{item: data, "label": label}] | 881 | final = [{item: data, "label": label}] |
281 | 866 | except IOError as e: | 882 | except IOError as e: |
283 | 867 | #print "No data." | 883 | # print "No data." |
284 | 868 | final = [{item: "", "label": label}] | 884 | final = [{item: "", "label": label}] |
285 | 869 | return final | 885 | return final |
286 | 870 | 886 | ||
287 | @@ -905,7 +921,8 @@ | |||
288 | 905 | for collection in collections: | 921 | for collection in collections: |
289 | 906 | # For each collection... | 922 | # For each collection... |
290 | 907 | if collection in self.accomDB: | 923 | if collection in self.accomDB: |
292 | 908 | # This collection has already been loaded from another install path! | 924 | # This collection has already been loaded from another |
293 | 925 | # install path! | ||
294 | 909 | continue | 926 | continue |
295 | 910 | 927 | ||
296 | 911 | collpath = os.path.join(path, collection) | 928 | collpath = os.path.join(path, collection) |
297 | @@ -917,7 +934,8 @@ | |||
298 | 917 | 934 | ||
299 | 918 | if not (cfg.has_option("general", "langdefault") and cfg.has_option("general", "name")): | 935 | if not (cfg.has_option("general", "langdefault") and cfg.has_option("general", "name")): |
300 | 919 | print aboutpath | 936 | print aboutpath |
302 | 920 | raise LookupError("Accomplishment collection with invalid ABOUT file ") | 937 | raise LookupError( |
303 | 938 | "Accomplishment collection with invalid ABOUT file ") | ||
304 | 921 | 939 | ||
305 | 922 | langdefault = cfg.get("general", "langdefault") | 940 | langdefault = cfg.get("general", "langdefault") |
306 | 923 | collectionname = cfg.get("general", "name") | 941 | collectionname = cfg.get("general", "name") |
307 | @@ -934,14 +952,16 @@ | |||
308 | 934 | accompath = os.path.join(langdefaultpath, accomset) | 952 | accompath = os.path.join(langdefaultpath, accomset) |
309 | 935 | accomcfg = ConfigParser.RawConfigParser() | 953 | accomcfg = ConfigParser.RawConfigParser() |
310 | 936 | # check if there is a translated version... | 954 | # check if there is a translated version... |
312 | 937 | translatedpath = os.path.join(os.path.join(collpath, self.lang), accomset) | 955 | translatedpath = os.path.join( |
313 | 956 | os.path.join(collpath, self.lang), accomset) | ||
314 | 938 | if os.path.exists(translatedpath): | 957 | if os.path.exists(translatedpath): |
315 | 939 | # yes, so use the translated file | 958 | # yes, so use the translated file |
316 | 940 | readpath = translatedpath | 959 | readpath = translatedpath |
317 | 941 | langused = self.lang | 960 | langused = self.lang |
318 | 942 | else: | 961 | else: |
319 | 943 | # no. maybe there is a shorter language code? | 962 | # no. maybe there is a shorter language code? |
321 | 944 | translatedpath = os.path.join(os.path.join(collpath, self.lang.split("_")[0]), accomset) | 963 | translatedpath = os.path.join(os.path.join( |
322 | 964 | collpath, self.lang.split("_")[0]), accomset) | ||
323 | 945 | if os.path.exists(translatedpath): | 965 | if os.path.exists(translatedpath): |
324 | 946 | readpath = translatedpath | 966 | readpath = translatedpath |
325 | 947 | langused = self.lang.split("_")[0] | 967 | langused = self.lang.split("_")[0] |
326 | @@ -975,7 +995,8 @@ | |||
327 | 975 | accomdata['categories'] = [] | 995 | accomdata['categories'] = [] |
328 | 976 | for cat in cats: | 996 | for cat in cats: |
329 | 977 | catsplitted = cat.rstrip().lstrip().split(":") | 997 | catsplitted = cat.rstrip().lstrip().split(":") |
331 | 978 | accomdata['categories'].append(cat.rstrip().lstrip()) | 998 | accomdata['categories'].append( |
332 | 999 | cat.rstrip().lstrip()) | ||
333 | 979 | if catsplitted[0] in collcategories: | 1000 | if catsplitted[0] in collcategories: |
334 | 980 | pass | 1001 | pass |
335 | 981 | else: | 1002 | else: |
336 | @@ -983,7 +1004,8 @@ | |||
337 | 983 | if len(catsplitted) > 1: | 1004 | if len(catsplitted) > 1: |
338 | 984 | # category + subcategory | 1005 | # category + subcategory |
339 | 985 | if catsplitted[1] not in collcategories[catsplitted[0]]: | 1006 | if catsplitted[1] not in collcategories[catsplitted[0]]: |
341 | 986 | collcategories[catsplitted[0]].append(catsplitted[1]) | 1007 | collcategories[catsplitted[ |
342 | 1008 | 0]].append(catsplitted[1]) | ||
343 | 987 | del accomdata['category'] | 1009 | del accomdata['category'] |
344 | 988 | else: | 1010 | else: |
345 | 989 | accomdata['categories'] = [] | 1011 | accomdata['categories'] = [] |
346 | @@ -1025,7 +1047,8 @@ | |||
347 | 1025 | "Parse error is: %s" % (readpath, e.message)) | 1047 | "Parse error is: %s" % (readpath, e.message)) |
348 | 1026 | continue | 1048 | continue |
349 | 1027 | 1049 | ||
351 | 1028 | accomdata = dict(accomcfg._sections["accomplishment"]) | 1050 | accomdata = dict( |
352 | 1051 | accomcfg._sections["accomplishment"]) | ||
353 | 1029 | accomID = collection + "/" + accomfile[:-15] | 1052 | accomID = collection + "/" + accomfile[:-15] |
354 | 1030 | if 'author' in accomdata: | 1053 | if 'author' in accomdata: |
355 | 1031 | collauthors.add(accomdata['author']) | 1054 | collauthors.add(accomdata['author']) |
356 | @@ -1041,8 +1064,10 @@ | |||
357 | 1041 | categories = [] | 1064 | categories = [] |
358 | 1042 | accomdata['categories'] = [] | 1065 | accomdata['categories'] = [] |
359 | 1043 | for cat in cats: | 1066 | for cat in cats: |
362 | 1044 | catsplitted = cat.rstrip().lstrip().split(":") | 1067 | catsplitted = cat.rstrip( |
363 | 1045 | accomdata['categories'].append(cat.rstrip().lstrip()) | 1068 | ).lstrip().split(":") |
364 | 1069 | accomdata['categories'].append( | ||
365 | 1070 | cat.rstrip().lstrip()) | ||
366 | 1046 | if catsplitted[0] in collcategories: | 1071 | if catsplitted[0] in collcategories: |
367 | 1047 | pass | 1072 | pass |
368 | 1048 | else: | 1073 | else: |
369 | @@ -1050,7 +1075,8 @@ | |||
370 | 1050 | if len(catsplitted) > 1: | 1075 | if len(catsplitted) > 1: |
371 | 1051 | # category + subcategory | 1076 | # category + subcategory |
372 | 1052 | if catsplitted[1] not in collcategories[catsplitted[0]]: | 1077 | if catsplitted[1] not in collcategories[catsplitted[0]]: |
374 | 1053 | collcategories[catsplitted[0]].append(catsplitted[1]) | 1078 | collcategories[catsplitted[ |
375 | 1079 | 0]].append(catsplitted[1]) | ||
376 | 1054 | del accomdata['category'] | 1080 | del accomdata['category'] |
377 | 1055 | else: | 1081 | else: |
378 | 1056 | accomdata['categories'] = [] | 1082 | accomdata['categories'] = [] |
379 | @@ -1076,7 +1102,8 @@ | |||
380 | 1076 | if eicfg.has_option("description", self.lang): | 1102 | if eicfg.has_option("description", self.lang): |
381 | 1077 | description = eicfg.get("description", self.lang) | 1103 | description = eicfg.get("description", self.lang) |
382 | 1078 | elif eicfg.has_option("description", self.lang.split("_")[0]): | 1104 | elif eicfg.has_option("description", self.lang.split("_")[0]): |
384 | 1079 | description = eicfg.get("description", self.lang.split("_")[0]) | 1105 | description = eicfg.get( |
385 | 1106 | "description", self.lang.split("_")[0]) | ||
386 | 1080 | else: | 1107 | else: |
387 | 1081 | description = eicfg.get("description", langdefault) | 1108 | description = eicfg.get("description", langdefault) |
388 | 1082 | 1109 | ||
389 | @@ -1108,7 +1135,7 @@ | |||
390 | 1108 | self._update_all_locked_and_accomplished_statuses() | 1135 | self._update_all_locked_and_accomplished_statuses() |
391 | 1109 | 1136 | ||
392 | 1110 | self.create_all_trophy_icons() | 1137 | self.create_all_trophy_icons() |
394 | 1111 | 1138 | ||
395 | 1112 | if not self.test_mode: | 1139 | if not self.test_mode: |
396 | 1113 | self.service.accoms_collections_reloaded() | 1140 | self.service.accoms_collections_reloaded() |
397 | 1114 | # Uncomment following for debugging | 1141 | # Uncomment following for debugging |
398 | @@ -1553,7 +1580,8 @@ | |||
399 | 1553 | 1580 | ||
400 | 1554 | # Check if is hasn't been already accomplished | 1581 | # Check if is hasn't been already accomplished |
401 | 1555 | if self.get_accom_is_accomplished(accomID): | 1582 | if self.get_accom_is_accomplished(accomID): |
403 | 1556 | log.msg("Not accomplishing " + accomID + ", it has already been accomplished.") | 1583 | log.msg("Not accomplishing " + accomID + |
404 | 1584 | ", it has already been accomplished.") | ||
405 | 1557 | return True # success | 1585 | return True # success |
406 | 1558 | 1586 | ||
407 | 1559 | # Check if this accomplishment is unlocked | 1587 | # Check if this accomplishment is unlocked |
408 | @@ -1641,23 +1669,28 @@ | |||
409 | 1641 | log.msg(type(value)) | 1669 | log.msg(type(value)) |
410 | 1642 | if value == True: | 1670 | if value == True: |
411 | 1643 | log.msg("setting") | 1671 | log.msg("setting") |
413 | 1644 | command = os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --start" | 1672 | command = os.path.join( |
414 | 1673 | daemon_exec_dir, "accomplishments-daemon") + " --start" | ||
415 | 1645 | filetext = "[Desktop Entry]\n\ | 1674 | filetext = "[Desktop Entry]\n\ |
416 | 1646 | Type=Application\n\ | 1675 | Type=Application\n\ |
417 | 1647 | Encoding=UTF-8\n\ | 1676 | Encoding=UTF-8\n\ |
418 | 1648 | Name=Accomplishments Daemon\n\ | 1677 | Name=Accomplishments Daemon\n\ |
419 | 1649 | Exec=" + command + "\n\ | 1678 | Exec=" + command + "\n\ |
420 | 1650 | NoDisplay=true" | 1679 | NoDisplay=true" |
422 | 1651 | filename = os.path.join(self.dir_autostart, "accomplishments-daemon.desktop") | 1680 | filename = os.path.join( |
423 | 1681 | self.dir_autostart, "accomplishments-daemon.desktop") | ||
424 | 1652 | file = open(filename, "w") | 1682 | file = open(filename, "w") |
425 | 1653 | file.write(filetext) | 1683 | file.write(filetext) |
426 | 1654 | file.close | 1684 | file.close |
428 | 1655 | self.write_config_file_item("config", "daemon_sessionstart", "true") | 1685 | self.write_config_file_item( |
429 | 1686 | "config", "daemon_sessionstart", "true") | ||
430 | 1656 | elif value == False: | 1687 | elif value == False: |
432 | 1657 | filename = os.path.join(self.dir_autostart, "accomplishments-daemon.desktop") | 1688 | filename = os.path.join( |
433 | 1689 | self.dir_autostart, "accomplishments-daemon.desktop") | ||
434 | 1658 | if os.path.exists(filename): | 1690 | if os.path.exists(filename): |
435 | 1659 | os.remove(filename) | 1691 | os.remove(filename) |
437 | 1660 | self.write_config_file_item("config", "daemon_sessionstart", "false") | 1692 | self.write_config_file_item( |
438 | 1693 | "config", "daemon_sessionstart", "false") | ||
439 | 1661 | 1694 | ||
440 | 1662 | def get_daemon_session_start(self): | 1695 | def get_daemon_session_start(self): |
441 | 1663 | return self.get_config_value("config", "daemon_sessionstart") | 1696 | return self.get_config_value("config", "daemon_sessionstart") |
442 | @@ -1685,7 +1718,8 @@ | |||
443 | 1685 | with open(cfile, 'wb') as configfile: | 1718 | with open(cfile, 'wb') as configfile: |
444 | 1686 | config.write(configfile) | 1719 | config.write(configfile) |
445 | 1687 | 1720 | ||
447 | 1688 | # restart SyncDaemonTool to use new settings immediately, fixes LP#1011903 | 1721 | # restart SyncDaemonTool to use new settings immediately, fixes |
448 | 1722 | # LP#1011903 | ||
449 | 1689 | self.ubuntuone_restart_syncdaemontool() | 1723 | self.ubuntuone_restart_syncdaemontool() |
450 | 1690 | 1724 | ||
451 | 1691 | # XXX - NEEDS UNIT TEST | 1725 | # XXX - NEEDS UNIT TEST |
452 | @@ -1724,7 +1758,7 @@ | |||
453 | 1724 | 1758 | ||
454 | 1725 | def _display_accomplished_bubble(self, accomID): | 1759 | def _display_accomplished_bubble(self, accomID): |
455 | 1726 | if self.show_notifications == True and useNotify and ( | 1760 | if self.show_notifications == True and useNotify and ( |
457 | 1727 | Notify.is_initted() or Notify.init("icon-summary-body")): | 1761 | Notify.is_initted() or Notify.init("icon-summary-body")): |
458 | 1728 | n = Notify.Notification.new( | 1762 | n = Notify.Notification.new( |
459 | 1729 | _("You have accomplished something!"), | 1763 | _("You have accomplished something!"), |
460 | 1730 | self.get_accom_title(accomID), | 1764 | self.get_accom_title(accomID), |
461 | @@ -1736,7 +1770,7 @@ | |||
462 | 1736 | unlocked = len(self.list_depending_on(accomID)) | 1770 | unlocked = len(self.list_depending_on(accomID)) |
463 | 1737 | if unlocked is not 0: | 1771 | if unlocked is not 0: |
464 | 1738 | if self.show_notifications == True and useNotify and ( | 1772 | if self.show_notifications == True and useNotify and ( |
466 | 1739 | Notify.is_initted() or Notify.init("icon-summary-body")): | 1773 | Notify.is_initted() or Notify.init("icon-summary-body")): |
467 | 1740 | message = (N_("You have unlocked %s new opportunity.", "You have unlocked %s new opportunities.", unlocked) % str(unlocked)) | 1774 | message = (N_("You have unlocked %s new opportunity.", "You have unlocked %s new opportunities.", unlocked) % str(unlocked)) |
468 | 1741 | n = Notify.Notification.new( | 1775 | n = Notify.Notification.new( |
469 | 1742 | _("Opportunities Unlocked!"), message, | 1776 | _("Opportunities Unlocked!"), message, |
470 | @@ -1750,11 +1784,11 @@ | |||
471 | 1750 | 1784 | ||
472 | 1751 | def _get_is_asc_correct(self, filepath): | 1785 | def _get_is_asc_correct(self, filepath): |
473 | 1752 | if not os.path.exists(filepath): | 1786 | if not os.path.exists(filepath): |
475 | 1753 | log.msg("Cannot check if signature is correct, because file"\ | 1787 | log.msg("Cannot check if signature is correct, because file" |
476 | 1754 | "%s does not exist" % filepath) | 1788 | "%s does not exist" % filepath) |
477 | 1755 | return False | 1789 | return False |
478 | 1756 | elif not os.path.exists(filepath[:-4]): | 1790 | elif not os.path.exists(filepath[:-4]): |
480 | 1757 | log.msg("Cannot check if signature is correct, because file"\ | 1791 | log.msg("Cannot check if signature is correct, because file" |
481 | 1758 | "%s does not exist" % filepath[:-4]) | 1792 | "%s does not exist" % filepath[:-4]) |
482 | 1759 | return False | 1793 | return False |
483 | 1760 | else: | 1794 | else: |
484 | @@ -1782,7 +1816,8 @@ | |||
485 | 1782 | return False | 1816 | return False |
486 | 1783 | else: | 1817 | else: |
487 | 1784 | # Correct! | 1818 | # Correct! |
489 | 1785 | # result = {'timestamp': sig[0].timestamp, 'signer': sig[0].fpr} | 1819 | # result = {'timestamp': sig[0].timestamp, 'signer': |
490 | 1820 | # sig[0].fpr} | ||
491 | 1786 | return True | 1821 | return True |
492 | 1787 | 1822 | ||
493 | 1788 | def _check_if_accom_is_accomplished(self, accomID): | 1823 | def _check_if_accom_is_accomplished(self, accomID): |
494 | @@ -1817,13 +1852,15 @@ | |||
495 | 1817 | def _update_all_locked_and_accomplished_statuses(self): | 1852 | def _update_all_locked_and_accomplished_statuses(self): |
496 | 1818 | accoms = self.list_accoms() | 1853 | accoms = self.list_accoms() |
497 | 1819 | for accom in accoms: | 1854 | for accom in accoms: |
499 | 1820 | self.accomDB[accom]['accomplished'] = self._check_if_accom_is_accomplished(accom) | 1855 | self.accomDB[accom][ |
500 | 1856 | 'accomplished'] = self._check_if_accom_is_accomplished(accom) | ||
501 | 1821 | if self.accomDB[accom]['accomplished'] == True: | 1857 | if self.accomDB[accom]['accomplished'] == True: |
502 | 1822 | self.accomDB[accom]['date-accomplished'] = self._get_trophy_date_accomplished(accom) | 1858 | self.accomDB[accom]['date-accomplished'] = self._get_trophy_date_accomplished(accom) |
503 | 1823 | else: | 1859 | else: |
504 | 1824 | self.accomDB[accom]['date-accomplished'] = "None" | 1860 | self.accomDB[accom]['date-accomplished'] = "None" |
505 | 1825 | for accom in accoms: | 1861 | for accom in accoms: |
507 | 1826 | self.accomDB[accom]['locked'] = self._check_if_accom_is_locked(accom) | 1862 | self.accomDB[accom][ |
508 | 1863 | 'locked'] = self._check_if_accom_is_locked(accom) | ||
509 | 1827 | 1864 | ||
510 | 1828 | # XXX - NEEDS UNIT TEST | 1865 | # XXX - NEEDS UNIT TEST |
511 | 1829 | def _get_trophy_date_accomplished(self, accomID): | 1866 | def _get_trophy_date_accomplished(self, accomID): |
512 | @@ -1844,18 +1881,20 @@ | |||
513 | 1844 | # Marks accomplishments as accomplished in the accomDB, and | 1881 | # Marks accomplishments as accomplished in the accomDB, and |
514 | 1845 | # returns a list of accomIDs that just got unlocked. | 1882 | # returns a list of accomIDs that just got unlocked. |
515 | 1846 | self.accomDB[accomID]['accomplished'] = True | 1883 | self.accomDB[accomID]['accomplished'] = True |
517 | 1847 | self.accomDB[accomID]['date-accomplished'] = self._get_trophy_date_accomplished(accomID) | 1884 | self.accomDB[accomID][ |
518 | 1885 | 'date-accomplished'] = self._get_trophy_date_accomplished(accomID) | ||
519 | 1848 | accoms = self.list_depending_on(accomID) | 1886 | accoms = self.list_depending_on(accomID) |
520 | 1849 | res = [] | 1887 | res = [] |
521 | 1850 | for accom in accoms: | 1888 | for accom in accoms: |
522 | 1851 | before = self.accomDB[accom]['locked'] | 1889 | before = self.accomDB[accom]['locked'] |
524 | 1852 | self.accomDB[accom]['locked'] = self._check_if_accom_is_locked(accom) | 1890 | self.accomDB[accom][ |
525 | 1891 | 'locked'] = self._check_if_accom_is_locked(accom) | ||
526 | 1853 | # If it just got unlocked... | 1892 | # If it just got unlocked... |
527 | 1854 | if (before == True and self.accomDB[accom]['locked'] == False): | 1893 | if (before == True and self.accomDB[accom]['locked'] == False): |
528 | 1855 | res.append(accom) | 1894 | res.append(accom) |
529 | 1856 | return res | 1895 | return res |
530 | 1857 | 1896 | ||
532 | 1858 | #Other significant system functions | 1897 | # Other significant system functions |
533 | 1859 | 1898 | ||
534 | 1860 | def get_API_version(self): | 1899 | def get_API_version(self): |
535 | 1861 | return "0.2" | 1900 | return "0.2" |
536 | 1862 | 1901 | ||
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 | 1 | from optparse import OptionParser | 1 | from optparse import OptionParser |
542 | 2 | 2 | ||
543 | 3 | from twisted.application.internet import TimerService | ||
544 | 4 | from twisted.application.service import Application | 3 | from twisted.application.service import Application |
545 | 5 | 4 | ||
546 | 6 | from accomplishments.daemon import dbusapi | 5 | from accomplishments.daemon import dbusapi |
547 | 7 | from accomplishments.daemon import service | 6 | from accomplishments.daemon import service |
548 | 8 | from accomplishments.daemon import api | ||
549 | 9 | |||
550 | 10 | |||
551 | 11 | # XXX these won't work with twistd; we need to write a twistd plugin to support | ||
552 | 12 | # additional command line options. | ||
553 | 13 | def parse_options(): | ||
554 | 14 | parser = OptionParser() | ||
555 | 15 | parser.set_defaults(suppress_notifications=False) | ||
556 | 16 | parser.add_option("--trophies-path", dest="trophies_path", default=None) | ||
557 | 17 | parser.add_option("--accomplishments-path", dest="accomplishments_installpaths", | ||
558 | 18 | default=None) | ||
559 | 19 | parser.add_option("--suppress-notifications", action="store_true", | ||
560 | 20 | dest="suppress_notifications") | ||
561 | 21 | return parser.parse_args() | ||
562 | 22 | 7 | ||
563 | 23 | 8 | ||
564 | 24 | def applicationFactory(app_name="", bus_name="", main_loop=None, | 9 | def applicationFactory(app_name="", bus_name="", main_loop=None, |
565 | 25 | 10 | ||
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 | 11 | """ | 11 | """ |
571 | 12 | 12 | ||
572 | 13 | import dbus | 13 | import dbus |
573 | 14 | |||
574 | 15 | from twisted.python import log | ||
575 | 16 | |||
576 | 17 | from accomplishments.daemon import service | 14 | from accomplishments.daemon import service |
577 | 18 | 15 | ||
578 | 19 | |||
579 | 20 | def daemon_is_registered(): | 16 | def daemon_is_registered(): |
580 | 21 | try: | 17 | try: |
581 | 22 | obj = dbus.SessionBus().get_object( | 18 | obj = dbus.SessionBus().get_object( |
582 | @@ -408,10 +404,10 @@ | |||
583 | 408 | ["Launchpad"] | 404 | ["Launchpad"] |
584 | 409 | """ | 405 | """ |
585 | 410 | return self.api.get_accom_categories(accomID) | 406 | return self.api.get_accom_categories(accomID) |
587 | 411 | 407 | ||
588 | 412 | @dbus.service.method(dbus_interface='org.ubuntu.accomplishments', | 408 | @dbus.service.method(dbus_interface='org.ubuntu.accomplishments', |
589 | 413 | in_signature="s", out_signature="as") | 409 | in_signature="s", out_signature="as") |
591 | 414 | def get_accom_keywords(self,accomID): | 410 | def get_accom_keywords(self, accomID): |
592 | 415 | return self.api.get_accom_keywords(accomID) | 411 | return self.api.get_accom_keywords(accomID) |
593 | 416 | 412 | ||
594 | 417 | @dbus.service.method(dbus_interface='org.ubuntu.accomplishments', | 413 | @dbus.service.method(dbus_interface='org.ubuntu.accomplishments', |
595 | @@ -911,12 +907,11 @@ | |||
596 | 911 | def create_all_trophy_icons(self): | 907 | def create_all_trophy_icons(self): |
597 | 912 | return self.api.create_all_trophy_icons() | 908 | return self.api.create_all_trophy_icons() |
598 | 913 | 909 | ||
599 | 914 | |||
600 | 915 | # XXX this looks like an unintentional duplicate of the "other" | 910 | # XXX this looks like an unintentional duplicate of the "other" |
601 | 916 | # trophy_received... I've moved them here together so that someone in the | 911 | # trophy_received... I've moved them here together so that someone in the |
602 | 917 | # know (Jono?) can clarify and remove the one that's not needed | 912 | # know (Jono?) can clarify and remove the one that's not needed |
603 | 918 | #@dbus.service.signal(dbus_interface='org.ubuntu.accomplishments') | 913 | #@dbus.service.signal(dbus_interface='org.ubuntu.accomplishments') |
605 | 919 | #def trophy_received(self, trophy): | 914 | # def trophy_received(self, trophy): |
606 | 920 | # pass | 915 | # pass |
607 | 921 | @dbus.service.signal(dbus_interface='org.ubuntu.accomplishments') | 916 | @dbus.service.signal(dbus_interface='org.ubuntu.accomplishments') |
608 | 922 | def trophy_received(self, trophy): | 917 | def trophy_received(self, trophy): |
609 | 923 | 918 | ||
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 | 1 | import logging | ||
615 | 2 | import optparse | 1 | import optparse |
616 | 3 | import os | 2 | import os |
617 | 4 | 3 | ||
618 | @@ -22,40 +21,11 @@ | |||
619 | 22 | def get_version(): | 21 | def get_version(): |
620 | 23 | return config.__version__ | 22 | return config.__version__ |
621 | 24 | 23 | ||
622 | 25 | |||
623 | 26 | class NullHandler(logging.Handler): | ||
624 | 27 | """ | ||
625 | 28 | """ | ||
626 | 29 | def emit(self, record): | ||
627 | 30 | pass | ||
628 | 31 | |||
629 | 32 | |||
630 | 33 | def set_up_logging(opts): | ||
631 | 34 | # add a handler to prevent basicConfig | ||
632 | 35 | root = logging.getLogger() | ||
633 | 36 | null_handler = NullHandler() | ||
634 | 37 | root.addHandler(null_handler) | ||
635 | 38 | |||
636 | 39 | formatter = logging.Formatter( | ||
637 | 40 | "%(levelname)s:%(name)s: %(funcName)s() '%(message)s'") | ||
638 | 41 | |||
639 | 42 | logger = logging.getLogger('accomplishments-daemon') | ||
640 | 43 | logger_sh = logging.StreamHandler() | ||
641 | 44 | logger_sh.setFormatter(formatter) | ||
642 | 45 | logger.addHandler(logger_sh) | ||
643 | 46 | |||
644 | 47 | # Set the logging level to show debug messages. | ||
645 | 48 | if opts.verbose: | ||
646 | 49 | logger.setLevel(logging.DEBUG) | ||
647 | 50 | logger.debug('logging enabled') | ||
648 | 51 | if opts.verbose > 1: | ||
649 | 52 | logger.setLevel(logging.DEBUG) | ||
650 | 53 | |||
651 | 54 | |||
652 | 55 | def get_data_path(): | 24 | def get_data_path(): |
653 | 56 | # XXX: NOTE: This function will most likely work incorrectly when daemon is installed in non-default path. | 25 | # XXX: NOTE: This function will most likely work incorrectly when daemon is installed in non-default path. |
654 | 57 | # Luckily, this function is no longer used anywhere. | 26 | # Luckily, this function is no longer used anywhere. |
656 | 58 | # If you feel you need to get this path, please refer to utils/paths.py instead. | 27 | # If you feel you need to get this path, please refer to utils/paths.py |
657 | 28 | # instead. | ||
658 | 59 | """Retrieve accomplishments-daemon data path | 29 | """Retrieve accomplishments-daemon data path |
659 | 60 | 30 | ||
660 | 61 | This path is by default <accomplishments_daemon_lib_path>/../data/ in trunk | 31 | This path is by default <accomplishments_daemon_lib_path>/../data/ in trunk |
661 | @@ -64,7 +34,8 @@ | |||
662 | 64 | """ | 34 | """ |
663 | 65 | 35 | ||
664 | 66 | # Get pathname absolute or relative. | 36 | # Get pathname absolute or relative. |
666 | 67 | path = os.path.join(accomplishments.__path__[0], config.__accomplishments_daemon_data_directory__) | 37 | path = os.path.join(accomplishments.__path__[0], |
667 | 38 | config.__accomplishments_daemon_data_directory__) | ||
668 | 68 | abs_data_path = os.path.abspath(path) | 39 | abs_data_path = os.path.abspath(path) |
669 | 69 | log.msg("MODULE DIR") | 40 | log.msg("MODULE DIR") |
670 | 70 | log.msg(accomplishments.__path__[0]) | 41 | log.msg(accomplishments.__path__[0]) |
671 | 71 | 42 | ||
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 | 18 | # files). By default, this is ../data, relative your trunk layout | 18 | # files). By default, this is ../data, relative your trunk layout |
677 | 19 | __accomplishments_daemon_data_directory__ = '../data/' | 19 | __accomplishments_daemon_data_directory__ = '../data/' |
678 | 20 | __license__ = '' | 20 | __license__ = '' |
680 | 21 | __version__ = '0.1' | 21 | __version__ = '0.3' |
681 | 22 | 22 | ||
682 | 23 | import os | 23 | import os |
683 | 24 | 24 | ||
684 | 25 | 25 | ||
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 | 21 | def update_config(values={}): | 21 | def update_config(values={}): |
690 | 22 | oldvalues = {} | 22 | oldvalues = {} |
691 | 23 | try: | 23 | try: |
693 | 24 | fin = file('accomplishments/util/accomplishments-daemon-config.py', 'r') | 24 | fin = file( |
694 | 25 | 'accomplishments/util/accomplishments-daemon-config.py', 'r') | ||
695 | 25 | fout = file(fin.name + '.new', 'w') | 26 | fout = file(fin.name + '.new', 'w') |
696 | 26 | 27 | ||
697 | 27 | for line in fin: | 28 | for line in fin: |
698 | 28 | 29 | ||
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 | 20 | basepath = os.path.split(os.path.split(os.path.split(branchpath)[0])[0])[0] | 20 | basepath = os.path.split(os.path.split(os.path.split(branchpath)[0])[0])[0] |
704 | 21 | # basepath should equal to prefix given on installation. | 21 | # basepath should equal to prefix given on installation. |
705 | 22 | 22 | ||
707 | 23 | #print "Daemon seems to be installed to: " + basepath | 23 | # print "Daemon seems to be installed to: " + basepath |
708 | 24 | 24 | ||
709 | 25 | # finally, setting these significant data directories... | 25 | # finally, setting these significant data directories... |
710 | 26 | systemdata_dir = os.path.join(basepath, 'share/accomplishments-daemon') | 26 | systemdata_dir = os.path.join(basepath, 'share/accomplishments-daemon') |
711 | @@ -41,7 +41,8 @@ | |||
712 | 41 | # using branch root directory as the base path | 41 | # using branch root directory as the base path |
713 | 42 | basepath = branchpath | 42 | basepath = branchpath |
714 | 43 | 43 | ||
716 | 44 | #print "Daemon seems to be run not installed, branch base path used: " + basepath | 44 | # print "Daemon seems to be run not installed, branch base path used: " + |
717 | 45 | # basepath | ||
718 | 45 | 46 | ||
719 | 46 | # finally, setting these significant data directories... | 47 | # finally, setting these significant data directories... |
720 | 47 | systemdata_dir = os.path.join(basepath, 'data/daemon') | 48 | systemdata_dir = os.path.join(basepath, 'data/daemon') |
721 | 48 | 49 | ||
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 | 3 | import sys | 3 | import sys |
727 | 4 | import os | 4 | import os |
728 | 5 | 5 | ||
730 | 6 | # Importing from accomplishments.{daemon,util} would fail, if the path | 6 | # Importing from accomplishments.{daemon,util} would fail, if the path |
731 | 7 | # is set incorrectly. | 7 | # is set incorrectly. |
732 | 8 | # We need to ensure that the script will load the correct version of | 8 | # We need to ensure that the script will load the correct version of |
733 | 9 | # accomplishment.* that is installed with this script. | 9 | # accomplishment.* that is installed with this script. |
734 | 10 | scriptpath = os.path.abspath(__file__) | 10 | scriptpath = os.path.abspath(__file__) |
736 | 11 | # basepaths shall be equal to prefix used while installing - if the application is run from source, it does not really matter. | 11 | # basepaths shall be equal to prefix used while installing - if the |
737 | 12 | # application is run from source, it does not really matter. | ||
738 | 12 | basepath = os.path.split(os.path.split(scriptpath)[0])[0] | 13 | basepath = os.path.split(os.path.split(scriptpath)[0])[0] |
739 | 13 | sys.path.insert(0, basepath) | 14 | sys.path.insert(0, basepath) |
740 | 14 | sys.path.insert(0, basepath + "/lib/python2.7") | 15 | sys.path.insert(0, basepath + "/lib/python2.7") |
741 | @@ -18,18 +19,23 @@ | |||
742 | 18 | # This is a global variable | 19 | # This is a global variable |
743 | 19 | pidfile_path = None | 20 | pidfile_path = None |
744 | 20 | 21 | ||
745 | 22 | |||
746 | 21 | def main(): | 23 | def main(): |
747 | 22 | # This part of code is executed if the script is run directly. | 24 | # This part of code is executed if the script is run directly. |
748 | 23 | import argparse | 25 | import argparse |
750 | 24 | parser = argparse.ArgumentParser(description='Launches the accomplishments daemon.') | 26 | parser = argparse.ArgumentParser( |
751 | 27 | description='Launches the accomplishments daemon.') | ||
752 | 25 | mode = parser.add_mutually_exclusive_group() | 28 | mode = parser.add_mutually_exclusive_group() |
758 | 26 | mode.add_argument('--start',action='store_true',help="Launch the accomplishments daemon (default option when run without arguments).") | 29 | mode.add_argument('--start', action='store_true', help="Launch the accomplishments daemon (default option when run without arguments).") |
759 | 27 | mode.add_argument('--stop',action='store_true',help="Stop the daemon gracefully.") | 30 | mode.add_argument( |
760 | 28 | mode.add_argument('--restart','-r',action='store_true',help="Restart the daemon.") | 31 | '--stop', action='store_true', help="Stop the daemon gracefully.") |
761 | 29 | mode.add_argument('--reload',action='store_true',help="Reload accomplishments collections.") | 32 | mode.add_argument( |
762 | 30 | parser.add_argument('-f','--foreground',action='store_true',help="When starting the daemon, run it in the foreground, with logs directed to stdout.") | 33 | '--restart', '-r', action='store_true', help="Restart the daemon.") |
763 | 34 | mode.add_argument('--reload', action='store_true', | ||
764 | 35 | help="Reload accomplishments collections.") | ||
765 | 36 | parser.add_argument('-f', '--foreground', action='store_true', help="When starting the daemon, run it in the foreground, with logs directed to stdout.") | ||
766 | 31 | args = parser.parse_args() | 37 | args = parser.parse_args() |
768 | 32 | 38 | ||
769 | 33 | import xdg.BaseDirectory | 39 | import xdg.BaseDirectory |
770 | 34 | try: | 40 | try: |
771 | 35 | rootdir = os.environ['ACCOMPLISHMENTS_ROOT_DIR'] | 41 | rootdir = os.environ['ACCOMPLISHMENTS_ROOT_DIR'] |
772 | @@ -38,44 +44,44 @@ | |||
773 | 38 | except KeyError: | 44 | except KeyError: |
774 | 39 | cache_dir = os.path.join( | 45 | cache_dir = os.path.join( |
775 | 40 | xdg.BaseDirectory.xdg_cache_home, "accomplishments") | 46 | xdg.BaseDirectory.xdg_cache_home, "accomplishments") |
777 | 41 | 47 | ||
778 | 42 | global pidfile_path | 48 | global pidfile_path |
782 | 43 | pidfile_path = os.path.join(cache_dir,"accomplishments-daemon.pid") | 49 | pidfile_path = os.path.join(cache_dir, "accomplishments-daemon.pid") |
783 | 44 | 50 | ||
784 | 45 | launchdaemon = False | 51 | launchdaemon = False |
785 | 46 | if args.start or not (args.start or args.stop or args.reload or args.restart): | 52 | if args.start or not (args.start or args.stop or args.reload or args.restart): |
786 | 47 | # Start the daemon. | 53 | # Start the daemon. |
788 | 48 | 54 | ||
789 | 49 | from accomplishments.util.paths import daemon_exec_dir | 55 | from accomplishments.util.paths import daemon_exec_dir |
790 | 50 | # Check if the daemon is already running. | 56 | # Check if the daemon is already running. |
791 | 51 | if is_daemon_running(): | 57 | if is_daemon_running(): |
792 | 52 | print "The daemon is already running." | 58 | print "The daemon is already running." |
793 | 53 | return | 59 | return |
795 | 54 | 60 | ||
796 | 55 | # The daemon is not running. | 61 | # The daemon is not running. |
797 | 56 | launchdaemon = True | 62 | launchdaemon = True |
799 | 57 | 63 | ||
800 | 58 | elif args.stop: | 64 | elif args.stop: |
801 | 59 | # Stop the daemon | 65 | # Stop the daemon |
802 | 60 | if not is_daemon_running(): | 66 | if not is_daemon_running(): |
803 | 61 | print "The daemon is not running." | 67 | print "The daemon is not running." |
804 | 62 | return | 68 | return |
805 | 63 | print "Stopping the daemon..." | 69 | print "Stopping the daemon..." |
807 | 64 | 70 | ||
808 | 65 | from accomplishments.daemon import dbusapi | 71 | from accomplishments.daemon import dbusapi |
809 | 66 | api = dbusapi.Accomplishments() | 72 | api = dbusapi.Accomplishments() |
810 | 67 | api.stop_daemon() | 73 | api.stop_daemon() |
812 | 68 | 74 | ||
813 | 69 | elif args.reload: | 75 | elif args.reload: |
814 | 70 | if not is_daemon_running(): | 76 | if not is_daemon_running(): |
815 | 71 | print "The daemon is not running." | 77 | print "The daemon is not running." |
816 | 72 | return | 78 | return |
817 | 73 | print "Reloading accomplishments collections." | 79 | print "Reloading accomplishments collections." |
819 | 74 | 80 | ||
820 | 75 | from accomplishments.daemon import dbusapi | 81 | from accomplishments.daemon import dbusapi |
821 | 76 | api = dbusapi.Accomplishments() | 82 | api = dbusapi.Accomplishments() |
822 | 77 | api.reload_accom_database() | 83 | api.reload_accom_database() |
824 | 78 | 84 | ||
825 | 79 | elif args.restart: | 85 | elif args.restart: |
826 | 80 | from accomplishments.util.paths import daemon_exec_dir | 86 | from accomplishments.util.paths import daemon_exec_dir |
827 | 81 | # Check if the daemon is already running. | 87 | # Check if the daemon is already running. |
828 | @@ -86,54 +92,55 @@ | |||
829 | 86 | from accomplishments.daemon import dbusapi | 92 | from accomplishments.daemon import dbusapi |
830 | 87 | api = dbusapi.Accomplishments() | 93 | api = dbusapi.Accomplishments() |
831 | 88 | api.stop_daemon() | 94 | api.stop_daemon() |
833 | 89 | 95 | ||
834 | 90 | launchdaemon = True | 96 | launchdaemon = True |
836 | 91 | 97 | ||
837 | 92 | if launchdaemon: | 98 | if launchdaemon: |
838 | 93 | print "Launching the daemon..." | 99 | print "Launching the daemon..." |
839 | 94 | # Create the cache directories. | 100 | # Create the cache directories. |
840 | 95 | if not os.path.exists(cache_dir): | 101 | if not os.path.exists(cache_dir): |
841 | 96 | os.makedirs(cache_dir) | 102 | os.makedirs(cache_dir) |
845 | 97 | if not os.path.exists(os.path.join(cache_dir,"logs")): | 103 | if not os.path.exists(os.path.join(cache_dir, "logs")): |
846 | 98 | os.makedirs(os.path.join(cache_dir,"logs")) | 104 | os.makedirs(os.path.join(cache_dir, "logs")) |
847 | 99 | 105 | ||
848 | 100 | # Remove the pid file if for some reasons it's still present. | 106 | # Remove the pid file if for some reasons it's still present. |
849 | 101 | if os.path.exists(pidfile_path): | 107 | if os.path.exists(pidfile_path): |
852 | 102 | os.remove(pidfile_path) | 108 | os.remove(pidfile_path) |
853 | 103 | 109 | ||
854 | 104 | if not args.foreground: | 110 | if not args.foreground: |
855 | 105 | command = "twistd -y " + os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --logfile=" + os.path.join(cache_dir, "logs", "daemon.log") + " --pidfile=" + pidfile_path | 111 | command = "twistd -y " + os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --logfile=" + os.path.join(cache_dir, "logs", "daemon.log") + " --pidfile=" + pidfile_path |
856 | 106 | else: | 112 | else: |
857 | 107 | command = "twistd -noy " + os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --pidfile=" + pidfile_path | 113 | command = "twistd -noy " + os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --pidfile=" + pidfile_path |
861 | 108 | 114 | ||
862 | 109 | #print command | 115 | # print command |
863 | 110 | 116 | ||
864 | 111 | os.system(command) | 117 | os.system(command) |
866 | 112 | 118 | ||
867 | 119 | |||
868 | 113 | def is_daemon_running(): | 120 | def is_daemon_running(): |
869 | 114 | from accomplishments.daemon.dbusapi import daemon_is_registered | 121 | from accomplishments.daemon.dbusapi import daemon_is_registered |
870 | 115 | return daemon_is_registered() | 122 | return daemon_is_registered() |
874 | 116 | 123 | ||
875 | 117 | 124 | ||
876 | 118 | if __name__=="__main__": | 125 | if __name__ == "__main__": |
877 | 119 | # If run directly... | 126 | # If run directly... |
878 | 120 | main() | 127 | main() |
881 | 121 | 128 | ||
882 | 122 | if __name__=="__builtin__": | 129 | if __name__ == "__builtin__": |
883 | 123 | # This part of code is executed only if the script is run by twistd. | 130 | # This part of code is executed only if the script is run by twistd. |
884 | 124 | # It is responsible for setting up and launching the twistd daemon. | 131 | # It is responsible for setting up and launching the twistd daemon. |
886 | 125 | 132 | ||
887 | 126 | # This piece of code cannot be wrapped inside a function, as silly | 133 | # This piece of code cannot be wrapped inside a function, as silly |
888 | 127 | # twistd blindly searches fora global variable named "application", | 134 | # twistd blindly searches fora global variable named "application", |
889 | 128 | # and therefore while this code must be exposed. | 135 | # and therefore while this code must be exposed. |
891 | 129 | 136 | ||
892 | 130 | # Reactor has to be installed before any import statements. | 137 | # Reactor has to be installed before any import statements. |
893 | 131 | from twisted.internet import gireactor | 138 | from twisted.internet import gireactor |
894 | 132 | gireactor.install() | 139 | gireactor.install() |
895 | 133 | 140 | ||
896 | 134 | from accomplishments.daemon import app | 141 | from accomplishments.daemon import app |
897 | 135 | from accomplishments.util import paths | 142 | from accomplishments.util import paths |
899 | 136 | 143 | ||
900 | 137 | # Ensure the sync daemon is running. The following command can be run in the | 144 | # Ensure the sync daemon is running. The following command can be run in the |
901 | 138 | # background (&), because it would block the daemon from running for few | 145 | # background (&), because it would block the daemon from running for few |
902 | 139 | # seconds, while the syncdaemon will not be needed immediatelly after | 146 | # seconds, while the syncdaemon will not be needed immediatelly after |