Commit 5b812028 by Calen Pennington

Move the resources_fs abstraction into the primary DescriptorSystem, as it is…

Move the resources_fs abstraction into the primary DescriptorSystem, as it is needed for more than just XMLParsing
parent 3c054306
......@@ -31,26 +31,25 @@ class Command(BaseCommand):
class ImportSystem(XMLParsingSystem):
def __init__(self):
self.load_item = keystore().get_item
self.fs = OSFS(data_dir)
def process_xml(self, xml):
try:
xml_data = etree.fromstring(xml)
except:
raise CommandError("Unable to parse xml: " + xml)
if not xml_data.get('name'):
global unnamed_modules
unnamed_modules += 1
xml_data.set('name', '{tag}_{count}'.format(tag=xml_data.tag, count=unnamed_modules))
module = XModuleDescriptor.load_from_xml(etree.tostring(xml_data), self, org, course, RawDescriptor)
keystore().create_item(module.url)
if 'data' in module.definition:
keystore().update_item(module.url, module.definition['data'])
if 'children' in module.definition:
keystore().update_children(module.url, module.definition['children'])
return module
def process_xml(xml):
try:
xml_data = etree.fromstring(xml)
except:
raise CommandError("Unable to parse xml: " + xml)
if not xml_data.get('name'):
global unnamed_modules
unnamed_modules += 1
xml_data.set('name', '{tag}_{count}'.format(tag=xml_data.tag, count=unnamed_modules))
module = XModuleDescriptor.load_from_xml(etree.tostring(xml_data), self, org, course, RawDescriptor)
keystore().create_item(module.url)
if 'data' in module.definition:
keystore().update_item(module.url, module.definition['data'])
if 'children' in module.definition:
keystore().update_children(module.url, module.definition['children'])
return module
XMLParsingSystem.__init__(self, keystore().get_item, OSFS(data_dir), process_xml)
ImportSystem().process_xml(course_file.read())
......@@ -51,8 +51,9 @@ class MongoModuleStore(ModuleStore):
if item is None:
raise ItemNotFoundError(location)
# TODO (cpennington): Pass a proper resources_fs to the system
return XModuleDescriptor.load_from_json(
item, DescriptorSystem(self.get_item), self.default_class)
item, DescriptorSystem(self.get_item, None), self.default_class)
def create_item(self, location):
"""
......
......@@ -23,7 +23,7 @@ def process_includes(fn):
file = next_include.get('file')
if file is not None:
try:
ifp = system.fs.open(file)
ifp = system.resources_fs.open(file)
except Exception:
log.exception('Error in problem xml include: %s' % (etree.tostring(next_include, pretty_print=True)))
log.exception('Cannot find file %s in %s' % (file, dir))
......
......@@ -331,20 +331,21 @@ class XModuleDescriptor(Plugin):
class DescriptorSystem(object):
def __init__(self, load_item):
def __init__(self, load_item, resources_fs):
"""
load_item: Takes a Location and returns an XModuleDescriptor
resources_fs: A Filesystem object that contains all of the
resources needed for the course
"""
self.load_item = load_item
self.resources_fs = resources_fs
class XMLParsingSystem(DescriptorSystem):
def __init__(self, load_item, process_xml, fs):
def __init__(self, load_item, resources_fs, process_xml):
"""
process_xml: Takes an xml string, and returns the the XModuleDescriptor created from that xml
fs: A Filesystem object that contains all of the xml resources needed to parse
the course
"""
DescriptorSystem.__init__(self, load_item, resources_fs)
self.process_xml = process_xml
self.fs = fs
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