Commit a521ea23 by Chris Dodge

baseline working for importing courseware and static assets

parent bb46c5f9
...@@ -12,6 +12,7 @@ TEMPLATE_DEBUG = DEBUG ...@@ -12,6 +12,7 @@ TEMPLATE_DEBUG = DEBUG
LOGGING = get_logger_config(ENV_ROOT / "log", LOGGING = get_logger_config(ENV_ROOT / "log",
logging_env="dev", logging_env="dev",
tracking_filename="tracking.log", tracking_filename="tracking.log",
dev_env = True,
debug=True) debug=True)
modulestore_options = { modulestore_options = {
......
...@@ -18,7 +18,7 @@ class MongoContentStore(ContentStore): ...@@ -18,7 +18,7 @@ class MongoContentStore(ContentStore):
logging.debug( 'Using MongoDB for static content serving at host={0} db={1}'.format(host,db)) logging.debug( 'Using MongoDB for static content serving at host={0} db={1}'.format(host,db))
_db = Connection(host=host, port=port, **kwargs)[db] _db = Connection(host=host, port=port, **kwargs)[db]
if self.user is not None and self.password is not None: if user is not None and password is not None:
_db.authenticate(user, password) _db.authenticate(user, password)
self.fs = gridfs.GridFS(_db) self.fs = gridfs.GridFS(_db)
......
...@@ -5,48 +5,28 @@ import mimetypes ...@@ -5,48 +5,28 @@ import mimetypes
from .xml import XMLModuleStore from .xml import XMLModuleStore
from .exceptions import DuplicateItemError from .exceptions import DuplicateItemError
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.contentstore.content import StaticContent from xmodule.contentstore.content import StaticContent, XASSET_SRCREF_PREFIX
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def import_static_content(modules, data_dir, static_content_store):
def import_from_xml(store, data_dir, course_dirs=None, remap_dict = {}
default_class='xmodule.raw_module.RawDescriptor',
load_error_modules=True, static_content_store=None):
"""
Import the specified xml data_dir into the "store" modulestore,
using org and course as the location org and course.
course_dirs: If specified, the list of course_dirs to load. Otherwise, load
all course dirs
"""
module_store = XMLModuleStore(
data_dir,
default_class=default_class,
course_dirs=course_dirs,
load_error_modules=load_error_modules,
)
for course_id in module_store.modules.keys():
course_data_dir = None course_data_dir = None
course_loc = None course_loc = None
for module in module_store.modules[course_id].itervalues(): # quick scan to find the course module and pull out the data_dir and location
# maybe there an easier way to look this up?!?
for module in modules.itervalues():
if module.category == 'course': if module.category == 'course':
course_loc = module.location course_loc = module.location
if 'data' in module.definition:
store.update_item(module.location, module.definition['data'])
if 'children' in module.definition:
store.update_children(module.location, module.definition['children'])
# NOTE: It's important to use own_metadata here to avoid writing
# inherited metadata everywhere.
store.update_metadata(module.location, dict(module.own_metadata))
course_data_dir = module.metadata['data_dir'] course_data_dir = module.metadata['data_dir']
if static_content_store is not None: if course_data_dir is None or course_loc is None:
return remap_dict
''' '''
now import all static assets now import all static assets
''' '''
...@@ -78,7 +58,62 @@ def import_from_xml(store, data_dir, course_dirs=None, ...@@ -78,7 +58,62 @@ def import_from_xml(store, data_dir, course_dirs=None,
#then commit the content #then commit the content
static_content_store.save(content) static_content_store.save(content)
#store the remapping information which will be needed to subsitute in the module data
remap_dict[fullname_with_subpath] = content_loc.name
except: except:
raise raise
return remap_dict
def import_from_xml(store, data_dir, course_dirs=None,
default_class='xmodule.raw_module.RawDescriptor',
load_error_modules=True, static_content_store=None):
"""
Import the specified xml data_dir into the "store" modulestore,
using org and course as the location org and course.
course_dirs: If specified, the list of course_dirs to load. Otherwise, load
all course dirs
"""
module_store = XMLModuleStore(
data_dir,
default_class=default_class,
course_dirs=course_dirs,
load_error_modules=load_error_modules,
)
for course_id in module_store.modules.keys():
remap_dict = {}
if static_content_store is not None:
remap_dict = import_static_content(module_store.modules[course_id], data_dir, static_content_store)
for module in module_store.modules[course_id].itervalues():
if module.category == 'course':
course_loc = module.location
course_data_dir = module.metadata['data_dir']
if 'data' in module.definition:
module_data = module.definition['data']
# cdodge: update any references to the static content paths
# This is a bit brute force - simple search/replace - but it's unlikely that such references to '/static/....'
# would occur naturally (in the wild)
if '/static/' in module_data:
for subkey in remap_dict.keys():
module_data = module_data.replace('/static/' + subkey, 'xasset:' + remap_dict[subkey])
logging.debug("was {0} now {1}".format(module.definition['data'], module_data))
store.update_item(module.location, module_data)
if 'children' in module.definition:
store.update_children(module.location, module.definition['children'])
# NOTE: It's important to use own_metadata here to avoid writing
# inherited metadata everywhere.
store.update_metadata(module.location, dict(module.own_metadata))
return module_store return module_store
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