Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_xmllog.py @ 2624:56f94936df1e
code style reformatting using black
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 20:14:46 +0200 |
parents | 26edcf3a30eb |
children | 1ecceac3df96 |
comparison
equal
deleted
inserted
replaced
2623:49533de4540b | 2624:56f94936df1e |
---|---|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from sat.core.constants import Const as C | 21 from sat.core.constants import Const as C |
22 from sat.core.log import getLogger | 22 from sat.core.log import getLogger |
23 | |
23 log = getLogger(__name__) | 24 log = getLogger(__name__) |
24 from twisted.words.xish import domish | 25 from twisted.words.xish import domish |
25 from twisted.words.xish import xmlstream | 26 from twisted.words.xish import xmlstream |
26 | 27 |
27 PLUGIN_INFO = { | 28 PLUGIN_INFO = { |
30 C.PI_TYPE: "Misc", | 31 C.PI_TYPE: "Misc", |
31 C.PI_PROTOCOLS: [], | 32 C.PI_PROTOCOLS: [], |
32 C.PI_DEPENDENCIES: [], | 33 C.PI_DEPENDENCIES: [], |
33 C.PI_MAIN: "XmlLog", | 34 C.PI_MAIN: "XmlLog", |
34 C.PI_HANDLER: "no", | 35 C.PI_HANDLER: "no", |
35 C.PI_DESCRIPTION: _(u"""Send raw XML logs to bridge""") | 36 C.PI_DESCRIPTION: _(u"""Send raw XML logs to bridge"""), |
36 } | 37 } |
37 | 38 |
38 host = None | 39 host = None |
40 | |
39 | 41 |
40 def send(self, obj): | 42 def send(self, obj): |
41 global host | 43 global host |
42 if isinstance(obj, basestring): | 44 if isinstance(obj, basestring): |
43 log = unicode(obj) | 45 log = unicode(obj) |
44 elif isinstance(obj, domish.Element): | 46 elif isinstance(obj, domish.Element): |
45 log = obj.toXml() | 47 log = obj.toXml() |
46 else: | 48 else: |
47 log.error(_(u'INTERNAL ERROR: Unmanaged XML type')) | 49 log.error(_(u"INTERNAL ERROR: Unmanaged XML type")) |
48 host.bridge.xmlLog("OUT", log, self._profile) | 50 host.bridge.xmlLog("OUT", log, self._profile) |
49 return self._original_send(obj) | 51 return self._original_send(obj) |
50 | 52 |
51 | 53 |
52 def onElement(self, element): | 54 def onElement(self, element): |
63 <category name="Debug"> | 65 <category name="Debug"> |
64 <param name="Xml log" label="%(label_xmllog)s" value="false" type="bool" /> | 66 <param name="Xml log" label="%(label_xmllog)s" value="false" type="bool" /> |
65 </category> | 67 </category> |
66 </general> | 68 </general> |
67 </params> | 69 </params> |
68 """ % {"label_xmllog": _("Activate XML log")} | 70 """ % { |
71 "label_xmllog": _("Activate XML log") | |
72 } | |
69 | 73 |
70 def __init__(self, host_): | 74 def __init__(self, host_): |
71 log.info(_("Plugin XML Log initialization")) | 75 log.info(_("Plugin XML Log initialization")) |
72 global host | 76 global host |
73 host = host_ | 77 host = host_ |
74 | 78 |
75 #parameters | 79 # parameters |
76 host.memory.updateParams(self.params) | 80 host.memory.updateParams(self.params) |
77 | 81 |
78 #bridge | 82 # bridge |
79 host.bridge.addSignal("xmlLog", ".plugin", signature='sss') # args: direction("IN" or "OUT"), xml_data, profile | 83 host.bridge.addSignal( |
84 "xmlLog", ".plugin", signature="sss" | |
85 ) # args: direction("IN" or "OUT"), xml_data, profile | |
80 | 86 |
81 self.do_log = host.memory.getParamA("Xml log", "Debug") | 87 self.do_log = host.memory.getParamA("Xml log", "Debug") |
82 if self.do_log: | 88 if self.do_log: |
83 XmlStream = xmlstream.XmlStream | 89 XmlStream = xmlstream.XmlStream |
84 XmlStream._original_send = XmlStream.send | 90 XmlStream._original_send = XmlStream.send |
85 XmlStream._original_onElement = XmlStream.onElement | 91 XmlStream._original_onElement = XmlStream.onElement |
86 XmlStream.send = send | 92 XmlStream.send = send |
87 XmlStream.onElement = onElement | 93 XmlStream.onElement = onElement |
88 XmlStream._profile = '' | 94 XmlStream._profile = "" |
89 host.trigger.add("XML Initialized", self.setProfile) | 95 host.trigger.add("XML Initialized", self.setProfile) |
90 log.info(_(u"XML log activated")) | 96 log.info(_(u"XML log activated")) |
91 | 97 |
92 def setProfile(self, xmlstream, profile): | 98 def setProfile(self, xmlstream, profile): |
93 xmlstream._profile = profile | 99 xmlstream._profile = profile |