Verified Commit 8e29f6d1 authored by mathieui's avatar mathieui

Add a /dump <filename> command to the XML tab

parent 8f6ab25f
...@@ -541,10 +541,16 @@ XML tab commands ...@@ -541,10 +541,16 @@ XML tab commands
~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~
.. glossary:: .. glossary::
:sorted:
/clear [XML tab version] /clear [XML tab version]
Clear the current buffer. Clear the current buffer.
/dump
**Usage:** ``/dump <filename>``
Write the content of the XML buffer into a file.
/reset /reset
Reset the stanza filter. Reset the stanza filter.
......
...@@ -11,12 +11,14 @@ import logging ...@@ -11,12 +11,14 @@ import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
import curses import curses
import os
from sleekxmpp.xmlstream import matcher from sleekxmpp.xmlstream import matcher
from sleekxmpp.xmlstream.handler import Callback from sleekxmpp.xmlstream.handler import Callback
from . import Tab from . import Tab
import windows import windows
from xhtml import clean_text
class XMLTab(Tab): class XMLTab(Tab):
def __init__(self): def __init__(self):
...@@ -45,6 +47,10 @@ class XMLTab(Tab): ...@@ -45,6 +47,10 @@ class XMLTab(Tab):
usage=_('<xml mask>'), usage=_('<xml mask>'),
desc=_('Show only the stanzas matching the given xml mask.'), desc=_('Show only the stanzas matching the given xml mask.'),
shortdesc=_('Filter by xml mask.')) shortdesc=_('Filter by xml mask.'))
self.register_command('dump', self.command_dump,
usage=_('<filename>'),
desc=_('Writes the content of the XML buffer into a file.'),
shortdesc=_('Write in a file.'))
self.input = self.default_help_message self.input = self.default_help_message
self.key_func['^T'] = self.close self.key_func['^T'] = self.close
self.key_func['^I'] = self.completion self.key_func['^I'] = self.completion
...@@ -111,6 +117,17 @@ class XMLTab(Tab): ...@@ -111,6 +117,17 @@ class XMLTab(Tab):
self.filter = '' self.filter = ''
self.refresh() self.refresh()
def command_dump(self, arg):
"""/dump <filename>"""
xml = self.core.xml_buffer.messages[:]
text = '\n'.join(('%s %s' % (msg.str_time, clean_text(msg.txt)) for msg in xml))
filename = os.path.expandvars(os.path.expanduser(arg))
try:
with open(filename, 'w') as fd:
fd.write(text)
except Exception as e:
self.core.information('Could not write the XML dump: %s' % e, 'Error')
def on_slash(self): def on_slash(self):
""" """
'/' is pressed, activate the input '/' is pressed, activate the input
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment