From 6997fc579ecdc0486e5776f0749b14892cfbc83f Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Fri, 27 Jul 2012 08:57:53 -0400 Subject: [PATCH] Continue on errors when syncing with github --- common/lib/xmodule/xmodule/raw_module.py | 3 ++- common/lib/xmodule/xmodule/xml_module.py | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/common/lib/xmodule/xmodule/raw_module.py b/common/lib/xmodule/xmodule/raw_module.py index d8c18b251a..90f4139bd5 100644 --- a/common/lib/xmodule/xmodule/raw_module.py +++ b/common/lib/xmodule/xmodule/raw_module.py @@ -6,6 +6,7 @@ import logging log = logging.getLogger(__name__) + class RawDescriptor(MakoModuleDescriptor, XmlDescriptor): """ Module that provides a raw editing view of its data and children @@ -33,7 +34,7 @@ class RawDescriptor(MakoModuleDescriptor, XmlDescriptor): line, offset = err.position msg = ("Unable to create xml for problem {loc}. " "Context: '{context}'".format( - context=lines[line-1][offset - 40:offset + 40], + context=lines[line - 1][offset - 40:offset + 40], loc=self.location)) log.exception(msg) self.system.error_handler(msg) diff --git a/common/lib/xmodule/xmodule/xml_module.py b/common/lib/xmodule/xmodule/xml_module.py index 8327a3ddec..2465a941b2 100644 --- a/common/lib/xmodule/xmodule/xml_module.py +++ b/common/lib/xmodule/xmodule/xml_module.py @@ -1,5 +1,6 @@ from collections import MutableMapping from xmodule.x_module import XModuleDescriptor +from xmodule.modulestore import Location from lxml import etree import copy import logging @@ -13,6 +14,7 @@ log = logging.getLogger(__name__) # 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 + class LazyLoadingDict(MutableMapping): """ A dictionary object that lazily loads its contents from a provided @@ -173,6 +175,9 @@ class XmlDescriptor(XModuleDescriptor): url identifiers """ 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(): metadata = {} @@ -210,25 +215,21 @@ class XmlDescriptor(XModuleDescriptor): with system.resources_fs.open(filepath) as file: definition_xml = cls.file_to_xml(file) 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) system.error_handler(msg) # 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) 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( system, LazyLoadingDict(definition_loader), - location=['i4x', - org, - course, - xml_object.tag, - slug], + location=location, metadata=LazyLoadingDict(metadata_loader), )