comparison src/core/sat_main.py @ 1550:465d4d484e7c

core: plugin unload: Call unload() if it exists on all loaded plugin instances when leaving SàT. This method will probably be used later for hot (un)loading
author Goffi <goffi@goffi.org>
date Mon, 02 Nov 2015 22:02:41 +0100
parents c9ef16de3f13
children 6338677f3a89
comparison
equal deleted inserted replaced
1549:e987325c14ef 1550:465d4d484e7c
47 except ImportError: 47 except ImportError:
48 from ordereddict import OrderedDict 48 from ordereddict import OrderedDict
49 49
50 50
51 class SAT(service.Service): 51 class SAT(service.Service):
52
53 @property
54 def version(self):
55 """Return the short version of SàT"""
56 return C.APP_VERSION
57
58 @property
59 def full_version(self):
60 """Return the full version of SàT (with extra data when in development mode)"""
61 version = self.version
62 if version[-1] == 'D':
63 # we are in debug version, we add extra data
64 try:
65 return self._version_cache
66 except AttributeError:
67 self._version_cache = u"{} ({})".format(version, utils.getRepositoryData(sat))
68 return self._version_cache
69 else:
70 return version
71 52
72 def __init__(self): 53 def __init__(self):
73 self._cb_map = {} # map from callback_id to callbacks 54 self._cb_map = {} # map from callback_id to callbacks
74 self._menus = OrderedDict() # dynamic menus. key: callback_id, value: menu data (dictionnary) 55 self._menus = OrderedDict() # dynamic menus. key: callback_id, value: menu data (dictionnary)
75 self.__private_data = {} # used for internal callbacks (key = id) FIXME: to be removed 56 self.__private_data = {} # used for internal callbacks (key = id) FIXME: to be removed
130 self.bridge.register("saveParamsTemplate", self.memory.save_xml) 111 self.bridge.register("saveParamsTemplate", self.memory.save_xml)
131 self.bridge.register("loadParamsTemplate", self.memory.load_xml) 112 self.bridge.register("loadParamsTemplate", self.memory.load_xml)
132 113
133 self.memory.initialized.addCallback(self._postMemoryInit) 114 self.memory.initialized.addCallback(self._postMemoryInit)
134 115
116 @property
117 def version(self):
118 """Return the short version of SàT"""
119 return C.APP_VERSION
120
121 @property
122 def full_version(self):
123 """Return the full version of SàT (with extra data when in development mode)"""
124 version = self.version
125 if version[-1] == 'D':
126 # we are in debug version, we add extra data
127 try:
128 return self._version_cache
129 except AttributeError:
130 self._version_cache = u"{} ({})".format(version, utils.getRepositoryData(sat))
131 return self._version_cache
132 else:
133 return version
134
135 def _postMemoryInit(self, ignore): 135 def _postMemoryInit(self, ignore):
136 """Method called after memory initialization is done""" 136 """Method called after memory initialization is done"""
137 log.info(_("Memory initialised")) 137 log.info(_("Memory initialised"))
138 self._import_plugins() 138 self._import_plugins()
139 ui_contact_list.ContactList(self) 139 ui_contact_list.ContactList(self)
225 self.plugins[import_name].is_handler = True 225 self.plugins[import_name].is_handler = True
226 else: 226 else:
227 self.plugins[import_name].is_handler = False 227 self.plugins[import_name].is_handler = False
228 #TODO: test xmppclient presence and register handler parent 228 #TODO: test xmppclient presence and register handler parent
229 229
230 def pluginsUnload(self):
231 """Call unload method on every loaded plugin, if exists
232
233 @return (D): A deferred which return None when all method have been called
234 """
235 # TODO: in the futur, it should be possible to hot unload a plugin
236 # pluging depending on the unloaded one should be unloaded too
237 # for now, just a basic call on plugin.unload is done
238 defers_list = []
239 for plugin in self.plugins.itervalues():
240 try:
241 unload = plugin.unload
242 except AttributeError:
243 continue
244 else:
245 defers_list.append(defer.maybeDeferred(unload))
246 return defers_list
247
230 def asyncConnect(self, profile_key=C.PROF_KEY_NONE, password=''): 248 def asyncConnect(self, profile_key=C.PROF_KEY_NONE, password=''):
231 """Retrieve the individual parameters, authenticate the profile 249 """Retrieve the individual parameters, authenticate the profile
232 and initiate the connection to the associated XMPP server. 250 and initiate the connection to the associated XMPP server.
233 251
234 @param password (string): the SàT profile password 252 @param password (string): the SàT profile password
443 def startService(self): 461 def startService(self):
444 log.info(u"Salut à toi ô mon frère !") 462 log.info(u"Salut à toi ô mon frère !")
445 463
446 def stopService(self): 464 def stopService(self):
447 log.info(u"Salut aussi à Rantanplan") 465 log.info(u"Salut aussi à Rantanplan")
466 return self.pluginsUnload()
448 467
449 def run(self): 468 def run(self):
450 log.debug(_("running app")) 469 log.debug(_("running app"))
451 reactor.run() 470 reactor.run()
452 471