Commit 6997fc57 by Calen Pennington

Continue on errors when syncing with github

parent 05add581
...@@ -6,6 +6,7 @@ import logging ...@@ -6,6 +6,7 @@ import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class RawDescriptor(MakoModuleDescriptor, XmlDescriptor): class RawDescriptor(MakoModuleDescriptor, XmlDescriptor):
""" """
Module that provides a raw editing view of its data and children Module that provides a raw editing view of its data and children
...@@ -33,7 +34,7 @@ class RawDescriptor(MakoModuleDescriptor, XmlDescriptor): ...@@ -33,7 +34,7 @@ class RawDescriptor(MakoModuleDescriptor, XmlDescriptor):
line, offset = err.position line, offset = err.position
msg = ("Unable to create xml for problem {loc}. " msg = ("Unable to create xml for problem {loc}. "
"Context: '{context}'".format( "Context: '{context}'".format(
context=lines[line-1][offset - 40:offset + 40], context=lines[line - 1][offset - 40:offset + 40],
loc=self.location)) loc=self.location))
log.exception(msg) log.exception(msg)
self.system.error_handler(msg) self.system.error_handler(msg)
......
from collections import MutableMapping from collections import MutableMapping
from xmodule.x_module import XModuleDescriptor from xmodule.x_module import XModuleDescriptor
from xmodule.modulestore import Location
from lxml import etree from lxml import etree
import copy import copy
import logging import logging
...@@ -13,6 +14,7 @@ log = logging.getLogger(__name__) ...@@ -13,6 +14,7 @@ log = logging.getLogger(__name__)
# but the actual improvement wasn't measured (and it was implemented late at night). # but the actual improvement wasn't measured (and it was implemented late at night).
# We should check if it hurts, and whether there's a better way of doing lazy loading # We should check if it hurts, and whether there's a better way of doing lazy loading
class LazyLoadingDict(MutableMapping): class LazyLoadingDict(MutableMapping):
""" """
A dictionary object that lazily loads its contents from a provided A dictionary object that lazily loads its contents from a provided
...@@ -173,6 +175,9 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -173,6 +175,9 @@ class XmlDescriptor(XModuleDescriptor):
url identifiers url identifiers
""" """
xml_object = etree.fromstring(xml_data) xml_object = etree.fromstring(xml_data)
# VS[compat] -- just have the url_name lookup once translation is done
slug = xml_object.get('url_name', xml_object.get('slug'))
location = Location('i4x', org, course, xml_object.tag, slug)
def metadata_loader(): def metadata_loader():
metadata = {} metadata = {}
...@@ -210,25 +215,21 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -210,25 +215,21 @@ class XmlDescriptor(XModuleDescriptor):
with system.resources_fs.open(filepath) as file: with system.resources_fs.open(filepath) as file:
definition_xml = cls.file_to_xml(file) definition_xml = cls.file_to_xml(file)
except (ResourceNotFoundError, etree.XMLSyntaxError): except (ResourceNotFoundError, etree.XMLSyntaxError):
msg = 'Unable to load file contents at path %s' % filepath msg = 'Unable to load file contents at path %s for item %s' % (filepath, location.url())
log.exception(msg) log.exception(msg)
system.error_handler(msg) system.error_handler(msg)
# if error_handler didn't reraise, work around problem. # if error_handler didn't reraise, work around problem.
return {'data': 'Error loading file contents at path %s' % filepath} error_elem = etree.Element('error')
error_elem.text = msg
return {'data': etree.tostring(error_elem)}
cls.clean_metadata_from_xml(definition_xml) cls.clean_metadata_from_xml(definition_xml)
return cls.definition_from_xml(definition_xml, system) return cls.definition_from_xml(definition_xml, system)
# VS[compat] -- just have the url_name lookup once translation is done
slug = xml_object.get('url_name', xml_object.get('slug'))
return cls( return cls(
system, system,
LazyLoadingDict(definition_loader), LazyLoadingDict(definition_loader),
location=['i4x', location=location,
org,
course,
xml_object.tag,
slug],
metadata=LazyLoadingDict(metadata_loader), metadata=LazyLoadingDict(metadata_loader),
) )
......
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