From 0cbcd566ced11f67a4585e553f0ff9ed255fcad2 Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 1 Jun 2018 12:15:38 +0200 Subject: [PATCH] jp (output): new OUPUT_XMLUI and OUTPUT_LIST_XMLUI outputs --- sat_frontends/jp/constants.py | 5 +++- sat_frontends/jp/output_xml.py | 2 +- sat_frontends/jp/output_xmlui.py | 46 ++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 sat_frontends/jp/output_xmlui.py diff --git a/sat_frontends/jp/constants.py b/sat_frontends/jp/constants.py index c81504c8..2407b6b9 100644 --- a/sat_frontends/jp/constants.py +++ b/sat_frontends/jp/constants.py @@ -34,7 +34,10 @@ class Const(constants.Const): OUTPUT_COMPLEX = u'complex' # complex data (e.g. multi-level dictionary) OUTPUT_XML = u'xml' # XML node (as unicode string) OUTPUT_LIST_XML = u'list_xml' # list of XML nodes (as unicode strings) - OUTPUT_TYPES = (OUTPUT_TEXT, OUTPUT_DICT, OUTPUT_LIST, OUTPUT_LIST_DICT, OUTPUT_DICT_DICT, OUTPUT_COMPLEX, OUTPUT_XML, OUTPUT_LIST_XML) + OUTPUT_XMLUI = u'xmlui' # XMLUI as unicode string + OUTPUT_LIST_XMLUI = u'list_xmlui' # list of XMLUI (as unicode strings) + OUTPUT_TYPES = (OUTPUT_TEXT, OUTPUT_DICT, OUTPUT_LIST, OUTPUT_LIST_DICT, OUTPUT_DICT_DICT, + OUTPUT_COMPLEX, OUTPUT_XML, OUTPUT_LIST_XML, OUTPUT_XMLUI, OUTPUT_LIST_XMLUI) # Pubsub options flags SERVICE = u'service' # service required diff --git a/sat_frontends/jp/output_xml.py b/sat_frontends/jp/output_xml.py index 54b6327b..9d23a41b 100644 --- a/sat_frontends/jp/output_xml.py +++ b/sat_frontends/jp/output_xml.py @@ -39,7 +39,7 @@ PRETTY = u'xml_pretty' class XML(object): - """Default outputs""" + """Outputs for XML""" def __init__(self, host): self.host = host diff --git a/sat_frontends/jp/output_xmlui.py b/sat_frontends/jp/output_xmlui.py new file mode 100644 index 00000000..7fc76157 --- /dev/null +++ b/sat_frontends/jp/output_xmlui.py @@ -0,0 +1,46 @@ +#! /usr/bin/python +# -*- coding: utf-8 -*- + +# jp: a SàT command line tool +# Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +"""Standard outputs""" + + +from sat_frontends.jp.constants import Const as C +from sat_frontends.jp import xmlui_manager +from sat.core.log import getLogger +log = getLogger(__name__) + + +__outputs__ = ["XMLUI"] + + +class XMLUI(object): + """Outputs for XMLUI""" + + def __init__(self, host): + self.host = host + host.register_output(C.OUTPUT_XMLUI, u"simple", self.xmlui, default=True) + host.register_output(C.OUTPUT_LIST_XMLUI, u"simple", self.xmlui_list, default=True) + + def xmlui(self, data): + xmlui = xmlui_manager.create(self.host, data) + xmlui.show(values_only=True) + self.host.disp(u'') + + def xmlui_list(self, data): + for d in data: + self.xmlui(d)