Mercurial > libervia-backend
annotate src/plugins/plugin_misc_xmllog.py @ 568:239abc5484c9
bridge: generic plugin methods handling for frontend side in D-Bus Bridge \o/
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 07 Jan 2013 01:01:10 +0100 |
parents | 2c4016921403 |
children | 952322b1d490 |
rev | line source |
---|---|
277 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 SàT plugin for managing raw XML log | |
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
277 | 10 the Free Software Foundation, either version 3 of the License, or |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
16 GNU Affero General Public License for more details. |
277 | 17 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
372
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
277 | 19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 """ | |
21 | |
22 from logging import debug, info, error | |
23 from twisted.words.protocols.jabber.xmlstream import XmlStream | |
24 from twisted.words.xish import domish | |
25 | |
26 PLUGIN_INFO = { | |
27 "name": "Raw XML log Plugin", | |
28 "import_name": "XmlLog", | |
29 "type": "Misc", | |
30 "protocols": [], | |
31 "dependencies": [], | |
32 "main": "XmlLog", | |
33 "handler": "no", | |
34 "description": _("""Send raw XML logs to bridge""") | |
35 } | |
36 | |
37 class LoggingXmlStream(XmlStream): | |
38 """This class send the raw XML to the Bridge, for logging purpose""" | |
39 | |
40 def send(self, obj): | |
41 if isinstance(obj,basestring): | |
42 log=unicode(obj) | |
43 elif isinstance(obj, domish.Element): | |
44 log=obj.toXml() | |
45 else: | |
46 error(_('INTERNAL ERROR: Unmanaged XML type')) | |
285
6422fcdd831c
plugin XML Log: fixed dbus signal name
Goffi <goffi@goffi.org>
parents:
280
diff
changeset
|
47 self._host.bridge.xmlLog("OUT", log, self._profile) |
277 | 48 return XmlStream.send(self, obj) |
49 | |
50 def dataReceived(self, data): | |
285
6422fcdd831c
plugin XML Log: fixed dbus signal name
Goffi <goffi@goffi.org>
parents:
280
diff
changeset
|
51 self._host.bridge.xmlLog("IN", data.decode('utf-8'), self._profile) |
277 | 52 return XmlStream.dataReceived(self, data) |
53 | |
54 | |
55 class XmlLog(): | |
56 | |
57 params = """ | |
58 <params> | |
59 <general> | |
60 <category name="Debug"> | |
61 <param name="Xml log" label="%(label_xmllog)s" value="false" type="bool" /> | |
62 </category> | |
63 </general> | |
64 </params> | |
65 """ % {"label_xmllog": _("Activate XML log")} | |
66 | |
67 def __init__(self, host): | |
68 info(_("Plugin XML Log initialization")) | |
69 self.host = host | |
70 | |
71 #parameters | |
72 host.memory.importParams(self.params) | |
73 | |
74 #bridge | |
372
f964dcec1611
core: plugins refactored according to bridge + updatedValue now use profile
Goffi <goffi@goffi.org>
parents:
285
diff
changeset
|
75 host.bridge.addSignal("xmlLog", ".plugin", signature='sss') #args: direction("IN" or "OUT"), xml_data, profile |
277 | 76 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
77 do_log = self.host.memory.getParamA("Xml log", "Debug") |
277 | 78 if do_log: |
79 info(_("XML log activated")) | |
80 host.trigger.add("XML Initialized", self.logXml) | |
81 | |
82 def logXml(self, xmlstream, profile): | |
83 xmlstream.__class__ = LoggingXmlStream | |
84 xmlstream._profile = profile | |
85 xmlstream._host = self.host | |
86 return True |