jp (pubsub/node): new "import" command, to publish many nodes from an XML file

This commit is contained in:
Goffi 2019-02-15 22:13:43 +01:00
commit bb5a2befc5

View file

@ -20,11 +20,13 @@
from sat.core.i18n import _
from sat_frontends.jp.constants import Const as C
def etreeParse(cmd, raw_xml):
def etreeParse(cmd, raw_xml, reraise=False):
"""Import lxml and parse raw XML
@param cmd(CommandBase): current command instance
@param raw_xml(file, str): an XML bytestring, string or file-like object
@param reraise(bool): if True, re raise exception on parse error instead of doing a
parser.error (which terminate the execution)
@return (tuple(etree.Element, module): parsed element, etree module
"""
try:
@ -42,6 +44,8 @@ def etreeParse(cmd, raw_xml):
else:
element = etree.parse(raw_xml).getroot()
except Exception as e:
if reraise:
raise e
cmd.parser.error(
_(u"Can't parse the payload XML in input: {msg}").format(msg=e)
)