# HG changeset patch # User Goffi # Date 1446498161 -3600 # Node ID 465d4d484e7c1518f8686dacda23a083ac0e5598 # Parent e987325c14efd0082baef4b17c4bad2b95713840 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 diff -r e987325c14ef -r 465d4d484e7c src/core/sat_main.py --- a/src/core/sat_main.py Mon Nov 02 22:02:41 2015 +0100 +++ b/src/core/sat_main.py Mon Nov 02 22:02:41 2015 +0100 @@ -50,25 +50,6 @@ class SAT(service.Service): - @property - def version(self): - """Return the short version of SàT""" - return C.APP_VERSION - - @property - def full_version(self): - """Return the full version of SàT (with extra data when in development mode)""" - version = self.version - if version[-1] == 'D': - # we are in debug version, we add extra data - try: - return self._version_cache - except AttributeError: - self._version_cache = u"{} ({})".format(version, utils.getRepositoryData(sat)) - return self._version_cache - else: - return version - def __init__(self): self._cb_map = {} # map from callback_id to callbacks self._menus = OrderedDict() # dynamic menus. key: callback_id, value: menu data (dictionnary) @@ -132,6 +113,25 @@ self.memory.initialized.addCallback(self._postMemoryInit) + @property + def version(self): + """Return the short version of SàT""" + return C.APP_VERSION + + @property + def full_version(self): + """Return the full version of SàT (with extra data when in development mode)""" + version = self.version + if version[-1] == 'D': + # we are in debug version, we add extra data + try: + return self._version_cache + except AttributeError: + self._version_cache = u"{} ({})".format(version, utils.getRepositoryData(sat)) + return self._version_cache + else: + return version + def _postMemoryInit(self, ignore): """Method called after memory initialization is done""" log.info(_("Memory initialised")) @@ -227,6 +227,24 @@ self.plugins[import_name].is_handler = False #TODO: test xmppclient presence and register handler parent + def pluginsUnload(self): + """Call unload method on every loaded plugin, if exists + + @return (D): A deferred which return None when all method have been called + """ + # TODO: in the futur, it should be possible to hot unload a plugin + # pluging depending on the unloaded one should be unloaded too + # for now, just a basic call on plugin.unload is done + defers_list = [] + for plugin in self.plugins.itervalues(): + try: + unload = plugin.unload + except AttributeError: + continue + else: + defers_list.append(defer.maybeDeferred(unload)) + return defers_list + def asyncConnect(self, profile_key=C.PROF_KEY_NONE, password=''): """Retrieve the individual parameters, authenticate the profile and initiate the connection to the associated XMPP server. @@ -445,6 +463,7 @@ def stopService(self): log.info(u"Salut aussi à Rantanplan") + return self.pluginsUnload() def run(self): log.debug(_("running app"))