jp (pubsub/node): new "import" command, to publish many nodes from an XML file
This commit is contained in:
parent
d747c46736
commit
bb5a2befc5
1 changed files with 92 additions and 1 deletions
|
|
@ -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)
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue