Commit 4d821541 by Calen Pennington

Allow importing of courses that still have mako templating in them

parent 5008e979
...@@ -5,7 +5,9 @@ from lxml import etree ...@@ -5,7 +5,9 @@ from lxml import etree
from path import path from path import path
from xmodule.x_module import XModuleDescriptor, XMLParsingSystem from xmodule.x_module import XModuleDescriptor, XMLParsingSystem
from xmodule.mako_module import MakoDescriptorSystem from xmodule.mako_module import MakoDescriptorSystem
from cStringIO import StringIO
import os import os
import re
from . import ModuleStore, Location from . import ModuleStore, Location
from .exceptions import ItemNotFoundError from .exceptions import ItemNotFoundError
...@@ -16,6 +18,13 @@ etree.set_default_parser(etree.XMLParser(dtd_validation=False, load_dtd=False, ...@@ -16,6 +18,13 @@ etree.set_default_parser(etree.XMLParser(dtd_validation=False, load_dtd=False,
log = logging.getLogger('mitx.' + __name__) log = logging.getLogger('mitx.' + __name__)
# TODO (cpennington): Remove this once all fall 2012 courses have been imported into the cms from xml
def clean_out_mako_templating(xml_string):
xml_string = xml_string.replace('%include', 'include')
xml_string = re.sub("(?m)^\s*%.*$", '', xml_string)
return xml_string
class XMLModuleStore(ModuleStore): class XMLModuleStore(ModuleStore):
""" """
An XML backed ModuleStore An XML backed ModuleStore
...@@ -54,8 +63,11 @@ class XMLModuleStore(ModuleStore): ...@@ -54,8 +63,11 @@ class XMLModuleStore(ModuleStore):
if not os.path.exists(self.data_dir / course_dir / "course.xml"): if not os.path.exists(self.data_dir / course_dir / "course.xml"):
continue continue
course_descriptor = self.load_course(course_dir) try:
self.courses[course_dir] = course_descriptor course_descriptor = self.load_course(course_dir)
self.courses[course_dir] = course_descriptor
except:
log.exception("Failed to load course %s" % course_dir)
def load_course(self, course_dir): def load_course(self, course_dir):
""" """
...@@ -65,6 +77,9 @@ class XMLModuleStore(ModuleStore): ...@@ -65,6 +77,9 @@ class XMLModuleStore(ModuleStore):
with open(self.data_dir / course_dir / "course.xml") as course_file: with open(self.data_dir / course_dir / "course.xml") as course_file:
# TODO (cpennington): Remove this once all fall 2012 courses have been imported into the cms from xml
course_file = StringIO(clean_out_mako_templating(course_file.read()))
course_data = etree.parse(course_file).getroot() course_data = etree.parse(course_file).getroot()
org = course_data.get('org') org = course_data.get('org')
...@@ -91,6 +106,8 @@ class XMLModuleStore(ModuleStore): ...@@ -91,6 +106,8 @@ class XMLModuleStore(ModuleStore):
def process_xml(xml): def process_xml(xml):
try: try:
# TODO (cpennington): Remove this once all fall 2012 courses have been imported into the cms from xml
xml = clean_out_mako_templating(xml)
xml_data = etree.fromstring(xml) xml_data = etree.fromstring(xml)
except: except:
log.exception("Unable to parse xml: {xml}".format(xml=xml)) log.exception("Unable to parse xml: {xml}".format(xml=xml))
......
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