Commit 20e4d585 by Don Mitchell

Add documentation and comments.

parent 8e7fc153
...@@ -104,7 +104,16 @@ class MongoContentStore(ContentStore): ...@@ -104,7 +104,16 @@ class MongoContentStore(ContentStore):
with disk_fs.open(content.name, 'wb') as asset_file: with disk_fs.open(content.name, 'wb') as asset_file:
asset_file.write(content.data) asset_file.write(content.data)
def export_all_for_course(self, course_location, output_directory, policy_file): def export_all_for_course(self, course_location, output_directory, assets_policy_file):
"""
Export all of this course's assets to the output_directory. Export all of the assets'
attributes to the policy file.
:param course_location: the Location of type 'course'
:param output_directory: the directory under which to put all the asset files
:param assets_policy_file: the filename for the policy file which should be in the same
directory as the other policy files.
"""
policy = {} policy = {}
assets = self.get_all_content_for_course(course_location) assets = self.get_all_content_for_course(course_location)
...@@ -115,7 +124,7 @@ class MongoContentStore(ContentStore): ...@@ -115,7 +124,7 @@ class MongoContentStore(ContentStore):
if attr not in ['_id', 'md5', 'uploadDate', 'length', 'chunkSize']: if attr not in ['_id', 'md5', 'uploadDate', 'length', 'chunkSize']:
policy.setdefault(asset_location.url(), {})[attr] = value policy.setdefault(asset_location.url(), {})[attr] = value
with open(policy_file, 'w') as f: with open(assets_policy_file, 'w') as f:
json.dump(policy, f) json.dump(policy, f)
def get_all_content_thumbnails_for_course(self, location): def get_all_content_thumbnails_for_course(self, location):
......
...@@ -27,6 +27,8 @@ def import_static_content(modules, course_loc, course_data_path, static_content_ ...@@ -27,6 +27,8 @@ def import_static_content(modules, course_loc, course_data_path, static_content_
with open(course_data_path / 'policies/assets.json') as f: with open(course_data_path / 'policies/assets.json') as f:
policy = json.load(f) policy = json.load(f)
except (IOError, ValueError) as err: except (IOError, ValueError) as err:
# xml backed courses won't have this file, only exported courses; so, its absence is not
# really an exception.
policy = {} policy = {}
verbose = True verbose = True
......
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