Merge lp:~mfisch/ubuntu-accomplishments-daemon/cleanup into lp:ubuntu-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
Reviewer Review Type Date Requested Status
Ubuntu Accomplishments Daemon Developers Pending
Review via email: mp+141144@code.launchpad.net

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:

http://paste.ubuntu.com/1456270/

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
=== modified file 'accomplishments/daemon/api.py'
--- accomplishments/daemon/api.py 2012-12-12 21:02:59 +0000
+++ accomplishments/daemon/api.py 2012-12-22 03:54:22 +0000
@@ -20,22 +20,14 @@
20import datetime20import datetime
21import getpass21import getpass
22import glob22import glob
23#import gobject23# import gobject
24import gpgme24import gpgme
25import json
26import os25import os
27import pwd
28import subprocess
29import time26import time
30import locale27import locale
31from collections import deque28from collections import deque
3229
33import dbus
34import dbus.service
35
36from twisted.internet import defer, reactor30from twisted.internet import defer, reactor
37from twisted.internet.protocol import ProcessProtocol
38from twisted.python import filepath
39from twisted.python import log31from twisted.python import log
4032
41import xdg.BaseDirectory33import xdg.BaseDirectory
@@ -53,7 +45,7 @@
53import accomplishments45import accomplishments
54from accomplishments import exceptions46from accomplishments import exceptions
55from accomplishments.daemon import dbusapi47from accomplishments.daemon import dbusapi
56from accomplishments.util import get_data_file, SubprocessReturnCodeProtocol48from accomplishments.util import SubprocessReturnCodeProtocol
57from accomplishments.util.paths import daemon_exec_dir, media_dir, module_dir1, module_dir2, installed, locale_dir49from accomplishments.util.paths import daemon_exec_dir, media_dir, module_dir1, module_dir2, installed, locale_dir
5850
59gettext.bindtextdomain('accomplishments-daemon', locale_dir)51gettext.bindtextdomain('accomplishments-daemon', locale_dir)
@@ -64,7 +56,8 @@
64# may happen to be in a completely different directory, if the daemon was56# may happen to be in a completely different directory, if the daemon was
65# installed using a non-default prefix.57# installed using a non-default prefix.
66if installed:58if installed:
67 os.environ["PYTHONPATH"] = module_dir1 + ":" + module_dir2 + ":" + os.environ["PYTHONPATH"]59 os.environ["PYTHONPATH"] = module_dir1 + ":" + module_dir2 + ":" + \
60 os.environ["PYTHONPATH"]
6861
69LOCAL_USERNAME = getpass.getuser()62LOCAL_USERNAME = getpass.getuser()
70SCRIPT_DELAY = 90063SCRIPT_DELAY = 900
@@ -72,7 +65,7 @@
72STAGING_ID = "openiduser204307" # staging ID65STAGING_ID = "openiduser204307" # staging ID
73PRODUCTION_ID = "openiduser155707" # production ID66PRODUCTION_ID = "openiduser155707" # production ID
7467
75#flags used for scripts_state68# flags used for scripts_state
76NOT_RUNNING = 069NOT_RUNNING = 0
77RUNNING = 170RUNNING = 1
7871
@@ -156,7 +149,8 @@
156 signal_ok='FolderCreated', success_filter=success_filter)149 signal_ok='FolderCreated', success_filter=success_filter)
157150
158 self.parent.sd.offer_share(151 self.parent.sd.offer_share(
159 trophydir, self.parent.matrix_username, LOCAL_USERNAME + " Trophies Folder"152 trophydir, self.parent.matrix_username, LOCAL_USERNAME +
153 " Trophies Folder"
160 + " (" + timeid + ")", "Modify")154 + " (" + timeid + ")", "Modify")
161 log.msg(155 log.msg(
162 "...share has been offered (" + trophydir + "" + ", "156 "...share has been offered (" + trophydir + "" + ", "
@@ -180,7 +174,8 @@
180 # XXX let's break this out into a separate folder-sharing method174 # XXX let's break this out into a separate folder-sharing method
181 log.msg("...the '%s' folder is not shared" % trophydir)175 log.msg("...the '%s' folder is not shared" % trophydir)
182 self.parent.sd.offer_share(176 self.parent.sd.offer_share(
183 trophydir, self.parent.matrix_username, LOCAL_USERNAME + " Trophies Folder"177 trophydir, self.parent.matrix_username, LOCAL_USERNAME +
178 " Trophies Folder"
184 + " (" + timeid + ")", "Modify")179 + " (" + timeid + ")", "Modify")
185 log.msg("...share has been offered (" + trophydir + "" + ", "180 log.msg("...share has been offered (" + trophydir + "" + ", "
186 + self.parent.matrix_username + ", " + LOCAL_USERNAME + ")")181 + self.parent.matrix_username + ", " + LOCAL_USERNAME + ")")
@@ -203,7 +198,7 @@
203 return198 return
204199
205 self.scripts_state = RUNNING200 self.scripts_state = RUNNING
206 201
207 if not dbusapi.daemon_is_registered():202 if not dbusapi.daemon_is_registered():
208 return203 return
209204
@@ -213,7 +208,8 @@
213208
214 queuesize = len(self.parent.scripts_queue)209 queuesize = len(self.parent.scripts_queue)
215210
216 log.msg("--- Starting Running Scripts - %d items on the queue ---" % (queuesize))211 log.msg("--- Starting Running Scripts - %d items on the queue ---" %
212 (queuesize))
217 timestart = time.time()213 timestart = time.time()
218 if not self.parent.test_mode:214 if not self.parent.test_mode:
219 self.parent.service.scriptrunner_start()215 self.parent.service.scriptrunner_start()
@@ -257,7 +253,7 @@
257 queuesize = len(self.parent.scripts_queue)253 queuesize = len(self.parent.scripts_queue)
258254
259 log.msg("The queue is now empty - stopping the scriptrunner.")255 log.msg("The queue is now empty - stopping the scriptrunner.")
260 256
261 # XXX eventually the code in this method will be rewritten using257 # XXX eventually the code in this method will be rewritten using
262 # deferreds; as such, we're going to have to be more clever regarding258 # deferreds; as such, we're going to have to be more clever regarding
263 # timing things...259 # timing things...
@@ -291,7 +287,7 @@
291 self.lang = locale.getdefaultlocale()[0]287 self.lang = locale.getdefaultlocale()[0]
292288
293 # use this to override the language for testing289 # use this to override the language for testing
294 #self.lang = "pt_BR"290 # self.lang = "pt_BR"
295 self.accomlangs = []291 self.accomlangs = []
296 self.service = service292 self.service = service
297 self.asyncapi = AsyncAPI(self)293 self.asyncapi = AsyncAPI(self)
@@ -346,7 +342,8 @@
346 self.reload_accom_database()342 self.reload_accom_database()
347343
348 if not self.test_mode:344 if not self.test_mode:
349 self.sd.connect_signal("DownloadFinished", self._process_received_trophy_file)345 self.sd.connect_signal(
346 "DownloadFinished", self._process_received_trophy_file)
350347
351 self._refresh_share_data()348 self._refresh_share_data()
352349
@@ -556,7 +553,8 @@
556 for s in shares:553 for s in shares:
557 if s["other_username"] == self.matrix_username:554 if s["other_username"] == self.matrix_username:
558 if s["subscribed"] == "True":555 if s["subscribed"] == "True":
559 matchingshares.append({"name": s["name"], "share_id": s["volume_id"]})556 matchingshares.append(
557 {"name": s["name"], "share_id": s["volume_id"]})
560558
561 if len(matchingshares) > 1:559 if len(matchingshares) > 1:
562 log.msg("Could not find unique active share.")560 log.msg("Could not find unique active share.")
@@ -626,7 +624,8 @@
626624
627 infoneeded = []625 infoneeded = []
628 # and prepend the path to the directory, where all extra-information626 # and prepend the path to the directory, where all extra-information
629 # is stored [like: ~/.local/share/accomplishments/trophies/.extrainformation/]627 # is stored [like:
628 # ~/.local/share/accomplishments/trophies/.extrainformation/]
630 trophyextrainfo = os.path.join(629 trophyextrainfo = os.path.join(
631 self.trophies_path, ".extrainformation/")630 self.trophies_path, ".extrainformation/")
632631
@@ -640,9 +639,11 @@
640 # get the path to the directory of accomplishments set's639 # get the path to the directory of accomplishments set's
641 # "extrainformation" dir - it is useful, because it contains640 # "extrainformation" dir - it is useful, because it contains
642 # translated labels and descriptions641 # translated labels and descriptions
643 accomextrainfo = os.path.join(self.accomDB[accom]['base-path'], "extrainformation")642 accomextrainfo = os.path.join(
643 self.accomDB[accom]['base-path'], "extrainformation")
644644
645 # a temporary variable, representing a single entry of the list this function returns645 # a temporary variable, representing a single entry of the list
646 # this function returns
646 d = {}647 d = {}
647648
648 # Get collection name from accomOD649 # Get collection name from accomOD
@@ -653,23 +654,30 @@
653654
654 # For each needed piece of information:655 # For each needed piece of information:
655 for i in ei:656 for i in ei:
656 label = self.accomDB[collection]['extra-information'][i]['label']657 label = self.accomDB[collection][
657 desc = self.accomDB[collection]['extra-information'][i]['description']658 'extra-information'][i]['label']
658 example = self.accomDB[collection]['extra-information'][i].get('example')659 desc = self.accomDB[collection][
660 'extra-information'][i]['description']
661 example = self.accomDB[collection][
662 'extra-information'][i].get('example')
659 if example is None:663 if example is None:
660 example = ''664 example = ''
661 regex = self.accomDB[collection]['extra-information'][i].get('regex')665 regex = self.accomDB[collection][
666 'extra-information'][i].get('regex')
662 if regex is None:667 if regex is None:
663 regex = ''668 regex = ''
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.
665 # to do this, simply check whether trophies/.extrainformation/<item> file exists.670 # to do this, simply check whether
671 # trophies/.extrainformation/<item> file exists.
666 try:672 try:
667 valuefile = open(os.path.join(trophyextrainfo, i))673 valuefile = open(os.path.join(trophyextrainfo, i))
668 # if we got here without an exception, it means that the file exists674 # if we got here without an exception, it means that the file exists
669 # so, we can read it's value675 # so, we can read it's value
670 value = valuefile.readline()676 value = valuefile.readline()
671 value = value.rstrip() # get rid of the tailing newline677 value = value.rstrip(
672 # and build up the dictionary of all data for a single ExtraInformation field678 ) # get rid of the tailing newline
679 # and build up the dictionary of all data for a single
680 # ExtraInformation field
673 d = {681 d = {
674 "collection": collection,682 "collection": collection,
675 "needs-information": i,683 "needs-information": i,
@@ -679,7 +687,9 @@
679 "regex": regex,687 "regex": regex,
680 "value": value}688 "value": value}
681 except IOError as e:689 except IOError as e:
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 empty690 # we got an exception, so it seems that the file is not
691 # present - we'll use "" as the value, to indicate that
692 # it's empty
683 d = {693 d = {
684 "collection": collection,694 "collection": collection,
685 "needs-information": i,695 "needs-information": i,
@@ -689,11 +699,13 @@
689 "regex": regex,699 "regex": regex,
690 "value": ""}700 "value": ""}
691701
692 # since the collected all data related to this particular ExtraInformation field, append it to the list702 # since the collected all data related to this particular
703 # ExtraInformation field, append it to the list
693 infoneeded.append(d)704 infoneeded.append(d)
694705
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,
696 # for the items have been added multiple times, if they are mentioned in more then one .accomplishment file707 # for the items have been added multiple times, if they are mentioned
708 # in more then one .accomplishment file
697 final = []709 final = []
698 for x in infoneeded: # for each item in the original list...710 for x in infoneeded: # for each item in the original list...
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.
@@ -713,16 +725,17 @@
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" : ""}]
714726
715 """727 """
716 #fetch a full list of ExtraInformation728 # fetch a full list of ExtraInformation
717 data = self.get_all_extra_information()729 data = self.get_all_extra_information()
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 == ""
719 #this way we can return a list of ExtraInformation fields, that have not been write_config_file_item731 # this way we can return a list of ExtraInformation fields, that have
732 # not been write_config_file_item
720 result = []733 result = []
721 for i in data: # for each ExtraInformation in the full list734 for i in data: # for each ExtraInformation in the full list
722 if not i['value']: # if the value string is empty, so this ExtraInformation field have not been yet set735 if not i['value']: # if the value string is empty, so this ExtraInformation field have not been yet set
723 i.pop('value') # remove the 'value' field (it's empty anyway)736 i.pop('value') # remove the 'value' field (it's empty anyway)
724 result.append(i) # add this entry to the resulting list737 result.append(i) # add this entry to the resulting list
725 #do not add these fields, that have some value738 # do not add these fields, that have some value
726739
727 return result740 return result
728741
@@ -732,14 +745,16 @@
732 does not overwrite any existing data745 does not overwrite any existing data
733 """746 """
734747
735 # XXX this should be removed as we are using write_extra_information_file748 # XXX this should be removed as we are using
749 # write_extra_information_file
736 log.msg("Creating Extra Information file: %s, %s" % (item, data))750 log.msg("Creating Extra Information file: %s, %s" % (item, data))
737 extrainfodir = os.path.join(self.trophies_path, ".extrainformation/")751 extrainfodir = os.path.join(self.trophies_path, ".extrainformation/")
738752
739 if not os.path.isdir(extrainfodir):753 if not os.path.isdir(extrainfodir):
740 os.makedirs(extrainfodir)754 os.makedirs(extrainfodir)
741 try:755 try:
742 open(os.path.join(extrainfodir, item)) # if the file already exists, do not overwrite it756 open(os.path.join(extrainfodir, item))
757 # if the file already exists, do not overwrite it
743 pass758 pass
744 except IOError as e:759 except IOError as e:
745 f = open(os.path.join(extrainfodir, item), 'w')760 f = open(os.path.join(extrainfodir, item), 'w')
@@ -787,11 +802,12 @@
787 os.makedirs(extrainfodir)802 os.makedirs(extrainfodir)
788803
789 if data:804 if data:
790 f = open(os.path.join(extrainfodir, item), 'w') # will trunkate the file, in case it exist805 f = open(os.path.join(extrainfodir, item), 'w')
806 # will trunkate the file, in case it exist
791 f.write(data)807 f.write(data)
792 f.close()808 f.close()
793 else:809 else:
794 #file would be empty, remove it instead810 # file would be empty, remove it instead
795 os.remove(os.path.join(extrainfodir, item))811 os.remove(os.path.join(extrainfodir, item))
796812
797 # Returns True if all extra information is available for an accom,813 # Returns True if all extra information is available for an accom,
@@ -864,7 +880,7 @@
864 data = f.read()880 data = f.read()
865 final = [{item: data, "label": label}]881 final = [{item: data, "label": label}]
866 except IOError as e:882 except IOError as e:
867 #print "No data."883 # print "No data."
868 final = [{item: "", "label": label}]884 final = [{item: "", "label": label}]
869 return final885 return final
870886
@@ -905,7 +921,8 @@
905 for collection in collections:921 for collection in collections:
906 # For each collection...922 # For each collection...
907 if collection in self.accomDB:923 if collection in self.accomDB:
908 # This collection has already been loaded from another install path!924 # This collection has already been loaded from another
925 # install path!
909 continue926 continue
910927
911 collpath = os.path.join(path, collection)928 collpath = os.path.join(path, collection)
@@ -917,7 +934,8 @@
917934
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")):
919 print aboutpath936 print aboutpath
920 raise LookupError("Accomplishment collection with invalid ABOUT file ")937 raise LookupError(
938 "Accomplishment collection with invalid ABOUT file ")
921939
922 langdefault = cfg.get("general", "langdefault")940 langdefault = cfg.get("general", "langdefault")
923 collectionname = cfg.get("general", "name")941 collectionname = cfg.get("general", "name")
@@ -934,14 +952,16 @@
934 accompath = os.path.join(langdefaultpath, accomset)952 accompath = os.path.join(langdefaultpath, accomset)
935 accomcfg = ConfigParser.RawConfigParser()953 accomcfg = ConfigParser.RawConfigParser()
936 # check if there is a translated version...954 # check if there is a translated version...
937 translatedpath = os.path.join(os.path.join(collpath, self.lang), accomset)955 translatedpath = os.path.join(
956 os.path.join(collpath, self.lang), accomset)
938 if os.path.exists(translatedpath):957 if os.path.exists(translatedpath):
939 # yes, so use the translated file958 # yes, so use the translated file
940 readpath = translatedpath959 readpath = translatedpath
941 langused = self.lang960 langused = self.lang
942 else:961 else:
943 # no. maybe there is a shorter language code?962 # no. maybe there is a shorter language code?
944 translatedpath = os.path.join(os.path.join(collpath, self.lang.split("_")[0]), accomset)963 translatedpath = os.path.join(os.path.join(
964 collpath, self.lang.split("_")[0]), accomset)
945 if os.path.exists(translatedpath):965 if os.path.exists(translatedpath):
946 readpath = translatedpath966 readpath = translatedpath
947 langused = self.lang.split("_")[0]967 langused = self.lang.split("_")[0]
@@ -975,7 +995,8 @@
975 accomdata['categories'] = []995 accomdata['categories'] = []
976 for cat in cats:996 for cat in cats:
977 catsplitted = cat.rstrip().lstrip().split(":")997 catsplitted = cat.rstrip().lstrip().split(":")
978 accomdata['categories'].append(cat.rstrip().lstrip())998 accomdata['categories'].append(
999 cat.rstrip().lstrip())
979 if catsplitted[0] in collcategories:1000 if catsplitted[0] in collcategories:
980 pass1001 pass
981 else:1002 else:
@@ -983,7 +1004,8 @@
983 if len(catsplitted) > 1:1004 if len(catsplitted) > 1:
984 # category + subcategory1005 # category + subcategory
985 if catsplitted[1] not in collcategories[catsplitted[0]]:1006 if catsplitted[1] not in collcategories[catsplitted[0]]:
986 collcategories[catsplitted[0]].append(catsplitted[1])1007 collcategories[catsplitted[
1008 0]].append(catsplitted[1])
987 del accomdata['category']1009 del accomdata['category']
988 else:1010 else:
989 accomdata['categories'] = []1011 accomdata['categories'] = []
@@ -1025,7 +1047,8 @@
1025 "Parse error is: %s" % (readpath, e.message))1047 "Parse error is: %s" % (readpath, e.message))
1026 continue1048 continue
10271049
1028 accomdata = dict(accomcfg._sections["accomplishment"])1050 accomdata = dict(
1051 accomcfg._sections["accomplishment"])
1029 accomID = collection + "/" + accomfile[:-15]1052 accomID = collection + "/" + accomfile[:-15]
1030 if 'author' in accomdata:1053 if 'author' in accomdata:
1031 collauthors.add(accomdata['author'])1054 collauthors.add(accomdata['author'])
@@ -1041,8 +1064,10 @@
1041 categories = []1064 categories = []
1042 accomdata['categories'] = []1065 accomdata['categories'] = []
1043 for cat in cats:1066 for cat in cats:
1044 catsplitted = cat.rstrip().lstrip().split(":")1067 catsplitted = cat.rstrip(
1045 accomdata['categories'].append(cat.rstrip().lstrip())1068 ).lstrip().split(":")
1069 accomdata['categories'].append(
1070 cat.rstrip().lstrip())
1046 if catsplitted[0] in collcategories:1071 if catsplitted[0] in collcategories:
1047 pass1072 pass
1048 else:1073 else:
@@ -1050,7 +1075,8 @@
1050 if len(catsplitted) > 1:1075 if len(catsplitted) > 1:
1051 # category + subcategory1076 # category + subcategory
1052 if catsplitted[1] not in collcategories[catsplitted[0]]:1077 if catsplitted[1] not in collcategories[catsplitted[0]]:
1053 collcategories[catsplitted[0]].append(catsplitted[1])1078 collcategories[catsplitted[
1079 0]].append(catsplitted[1])
1054 del accomdata['category']1080 del accomdata['category']
1055 else:1081 else:
1056 accomdata['categories'] = []1082 accomdata['categories'] = []
@@ -1076,7 +1102,8 @@
1076 if eicfg.has_option("description", self.lang):1102 if eicfg.has_option("description", self.lang):
1077 description = eicfg.get("description", self.lang)1103 description = eicfg.get("description", self.lang)
1078 elif eicfg.has_option("description", self.lang.split("_")[0]):1104 elif eicfg.has_option("description", self.lang.split("_")[0]):
1079 description = eicfg.get("description", self.lang.split("_")[0])1105 description = eicfg.get(
1106 "description", self.lang.split("_")[0])
1080 else:1107 else:
1081 description = eicfg.get("description", langdefault)1108 description = eicfg.get("description", langdefault)
10821109
@@ -1108,7 +1135,7 @@
1108 self._update_all_locked_and_accomplished_statuses()1135 self._update_all_locked_and_accomplished_statuses()
11091136
1110 self.create_all_trophy_icons()1137 self.create_all_trophy_icons()
1111 1138
1112 if not self.test_mode:1139 if not self.test_mode:
1113 self.service.accoms_collections_reloaded()1140 self.service.accoms_collections_reloaded()
1114 # Uncomment following for debugging1141 # Uncomment following for debugging
@@ -1553,7 +1580,8 @@
15531580
1554 # Check if is hasn't been already accomplished1581 # Check if is hasn't been already accomplished
1555 if self.get_accom_is_accomplished(accomID):1582 if self.get_accom_is_accomplished(accomID):
1556 log.msg("Not accomplishing " + accomID + ", it has already been accomplished.")1583 log.msg("Not accomplishing " + accomID +
1584 ", it has already been accomplished.")
1557 return True # success1585 return True # success
15581586
1559 # Check if this accomplishment is unlocked1587 # Check if this accomplishment is unlocked
@@ -1641,23 +1669,28 @@
1641 log.msg(type(value))1669 log.msg(type(value))
1642 if value == True:1670 if value == True:
1643 log.msg("setting")1671 log.msg("setting")
1644 command = os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --start"1672 command = os.path.join(
1673 daemon_exec_dir, "accomplishments-daemon") + " --start"
1645 filetext = "[Desktop Entry]\n\1674 filetext = "[Desktop Entry]\n\
1646Type=Application\n\1675Type=Application\n\
1647Encoding=UTF-8\n\1676Encoding=UTF-8\n\
1648Name=Accomplishments Daemon\n\1677Name=Accomplishments Daemon\n\
1649Exec=" + command + "\n\1678Exec=" + command + "\n\
1650NoDisplay=true"1679NoDisplay=true"
1651 filename = os.path.join(self.dir_autostart, "accomplishments-daemon.desktop")1680 filename = os.path.join(
1681 self.dir_autostart, "accomplishments-daemon.desktop")
1652 file = open(filename, "w")1682 file = open(filename, "w")
1653 file.write(filetext)1683 file.write(filetext)
1654 file.close1684 file.close
1655 self.write_config_file_item("config", "daemon_sessionstart", "true")1685 self.write_config_file_item(
1686 "config", "daemon_sessionstart", "true")
1656 elif value == False:1687 elif value == False:
1657 filename = os.path.join(self.dir_autostart, "accomplishments-daemon.desktop")1688 filename = os.path.join(
1689 self.dir_autostart, "accomplishments-daemon.desktop")
1658 if os.path.exists(filename):1690 if os.path.exists(filename):
1659 os.remove(filename)1691 os.remove(filename)
1660 self.write_config_file_item("config", "daemon_sessionstart", "false")1692 self.write_config_file_item(
1693 "config", "daemon_sessionstart", "false")
16611694
1662 def get_daemon_session_start(self):1695 def get_daemon_session_start(self):
1663 return self.get_config_value("config", "daemon_sessionstart")1696 return self.get_config_value("config", "daemon_sessionstart")
@@ -1685,7 +1718,8 @@
1685 with open(cfile, 'wb') as configfile:1718 with open(cfile, 'wb') as configfile:
1686 config.write(configfile)1719 config.write(configfile)
16871720
1688 # restart SyncDaemonTool to use new settings immediately, fixes LP#10119031721 # restart SyncDaemonTool to use new settings immediately, fixes
1722 # LP#1011903
1689 self.ubuntuone_restart_syncdaemontool()1723 self.ubuntuone_restart_syncdaemontool()
16901724
1691 # XXX - NEEDS UNIT TEST1725 # XXX - NEEDS UNIT TEST
@@ -1724,7 +1758,7 @@
17241758
1725 def _display_accomplished_bubble(self, accomID):1759 def _display_accomplished_bubble(self, accomID):
1726 if self.show_notifications == True and useNotify and (1760 if self.show_notifications == True and useNotify and (
1727 Notify.is_initted() or Notify.init("icon-summary-body")):1761 Notify.is_initted() or Notify.init("icon-summary-body")):
1728 n = Notify.Notification.new(1762 n = Notify.Notification.new(
1729 _("You have accomplished something!"),1763 _("You have accomplished something!"),
1730 self.get_accom_title(accomID),1764 self.get_accom_title(accomID),
@@ -1736,7 +1770,7 @@
1736 unlocked = len(self.list_depending_on(accomID))1770 unlocked = len(self.list_depending_on(accomID))
1737 if unlocked is not 0:1771 if unlocked is not 0:
1738 if self.show_notifications == True and useNotify and (1772 if self.show_notifications == True and useNotify and (
1739 Notify.is_initted() or Notify.init("icon-summary-body")):1773 Notify.is_initted() or Notify.init("icon-summary-body")):
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))
1741 n = Notify.Notification.new(1775 n = Notify.Notification.new(
1742 _("Opportunities Unlocked!"), message,1776 _("Opportunities Unlocked!"), message,
@@ -1750,11 +1784,11 @@
17501784
1751 def _get_is_asc_correct(self, filepath):1785 def _get_is_asc_correct(self, filepath):
1752 if not os.path.exists(filepath):1786 if not os.path.exists(filepath):
1753 log.msg("Cannot check if signature is correct, because file"\1787 log.msg("Cannot check if signature is correct, because file"
1754 "%s does not exist" % filepath)1788 "%s does not exist" % filepath)
1755 return False1789 return False
1756 elif not os.path.exists(filepath[:-4]):1790 elif not os.path.exists(filepath[:-4]):
1757 log.msg("Cannot check if signature is correct, because file"\1791 log.msg("Cannot check if signature is correct, because file"
1758 "%s does not exist" % filepath[:-4])1792 "%s does not exist" % filepath[:-4])
1759 return False1793 return False
1760 else:1794 else:
@@ -1782,7 +1816,8 @@
1782 return False1816 return False
1783 else:1817 else:
1784 # Correct!1818 # Correct!
1785 # result = {'timestamp': sig[0].timestamp, 'signer': sig[0].fpr}1819 # result = {'timestamp': sig[0].timestamp, 'signer':
1820 # sig[0].fpr}
1786 return True1821 return True
17871822
1788 def _check_if_accom_is_accomplished(self, accomID):1823 def _check_if_accom_is_accomplished(self, accomID):
@@ -1817,13 +1852,15 @@
1817 def _update_all_locked_and_accomplished_statuses(self):1852 def _update_all_locked_and_accomplished_statuses(self):
1818 accoms = self.list_accoms()1853 accoms = self.list_accoms()
1819 for accom in accoms:1854 for accom in accoms:
1820 self.accomDB[accom]['accomplished'] = self._check_if_accom_is_accomplished(accom)1855 self.accomDB[accom][
1856 'accomplished'] = self._check_if_accom_is_accomplished(accom)
1821 if self.accomDB[accom]['accomplished'] == True:1857 if self.accomDB[accom]['accomplished'] == True:
1822 self.accomDB[accom]['date-accomplished'] = self._get_trophy_date_accomplished(accom)1858 self.accomDB[accom]['date-accomplished'] = self._get_trophy_date_accomplished(accom)
1823 else:1859 else:
1824 self.accomDB[accom]['date-accomplished'] = "None"1860 self.accomDB[accom]['date-accomplished'] = "None"
1825 for accom in accoms:1861 for accom in accoms:
1826 self.accomDB[accom]['locked'] = self._check_if_accom_is_locked(accom)1862 self.accomDB[accom][
1863 'locked'] = self._check_if_accom_is_locked(accom)
18271864
1828 # XXX - NEEDS UNIT TEST1865 # XXX - NEEDS UNIT TEST
1829 def _get_trophy_date_accomplished(self, accomID):1866 def _get_trophy_date_accomplished(self, accomID):
@@ -1844,18 +1881,20 @@
1844 # Marks accomplishments as accomplished in the accomDB, and1881 # Marks accomplishments as accomplished in the accomDB, and
1845 # returns a list of accomIDs that just got unlocked.1882 # returns a list of accomIDs that just got unlocked.
1846 self.accomDB[accomID]['accomplished'] = True1883 self.accomDB[accomID]['accomplished'] = True
1847 self.accomDB[accomID]['date-accomplished'] = self._get_trophy_date_accomplished(accomID)1884 self.accomDB[accomID][
1885 'date-accomplished'] = self._get_trophy_date_accomplished(accomID)
1848 accoms = self.list_depending_on(accomID)1886 accoms = self.list_depending_on(accomID)
1849 res = []1887 res = []
1850 for accom in accoms:1888 for accom in accoms:
1851 before = self.accomDB[accom]['locked']1889 before = self.accomDB[accom]['locked']
1852 self.accomDB[accom]['locked'] = self._check_if_accom_is_locked(accom)1890 self.accomDB[accom][
1891 'locked'] = self._check_if_accom_is_locked(accom)
1853 # If it just got unlocked...1892 # If it just got unlocked...
1854 if (before == True and self.accomDB[accom]['locked'] == False):1893 if (before == True and self.accomDB[accom]['locked'] == False):
1855 res.append(accom)1894 res.append(accom)
1856 return res1895 return res
18571896
1858 #Other significant system functions1897 # Other significant system functions
18591898
1860 def get_API_version(self):1899 def get_API_version(self):
1861 return "0.2"1900 return "0.2"
18621901
=== modified file 'accomplishments/daemon/app.py'
--- accomplishments/daemon/app.py 2012-08-17 18:22:47 +0000
+++ accomplishments/daemon/app.py 2012-12-22 03:54:22 +0000
@@ -1,24 +1,9 @@
1from optparse import OptionParser1from optparse import OptionParser
22
3from twisted.application.internet import TimerService
4from twisted.application.service import Application3from twisted.application.service import Application
54
6from accomplishments.daemon import dbusapi5from accomplishments.daemon import dbusapi
7from accomplishments.daemon import service6from accomplishments.daemon import service
8from accomplishments.daemon import api
9
10
11# XXX these won't work with twistd; we need to write a twistd plugin to support
12# additional command line options.
13def parse_options():
14 parser = OptionParser()
15 parser.set_defaults(suppress_notifications=False)
16 parser.add_option("--trophies-path", dest="trophies_path", default=None)
17 parser.add_option("--accomplishments-path", dest="accomplishments_installpaths",
18 default=None)
19 parser.add_option("--suppress-notifications", action="store_true",
20 dest="suppress_notifications")
21 return parser.parse_args()
227
238
24def applicationFactory(app_name="", bus_name="", main_loop=None,9def applicationFactory(app_name="", bus_name="", main_loop=None,
2510
=== modified file 'accomplishments/daemon/dbusapi.py'
--- accomplishments/daemon/dbusapi.py 2012-11-29 19:33:30 +0000
+++ accomplishments/daemon/dbusapi.py 2012-12-22 03:54:22 +0000
@@ -11,12 +11,8 @@
11"""11"""
1212
13import dbus13import dbus
14
15from twisted.python import log
16
17from accomplishments.daemon import service14from accomplishments.daemon import service
1815
19
20def daemon_is_registered():16def daemon_is_registered():
21 try:17 try:
22 obj = dbus.SessionBus().get_object(18 obj = dbus.SessionBus().get_object(
@@ -408,10 +404,10 @@
408 ["Launchpad"]404 ["Launchpad"]
409 """405 """
410 return self.api.get_accom_categories(accomID)406 return self.api.get_accom_categories(accomID)
411 407
412 @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',408 @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',
413 in_signature="s", out_signature="as")409 in_signature="s", out_signature="as")
414 def get_accom_keywords(self,accomID):410 def get_accom_keywords(self, accomID):
415 return self.api.get_accom_keywords(accomID)411 return self.api.get_accom_keywords(accomID)
416412
417 @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',413 @dbus.service.method(dbus_interface='org.ubuntu.accomplishments',
@@ -911,12 +907,11 @@
911 def create_all_trophy_icons(self):907 def create_all_trophy_icons(self):
912 return self.api.create_all_trophy_icons()908 return self.api.create_all_trophy_icons()
913909
914
915 # XXX this looks like an unintentional duplicate of the "other"910 # XXX this looks like an unintentional duplicate of the "other"
916 # trophy_received... I've moved them here together so that someone in the911 # trophy_received... I've moved them here together so that someone in the
917 # know (Jono?) can clarify and remove the one that's not needed912 # know (Jono?) can clarify and remove the one that's not needed
918 #@dbus.service.signal(dbus_interface='org.ubuntu.accomplishments')913 #@dbus.service.signal(dbus_interface='org.ubuntu.accomplishments')
919 #def trophy_received(self, trophy):914 # def trophy_received(self, trophy):
920 # pass915 # pass
921 @dbus.service.signal(dbus_interface='org.ubuntu.accomplishments')916 @dbus.service.signal(dbus_interface='org.ubuntu.accomplishments')
922 def trophy_received(self, trophy):917 def trophy_received(self, trophy):
923918
=== modified file 'accomplishments/util/__init__.py'
--- accomplishments/util/__init__.py 2012-08-17 18:22:47 +0000
+++ accomplishments/util/__init__.py 2012-12-22 03:54:22 +0000
@@ -1,4 +1,3 @@
1import logging
2import optparse1import optparse
3import os2import os
43
@@ -22,40 +21,11 @@
22def get_version():21def get_version():
23 return config.__version__22 return config.__version__
2423
25
26class NullHandler(logging.Handler):
27 """
28 """
29 def emit(self, record):
30 pass
31
32
33def set_up_logging(opts):
34 # add a handler to prevent basicConfig
35 root = logging.getLogger()
36 null_handler = NullHandler()
37 root.addHandler(null_handler)
38
39 formatter = logging.Formatter(
40 "%(levelname)s:%(name)s: %(funcName)s() '%(message)s'")
41
42 logger = logging.getLogger('accomplishments-daemon')
43 logger_sh = logging.StreamHandler()
44 logger_sh.setFormatter(formatter)
45 logger.addHandler(logger_sh)
46
47 # Set the logging level to show debug messages.
48 if opts.verbose:
49 logger.setLevel(logging.DEBUG)
50 logger.debug('logging enabled')
51 if opts.verbose > 1:
52 logger.setLevel(logging.DEBUG)
53
54
55def get_data_path():24def get_data_path():
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.
57 # Luckily, this function is no longer used anywhere.26 # Luckily, this function is no longer used anywhere.
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
28 # instead.
59 """Retrieve accomplishments-daemon data path29 """Retrieve accomplishments-daemon data path
6030
61 This path is by default <accomplishments_daemon_lib_path>/../data/ in trunk31 This path is by default <accomplishments_daemon_lib_path>/../data/ in trunk
@@ -64,7 +34,8 @@
64 """34 """
6535
66 # Get pathname absolute or relative.36 # Get pathname absolute or relative.
67 path = os.path.join(accomplishments.__path__[0], config.__accomplishments_daemon_data_directory__)37 path = os.path.join(accomplishments.__path__[0],
38 config.__accomplishments_daemon_data_directory__)
68 abs_data_path = os.path.abspath(path)39 abs_data_path = os.path.abspath(path)
69 log.msg("MODULE DIR")40 log.msg("MODULE DIR")
70 log.msg(accomplishments.__path__[0])41 log.msg(accomplishments.__path__[0])
7142
=== modified file 'accomplishments/util/accomplishments-daemon-config.py'
--- accomplishments/util/accomplishments-daemon-config.py 2012-08-17 18:37:28 +0000
+++ accomplishments/util/accomplishments-daemon-config.py 2012-12-22 03:54:22 +0000
@@ -18,7 +18,7 @@
18# files). By default, this is ../data, relative your trunk layout18# files). By default, this is ../data, relative your trunk layout
19__accomplishments_daemon_data_directory__ = '../data/'19__accomplishments_daemon_data_directory__ = '../data/'
20__license__ = ''20__license__ = ''
21__version__ = '0.1'21__version__ = '0.3'
2222
23import os23import os
2424
2525
=== modified file 'accomplishments/util/dist.py'
--- accomplishments/util/dist.py 2012-08-17 18:37:28 +0000
+++ accomplishments/util/dist.py 2012-12-22 03:54:22 +0000
@@ -21,7 +21,8 @@
21def update_config(values={}):21def update_config(values={}):
22 oldvalues = {}22 oldvalues = {}
23 try:23 try:
24 fin = file('accomplishments/util/accomplishments-daemon-config.py', 'r')24 fin = file(
25 'accomplishments/util/accomplishments-daemon-config.py', 'r')
25 fout = file(fin.name + '.new', 'w')26 fout = file(fin.name + '.new', 'w')
2627
27 for line in fin:28 for line in fin:
2829
=== modified file 'accomplishments/util/paths.py'
--- accomplishments/util/paths.py 2012-08-17 18:37:28 +0000
+++ accomplishments/util/paths.py 2012-12-22 03:54:22 +0000
@@ -20,7 +20,7 @@
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]
21 # basepath should equal to prefix given on installation.21 # basepath should equal to prefix given on installation.
2222
23 #print "Daemon seems to be installed to: " + basepath23 # print "Daemon seems to be installed to: " + basepath
2424
25 # finally, setting these significant data directories...25 # finally, setting these significant data directories...
26 systemdata_dir = os.path.join(basepath, 'share/accomplishments-daemon')26 systemdata_dir = os.path.join(basepath, 'share/accomplishments-daemon')
@@ -41,7 +41,8 @@
41 # using branch root directory as the base path41 # using branch root directory as the base path
42 basepath = branchpath42 basepath = branchpath
4343
44 #print "Daemon seems to be run not installed, branch base path used: " + basepath44 # print "Daemon seems to be run not installed, branch base path used: " +
45 # basepath
4546
46 # finally, setting these significant data directories...47 # finally, setting these significant data directories...
47 systemdata_dir = os.path.join(basepath, 'data/daemon')48 systemdata_dir = os.path.join(basepath, 'data/daemon')
4849
=== modified file 'bin/accomplishments-daemon'
--- bin/accomplishments-daemon 2012-11-21 06:46:02 +0000
+++ bin/accomplishments-daemon 2012-12-22 03:54:22 +0000
@@ -3,12 +3,13 @@
3import sys3import sys
4import os4import os
55
6# Importing from accomplishments.{daemon,util} would fail, if the path 6# Importing from accomplishments.{daemon,util} would fail, if the path
7# is set incorrectly.7# is set incorrectly.
8# We need to ensure that the script will load the correct version of8# We need to ensure that the script will load the correct version of
9# accomplishment.* that is installed with this script.9# accomplishment.* that is installed with this script.
10scriptpath = os.path.abspath(__file__)10scriptpath = os.path.abspath(__file__)
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
12# application is run from source, it does not really matter.
12basepath = os.path.split(os.path.split(scriptpath)[0])[0]13basepath = os.path.split(os.path.split(scriptpath)[0])[0]
13sys.path.insert(0, basepath)14sys.path.insert(0, basepath)
14sys.path.insert(0, basepath + "/lib/python2.7")15sys.path.insert(0, basepath + "/lib/python2.7")
@@ -18,18 +19,23 @@
18# This is a global variable19# This is a global variable
19pidfile_path = None20pidfile_path = None
2021
22
21def main():23def main():
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.
23 import argparse25 import argparse
24 parser = argparse.ArgumentParser(description='Launches the accomplishments daemon.')26 parser = argparse.ArgumentParser(
27 description='Launches the accomplishments daemon.')
25 mode = parser.add_mutually_exclusive_group()28 mode = parser.add_mutually_exclusive_group()
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).")
27 mode.add_argument('--stop',action='store_true',help="Stop the daemon gracefully.")30 mode.add_argument(
28 mode.add_argument('--restart','-r',action='store_true',help="Restart the daemon.")31 '--stop', action='store_true', help="Stop the daemon gracefully.")
29 mode.add_argument('--reload',action='store_true',help="Reload accomplishments collections.")32 mode.add_argument(
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.")
34 mode.add_argument('--reload', action='store_true',
35 help="Reload accomplishments collections.")
36 parser.add_argument('-f', '--foreground', action='store_true', help="When starting the daemon, run it in the foreground, with logs directed to stdout.")
31 args = parser.parse_args()37 args = parser.parse_args()
32 38
33 import xdg.BaseDirectory39 import xdg.BaseDirectory
34 try:40 try:
35 rootdir = os.environ['ACCOMPLISHMENTS_ROOT_DIR']41 rootdir = os.environ['ACCOMPLISHMENTS_ROOT_DIR']
@@ -38,44 +44,44 @@
38 except KeyError:44 except KeyError:
39 cache_dir = os.path.join(45 cache_dir = os.path.join(
40 xdg.BaseDirectory.xdg_cache_home, "accomplishments")46 xdg.BaseDirectory.xdg_cache_home, "accomplishments")
41 47
42 global pidfile_path48 global pidfile_path
43 pidfile_path = os.path.join(cache_dir,"accomplishments-daemon.pid")49 pidfile_path = os.path.join(cache_dir, "accomplishments-daemon.pid")
44 50
45 launchdaemon = False 51 launchdaemon = False
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):
47 # Start the daemon.53 # Start the daemon.
48 54
49 from accomplishments.util.paths import daemon_exec_dir55 from accomplishments.util.paths import daemon_exec_dir
50 # Check if the daemon is already running.56 # Check if the daemon is already running.
51 if is_daemon_running():57 if is_daemon_running():
52 print "The daemon is already running."58 print "The daemon is already running."
53 return59 return
54 60
55 # The daemon is not running.61 # The daemon is not running.
56 launchdaemon = True62 launchdaemon = True
57 63
58 elif args.stop:64 elif args.stop:
59 # Stop the daemon65 # Stop the daemon
60 if not is_daemon_running():66 if not is_daemon_running():
61 print "The daemon is not running."67 print "The daemon is not running."
62 return68 return
63 print "Stopping the daemon..."69 print "Stopping the daemon..."
64 70
65 from accomplishments.daemon import dbusapi71 from accomplishments.daemon import dbusapi
66 api = dbusapi.Accomplishments()72 api = dbusapi.Accomplishments()
67 api.stop_daemon()73 api.stop_daemon()
68 74
69 elif args.reload:75 elif args.reload:
70 if not is_daemon_running():76 if not is_daemon_running():
71 print "The daemon is not running."77 print "The daemon is not running."
72 return78 return
73 print "Reloading accomplishments collections."79 print "Reloading accomplishments collections."
74 80
75 from accomplishments.daemon import dbusapi81 from accomplishments.daemon import dbusapi
76 api = dbusapi.Accomplishments()82 api = dbusapi.Accomplishments()
77 api.reload_accom_database()83 api.reload_accom_database()
78 84
79 elif args.restart:85 elif args.restart:
80 from accomplishments.util.paths import daemon_exec_dir86 from accomplishments.util.paths import daemon_exec_dir
81 # Check if the daemon is already running.87 # Check if the daemon is already running.
@@ -86,54 +92,55 @@
86 from accomplishments.daemon import dbusapi92 from accomplishments.daemon import dbusapi
87 api = dbusapi.Accomplishments()93 api = dbusapi.Accomplishments()
88 api.stop_daemon()94 api.stop_daemon()
89 95
90 launchdaemon = True96 launchdaemon = True
91 97
92 if launchdaemon:98 if launchdaemon:
93 print "Launching the daemon..."99 print "Launching the daemon..."
94 # Create the cache directories.100 # Create the cache directories.
95 if not os.path.exists(cache_dir):101 if not os.path.exists(cache_dir):
96 os.makedirs(cache_dir)102 os.makedirs(cache_dir)
97 if not os.path.exists(os.path.join(cache_dir,"logs")):103 if not os.path.exists(os.path.join(cache_dir, "logs")):
98 os.makedirs(os.path.join(cache_dir,"logs"))104 os.makedirs(os.path.join(cache_dir, "logs"))
99 105
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.
101 if os.path.exists(pidfile_path):107 if os.path.exists(pidfile_path):
102 os.remove(pidfile_path)108 os.remove(pidfile_path)
103 109
104 if not args.foreground:110 if not args.foreground:
105 command = "twistd -y " + os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --logfile=" + os.path.join(cache_dir, "logs", "daemon.log") + " --pidfile=" + pidfile_path111 command = "twistd -y " + os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --logfile=" + os.path.join(cache_dir, "logs", "daemon.log") + " --pidfile=" + pidfile_path
106 else:112 else:
107 command = "twistd -noy " + os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --pidfile=" + pidfile_path113 command = "twistd -noy " + os.path.join(daemon_exec_dir, "accomplishments-daemon") + " --pidfile=" + pidfile_path
108 114
109 #print command115 # print command
110 116
111 os.system(command)117 os.system(command)
112 118
119
113def is_daemon_running():120def is_daemon_running():
114 from accomplishments.daemon.dbusapi import daemon_is_registered121 from accomplishments.daemon.dbusapi import daemon_is_registered
115 return daemon_is_registered()122 return daemon_is_registered()
116 123
117124
118if __name__=="__main__":125if __name__ == "__main__":
119 # If run directly...126 # If run directly...
120 main()127 main()
121 128
122if __name__=="__builtin__":129if __name__ == "__builtin__":
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.
124 # It is responsible for setting up and launching the twistd daemon.131 # It is responsible for setting up and launching the twistd daemon.
125 132
126 # This piece of code cannot be wrapped inside a function, as silly133 # This piece of code cannot be wrapped inside a function, as silly
127 # twistd blindly searches fora global variable named "application",134 # twistd blindly searches fora global variable named "application",
128 # and therefore while this code must be exposed.135 # and therefore while this code must be exposed.
129 136
130 # Reactor has to be installed before any import statements.137 # Reactor has to be installed before any import statements.
131 from twisted.internet import gireactor138 from twisted.internet import gireactor
132 gireactor.install()139 gireactor.install()
133140
134 from accomplishments.daemon import app141 from accomplishments.daemon import app
135 from accomplishments.util import paths142 from accomplishments.util import paths
136 143
137 # Ensure the sync daemon is running. The following command can be run in the144 # Ensure the sync daemon is running. The following command can be run in the
138 # background (&), because it would block the daemon from running for few145 # background (&), because it would block the daemon from running for few
139 # seconds, while the syncdaemon will not be needed immediatelly after146 # seconds, while the syncdaemon will not be needed immediatelly after

Subscribers

People subscribed via source and target branches