Commit d0c99151 by Calen Pennington

Continue during backcompat imports by replacing contents with error xml

parent 7ae0836f
...@@ -5,6 +5,7 @@ from x_module import XModuleDescriptor ...@@ -5,6 +5,7 @@ from x_module import XModuleDescriptor
from lxml import etree from lxml import etree
from functools import wraps from functools import wraps
import logging import logging
import traceback
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -21,29 +22,31 @@ def process_includes(fn): ...@@ -21,29 +22,31 @@ def process_includes(fn):
next_include = xml_object.find('include') next_include = xml_object.find('include')
while next_include is not None: while next_include is not None:
file = next_include.get('file') file = next_include.get('file')
if file is not None: parent = next_include.getparent()
if file is None:
continue
try: try:
ifp = system.resources_fs.open(file) ifp = system.resources_fs.open(file)
except Exception:
msg = 'Error in problem xml include: %s\n' % (
etree.tostring(next_include, pretty_print=True))
msg += 'Cannot find file %s in %s' % (file, dir)
log.exception(msg)
system.error_handler(msg)
raise
try:
# read in and convert to XML # read in and convert to XML
incxml = etree.XML(ifp.read()) incxml = etree.XML(ifp.read())
# insert new XML into tree in place of inlcude
parent.insert(parent.index(next_include), incxml)
except Exception: except Exception:
msg = 'Error in problem xml include: %s\n' % ( msg = "Error in problem xml include: %s" % (etree.tostring(next_include, pretty_print=True))
etree.tostring(next_include, pretty_print=True))
msg += 'Cannot parse XML in %s' % (file)
log.exception(msg) log.exception(msg)
system.error_handler(msg)
raise
# insert new XML into tree in place of inlcude
parent = next_include.getparent() parent = next_include.getparent()
parent.insert(parent.index(next_include), incxml)
errorxml = etree.Element('error')
messagexml = etree.SubElement(errorxml, 'message')
messagexml.text = msg
stackxml = etree.SubElement(errorxml, 'stacktrace')
stackxml.text = traceback.format_exc()
# insert error XML in place of include
parent.insert(parent.index(next_include), errorxml)
parent.remove(next_include) parent.remove(next_include)
next_include = xml_object.find('include') next_include = xml_object.find('include')
......
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