Repository navigation
Enable mongodb to be used as back-end for git-based authoring workflow #652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
1b111b1
a5bb971
220ec52
39b6465
13bb3bf
2249692
e9ef450
210fa11
2fe4895
fedfa7c
91bf6ad
95952bd
0d938d3
8a84e67
d2e93f7
9b26e5b
42af561
2ba0d40
ef98c54
fb3a5bf
0c1c3f1
77a38af
842556d
079470d
7138aed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,10 @@ def import_static_content(modules, course_loc, course_data_path, static_content_ | |
| content.thumbnail_location = thumbnail_location | ||
|
|
||
| #then commit the content | ||
| static_content_store.save(content) | ||
| try: | ||
| static_content_store.save(content) | ||
| except Exception as err: | ||
| log.exception('Error importing {0}, error={1}'.format(fullname_with_subpath, err)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, just noticing this. Why the generic try/catch? What errors have you seen here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, you already commented on it once and I replied. We were observing a bunch of errors importing courses a few months ago, when we added this; I don't recall what the exceptions were, but there were several kinds. The idea is that such errors really ought to be surfaced to users, and not terminate the import. Also, without logging the exception, the filename of the file causing the error is unknown. This at least surfaces the error to our production team (since they have access to the logs).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha! That could be. We're all doing a lot of things and it's easy to loose track. I'm adding some test to bump up the coverage numbers on xml_import.py. I have to talk to @jzoldak about a few items, because a lot of xml_import is getting exercised in the CMS tests, but I don't think that is getting "counted" as coverage on the common/* reports. So this is a gap in my understanding. So in the meantime, I'm trying to exercise more code paths in the common/* tests. Should get more done tonight or early tomorrow. |
||
|
|
||
| #store the remapping information which will be needed to subsitute in the module data | ||
| remap_dict[fullname_with_subpath] = content_loc.name | ||
|
|
@@ -64,7 +67,8 @@ def import_static_content(modules, course_loc, course_data_path, static_content_ | |
| def import_from_xml(store, data_dir, course_dirs=None, | ||
| default_class='xmodule.raw_module.RawDescriptor', | ||
| load_error_modules=True, static_content_store=None, target_location_namespace=None, | ||
| verbose=False, draft_store=None): | ||
| verbose=False, draft_store=None, | ||
| do_import_static=True): | ||
| """ | ||
| Import the specified xml data_dir into the "store" modulestore, | ||
| using org and course as the location org and course. | ||
|
|
@@ -77,6 +81,10 @@ def import_from_xml(store, data_dir, course_dirs=None, | |
| expects a 'url_name' as an identifier to where things are on disk e.g. ../policies/<url_name>/policy.json as well as metadata keys in | ||
| the policy.json. so we need to keep the original url_name during import | ||
|
|
||
| do_import_static: if False, then static files are not imported into the static content store. This can be employed for courses which | ||
| have substantial unchanging static content, which is to inefficient to import every time the course is loaded. | ||
| Static content for some courses may also be served directly by nginx, instead of going through django. | ||
|
|
||
| """ | ||
|
|
||
| xml_module_store = XMLModuleStore( | ||
|
|
@@ -116,8 +124,17 @@ def import_from_xml(store, data_dir, course_dirs=None, | |
| course_data_path = path(data_dir) / module.data_dir | ||
| course_location = module.location | ||
|
|
||
| log.debug('======> IMPORTING course to location {0}'.format(course_location)) | ||
|
|
||
| module = remap_namespace(module, target_location_namespace) | ||
|
|
||
| if not do_import_static: | ||
| module.lms.static_asset_path = module.data_dir # for old-style xblock where this was actually linked to kvs | ||
| module._model_data['static_asset_path'] = module.data_dir | ||
| log.debug('course static_asset_path={0}'.format(module.lms.static_asset_path)) | ||
|
|
||
| log.debug('course data_dir={0}'.format(module.data_dir)) | ||
|
|
||
| # cdodge: more hacks (what else). Seems like we have a problem when importing a course (like 6.002) which | ||
| # does not have any tabs defined in the policy file. The import goes fine and then displays fine in LMS, | ||
| # but if someone tries to add a new tab in the CMS, then the LMS barfs because it expects that - | ||
|
|
@@ -129,18 +146,36 @@ def import_from_xml(store, data_dir, course_dirs=None, | |
| {"type": "wiki", "name": "Wiki"}] # note, add 'progress' when we can support it on Edge | ||
|
|
||
| import_module(module, store, course_data_path, static_content_store, course_location, | ||
| target_location_namespace or course_location) | ||
| target_location_namespace or course_location, do_import_static=do_import_static) | ||
|
|
||
| course_items.append(module) | ||
|
|
||
| # then import all the static content | ||
| if static_content_store is not None: | ||
| if static_content_store is not None and do_import_static: | ||
| _namespace_rename = target_location_namespace if target_location_namespace is not None else course_location | ||
|
|
||
| # first pass to find everything in /static/ | ||
| import_static_content(xml_module_store.modules[course_id], course_location, course_data_path, static_content_store, | ||
| _namespace_rename, subpath='static', verbose=verbose) | ||
|
|
||
| elif verbose and not do_import_static: | ||
| log.debug('Skipping import of static content, since do_import_static={0}'.format(do_import_static)) | ||
|
|
||
| # no matter what do_import_static is, import "static_import" directory | ||
|
|
||
| # This is needed because the "about" pages (eg "overview") are loaded via load_extra_content, and | ||
| # do not inherit the lms metadata from the course module, and thus do not get "static_content_store" | ||
| # properly defined. Static content referenced in those extra pages thus need to come through the | ||
| # c4x:// contentstore, unfortunately. Tell users to copy that content into the "static_import" subdir. | ||
|
|
||
| simport = 'static_import' | ||
| if os.path.exists(course_data_path / simport): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just so I understand the usage here, XML writers will be advised to put static content into a folder named 'static_import' which is known to have to be referenced by modules (in the link rewriting). Correct?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. This only affects a few special pages. Ideally, the way those special pages are handled through |
||
| _namespace_rename = target_location_namespace if target_location_namespace is not None else course_location | ||
|
|
||
| import_static_content(xml_module_store.modules[course_id], course_location, course_data_path, static_content_store, | ||
| _namespace_rename, subpath=simport, verbose=verbose) | ||
|
|
||
|
|
||
| # finally loop through all the modules | ||
| for module in xml_module_store.modules[course_id].itervalues(): | ||
| if module.category == 'course': | ||
|
|
@@ -156,7 +191,8 @@ def import_from_xml(store, data_dir, course_dirs=None, | |
| log.debug('importing module location {0}'.format(module.location)) | ||
|
|
||
| import_module(module, store, course_data_path, static_content_store, course_location, | ||
| target_location_namespace if target_location_namespace else course_location) | ||
| target_location_namespace if target_location_namespace else course_location, | ||
| do_import_static=do_import_static) | ||
|
|
||
| # now import any 'draft' items | ||
| if draft_store is not None: | ||
|
|
@@ -176,7 +212,8 @@ def import_from_xml(store, data_dir, course_dirs=None, | |
|
|
||
|
|
||
| def import_module(module, store, course_data_path, static_content_store, | ||
| source_course_location, dest_course_location, allow_not_found=False): | ||
| source_course_location, dest_course_location, allow_not_found=False, | ||
| do_import_static=True): | ||
|
|
||
| logging.debug('processing import of module {0}...'.format(module.location.url())) | ||
|
|
||
|
|
@@ -196,7 +233,7 @@ def import_module(module, store, course_data_path, static_content_store, | |
| else: | ||
| module_data = content | ||
|
|
||
| if isinstance(module_data, basestring): | ||
| if isinstance(module_data, basestring) and do_import_static: | ||
| # we want to convert all 'non-portable' links in the module_data (if it is a string) to | ||
| # portable strings (e.g. /static/) | ||
| module_data = rewrite_nonportable_content_links( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is your plan to not use Mongo (via GridFS) for your static resources but serve those off filesystem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - that is the main point of this PR. There are courses with huge
static resource collections, which take too long to import. And the gridfs
contentstore doest allow hierarchial storage.
This PR is already operating in production at MIT.
On Aug 19, 2013 9:22 AM, "chrisndodge" notifications@github.com wrote: