Mercurial > libervia-backend
annotate src/plugins/plugin_misc_xmllog.py @ 600:c5451501465b
plugin text commands: basic /whois command (just show jid so far)
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 20 Feb 2013 20:37:17 +0100 |
parents | e629371a28d3 |
children | 84a6e83157c2 |
rev | line source |
---|---|
277 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
538
diff
changeset
|
5 SàT plugin for managing raw XML log |
277 | 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 = { | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
27 "name": "Raw XML log Plugin", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
28 "import_name": "XmlLog", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
29 "type": "Misc", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
30 "protocols": [], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
31 "dependencies": [], |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
32 "main": "XmlLog", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
33 "handler": "no", |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
34 "description": _("""Send raw XML logs to bridge""") |
277 | 35 } |
36 | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
37 |
277 | 38 class LoggingXmlStream(XmlStream): |
39 """This class send the raw XML to the Bridge, for logging purpose""" | |
40 | |
41 def send(self, obj): | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
42 if isinstance(obj, basestring): |
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
43 log = unicode(obj) |
277 | 44 elif isinstance(obj, domish.Element): |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
45 log = obj.toXml() |
277 | 46 else: |
47 error(_('INTERNAL ERROR: Unmanaged XML type')) | |
285
6422fcdd831c
plugin XML Log: fixed dbus signal name
Goffi <goffi@goffi.org>
parents:
280
diff
changeset
|
48 self._host.bridge.xmlLog("OUT", log, self._profile) |
277 | 49 return XmlStream.send(self, obj) |
50 | |
51 def dataReceived(self, data): | |
285
6422fcdd831c
plugin XML Log: fixed dbus signal name
Goffi <goffi@goffi.org>
parents:
280
diff
changeset
|
52 self._host.bridge.xmlLog("IN", data.decode('utf-8'), self._profile) |
277 | 53 return XmlStream.dataReceived(self, data) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
538
diff
changeset
|
54 |
277 | 55 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
56 class XmlLog(object): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
538
diff
changeset
|
57 |
277 | 58 params = """ |
59 <params> | |
60 <general> | |
61 <category name="Debug"> | |
62 <param name="Xml log" label="%(label_xmllog)s" value="false" type="bool" /> | |
63 </category> | |
64 </general> | |
65 </params> | |
66 """ % {"label_xmllog": _("Activate XML log")} | |
67 | |
68 def __init__(self, host): | |
69 info(_("Plugin XML Log initialization")) | |
70 self.host = host | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
538
diff
changeset
|
71 |
277 | 72 #parameters |
73 host.memory.importParams(self.params) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
538
diff
changeset
|
74 |
277 | 75 #bridge |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
76 host.bridge.addSignal("xmlLog", ".plugin", signature='sss') # args: direction("IN" or "OUT"), xml_data, profile |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
538
diff
changeset
|
77 |
538
2c4016921403
core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
78 do_log = self.host.memory.getParamA("Xml log", "Debug") |
277 | 79 if do_log: |
80 info(_("XML log activated")) | |
81 host.trigger.add("XML Initialized", self.logXml) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
538
diff
changeset
|
82 |
277 | 83 def logXml(self, xmlstream, profile): |
84 xmlstream.__class__ = LoggingXmlStream | |
85 xmlstream._profile = profile | |
86 xmlstream._host = self.host | |
87 return True |