Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_xmllog.py @ 2562:26edcf3a30eb
core, setup: huge cleaning:
- moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention
- move twisted directory to root
- removed all hacks from setup.py, and added missing dependencies, it is now clean
- use https URL for website in setup.py
- removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed
- renamed sat.sh to sat and fixed its installation
- added python_requires to specify Python version needed
- replaced glib2reactor which use deprecated code by gtk3reactor
sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 02 Apr 2018 19:44:50 +0200 |
parents | src/plugins/plugin_misc_xmllog.py@51d346e283fd |
children | 56f94936df1e |
comparison
equal
deleted
inserted
replaced
2561:bd30dc3ffe5a | 2562:26edcf3a30eb |
---|---|
1 #!/usr/bin/env python2 | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # SàT plugin for managing raw XML log | |
5 # Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 from sat.core.i18n import _ | |
21 from sat.core.constants import Const as C | |
22 from sat.core.log import getLogger | |
23 log = getLogger(__name__) | |
24 from twisted.words.xish import domish | |
25 from twisted.words.xish import xmlstream | |
26 | |
27 PLUGIN_INFO = { | |
28 C.PI_NAME: "Raw XML log Plugin", | |
29 C.PI_IMPORT_NAME: "XmlLog", | |
30 C.PI_TYPE: "Misc", | |
31 C.PI_PROTOCOLS: [], | |
32 C.PI_DEPENDENCIES: [], | |
33 C.PI_MAIN: "XmlLog", | |
34 C.PI_HANDLER: "no", | |
35 C.PI_DESCRIPTION: _(u"""Send raw XML logs to bridge""") | |
36 } | |
37 | |
38 host = None | |
39 | |
40 def send(self, obj): | |
41 global host | |
42 if isinstance(obj, basestring): | |
43 log = unicode(obj) | |
44 elif isinstance(obj, domish.Element): | |
45 log = obj.toXml() | |
46 else: | |
47 log.error(_(u'INTERNAL ERROR: Unmanaged XML type')) | |
48 host.bridge.xmlLog("OUT", log, self._profile) | |
49 return self._original_send(obj) | |
50 | |
51 | |
52 def onElement(self, element): | |
53 global host | |
54 host.bridge.xmlLog("IN", element.toXml(), self._profile) | |
55 return self._original_onElement(element) | |
56 | |
57 | |
58 class XmlLog(object): | |
59 | |
60 params = """ | |
61 <params> | |
62 <general> | |
63 <category name="Debug"> | |
64 <param name="Xml log" label="%(label_xmllog)s" value="false" type="bool" /> | |
65 </category> | |
66 </general> | |
67 </params> | |
68 """ % {"label_xmllog": _("Activate XML log")} | |
69 | |
70 def __init__(self, host_): | |
71 log.info(_("Plugin XML Log initialization")) | |
72 global host | |
73 host = host_ | |
74 | |
75 #parameters | |
76 host.memory.updateParams(self.params) | |
77 | |
78 #bridge | |
79 host.bridge.addSignal("xmlLog", ".plugin", signature='sss') # args: direction("IN" or "OUT"), xml_data, profile | |
80 | |
81 self.do_log = host.memory.getParamA("Xml log", "Debug") | |
82 if self.do_log: | |
83 XmlStream = xmlstream.XmlStream | |
84 XmlStream._original_send = XmlStream.send | |
85 XmlStream._original_onElement = XmlStream.onElement | |
86 XmlStream.send = send | |
87 XmlStream.onElement = onElement | |
88 XmlStream._profile = '' | |
89 host.trigger.add("XML Initialized", self.setProfile) | |
90 log.info(_(u"XML log activated")) | |
91 | |
92 def setProfile(self, xmlstream, profile): | |
93 xmlstream._profile = profile | |
94 return True |