comparison src/twisted/plugins/sat_plugin.py @ 1130:adea30ca0b51

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.
author Goffi <goffi@goffi.org>
date Mon, 25 Aug 2014 17:21:04 +0200
parents 9ae01ccf89c1
children 069ad98b360d
comparison
equal deleted inserted replaced
1129:08f50fdac21b 1130:adea30ca0b51
33 from twisted.plugin import IPlugin 33 from twisted.plugin import IPlugin
34 from twisted.application.service import IServiceMaker 34 from twisted.application.service import IServiceMaker
35 35
36 # XXX: We need to configure logs before any log method is used, so here is the best place. 36 # XXX: We need to configure logs before any log method is used, so here is the best place.
37 from sat.core.constants import Const as C 37 from sat.core.constants import Const as C
38 from sat.core import log_config 38 from sat.core.i18n import _
39 log_config.satConfigure(C.LOG_BACKEND_TWISTED)
40 39
41 # XXX: SAT must be imported after log configuration, because it write stuff to logs 40
42 from sat.core.sat_main import SAT 41 def initialise(options):
43 from sat.core.i18n import _ 42 """Method to initialise global modules"""
43 from twisted.internet import glib2reactor
44 glib2reactor.install()
45 # XXX: We need to configure logs before any log method is used, so here is the best place.
46 from sat.core import log_config
47 log_config.satConfigure(C.LOG_BACKEND_TWISTED, C, backend_data=options)
44 48
45 49
46 class Options(usage.Options): 50 class Options(usage.Options):
47 optParameters = [] 51 optParameters = []
48 52
53 tapname = C.APP_NAME_FILE 57 tapname = C.APP_NAME_FILE
54 description = _(u"%s XMPP client backend") % C.APP_NAME_FULL 58 description = _(u"%s XMPP client backend") % C.APP_NAME_FULL
55 options = Options 59 options = Options
56 60
57 def makeService(self, options): 61 def makeService(self, options):
62 # XXX: SAT must be imported after log configuration, because it write stuff to logs
63 initialise(options.parent)
64 from sat.core.sat_main import SAT
58 return SAT() 65 return SAT()
59 66
60 67
61 serviceMaker = SatMaker() 68 serviceMaker = SatMaker()