From aca7307452310ff8af19e83f4d79bdd0b0dd8119 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 2 Nov 2015 22:02:41 +0100 Subject: [PATCH] =?UTF-8?q?core:=20plugin=20unload:=20=20=20=20=20Call=20u?= =?UTF-8?q?nload()=20if=20it=20exists=20on=20all=20loaded=20plugin=20insta?= =?UTF-8?q?nces=20when=20leaving=20S=C3=A0T.=20This=20method=20will=20prob?= =?UTF-8?q?ably=20be=20used=20later=20for=20hot=20(un)loading?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/sat_main.py | 57 +++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/src/core/sat_main.py b/src/core/sat_main.py index 2d557e8f..c8b54e09 100644 --- a/src/core/sat_main.py +++ b/src/core/sat_main.py @@ -50,25 +50,6 @@ except ImportError: 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 @@ class SAT(service.Service): 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 @@ class SAT(service.Service): 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 @@ class SAT(service.Service): def stopService(self): log.info(u"Salut aussi à Rantanplan") + return self.pluginsUnload() def run(self): log.debug(_("running app"))