# HG changeset patch # User Goffi # Date 1408980064 -7200 # Node ID adea30ca0b51c13092ae8ea74fbea34b6019c7f7 # Parent 08f50fdac21ba6390cef15e3b5a5e28b8dea21e2 core: twistd plugin refactoring: initialisation method manage things which must be done once (reactor installation + logging configuration), this method is called when service is created, so we can have the options passed to twistd (necessary to manage logging configuration). The initialisation order is important: for instance, sat_main must be imported after logging initialisation. This refactoring avoid initialisation issue when SàT backend and libervia are both installed as twisted plugins. diff -r 08f50fdac21b -r adea30ca0b51 src/core/sat_main.py --- a/src/core/sat_main.py Mon Aug 25 17:21:03 2014 +0200 +++ b/src/core/sat_main.py Mon Aug 25 17:21:04 2014 +0200 @@ -19,8 +19,6 @@ from sat.core.i18n import _, D_, languageSwitch from twisted.application import service -from twisted.internet import glib2reactor -glib2reactor.install() from twisted.internet import defer from twisted.words.protocols.jabber import jid from twisted.words.xish import domish diff -r 08f50fdac21b -r adea30ca0b51 src/twisted/plugins/sat_plugin.py --- a/src/twisted/plugins/sat_plugin.py Mon Aug 25 17:21:03 2014 +0200 +++ b/src/twisted/plugins/sat_plugin.py Mon Aug 25 17:21:04 2014 +0200 @@ -35,12 +35,16 @@ # XXX: We need to configure logs before any log method is used, so here is the best place. from sat.core.constants import Const as C -from sat.core import log_config -log_config.satConfigure(C.LOG_BACKEND_TWISTED) +from sat.core.i18n import _ + -# XXX: SAT must be imported after log configuration, because it write stuff to logs -from sat.core.sat_main import SAT -from sat.core.i18n import _ +def initialise(options): + """Method to initialise global modules""" + from twisted.internet import glib2reactor + glib2reactor.install() + # XXX: We need to configure logs before any log method is used, so here is the best place. + from sat.core import log_config + log_config.satConfigure(C.LOG_BACKEND_TWISTED, C, backend_data=options) class Options(usage.Options): @@ -55,6 +59,9 @@ options = Options def makeService(self, options): + # XXX: SAT must be imported after log configuration, because it write stuff to logs + initialise(options.parent) + from sat.core.sat_main import SAT return SAT()