Commit e92799bb by Chris Dodge

switch from prints to logging.debug. Also refactor some duplicate code

parent b18fb97e
...@@ -2,6 +2,8 @@ from xmodule.contentstore.content import StaticContent ...@@ -2,6 +2,8 @@ from xmodule.contentstore.content import StaticContent
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.modulestore.mongo import MongoModuleStore from xmodule.modulestore.mongo import MongoModuleStore
import logging
def clone_course(modulestore, contentstore, source_location, dest_location, delete_original=False): def clone_course(modulestore, contentstore, source_location, dest_location, delete_original=False):
# first check to see if the modulestore is Mongo backed # first check to see if the modulestore is Mongo backed
...@@ -109,7 +111,7 @@ def _delete_modules_except_course(modulestore, modules, source_location, commit) ...@@ -109,7 +111,7 @@ def _delete_modules_except_course(modulestore, modules, source_location, commit)
""" """
for module in modules: for module in modules:
if module.category != 'course': if module.category != 'course':
print "Deleting {0}...".format(module.location) logging.debug("Deleting {0}...".format(module.location))
if commit: if commit:
# sanity check. Make sure we're not deleting a module in the incorrect course # sanity check. Make sure we're not deleting a module in the incorrect course
if module.location.org != source_location.org or module.location.course != source_location.course: if module.location.org != source_location.org or module.location.course != source_location.course:
...@@ -117,6 +119,18 @@ def _delete_modules_except_course(modulestore, modules, source_location, commit) ...@@ -117,6 +119,18 @@ def _delete_modules_except_course(modulestore, modules, source_location, commit)
modulestore.delete_item(module.location) modulestore.delete_item(module.location)
def _delete_assets(contentstore, assets, commit):
"""
This helper method will enumerate through a list of assets and delete them
"""
for asset in assets:
asset_loc = Location(asset["_id"])
id = StaticContent.get_id_from_location(asset_loc)
logging.debug("Deleting {0}...".format(id))
if commit:
contentstore.delete(id)
def delete_course(modulestore, contentstore, source_location, commit=False): def delete_course(modulestore, contentstore, source_location, commit=False):
""" """
This method will actually do the work to delete all content in a course in a MongoDB backed This method will actually do the work to delete all content in a course in a MongoDB backed
...@@ -133,21 +147,11 @@ def delete_course(modulestore, contentstore, source_location, commit=False): ...@@ -133,21 +147,11 @@ def delete_course(modulestore, contentstore, source_location, commit=False):
# first delete all of the thumbnails # first delete all of the thumbnails
thumbs = contentstore.get_all_content_thumbnails_for_course(source_location) thumbs = contentstore.get_all_content_thumbnails_for_course(source_location)
for thumb in thumbs: _delete_assets(contentstore, thumbs, commit)
thumb_loc = Location(thumb["_id"])
id = StaticContent.get_id_from_location(thumb_loc)
print "Deleting {0}...".format(id)
if commit:
contentstore.delete(id)
# then delete all of the assets # then delete all of the assets
assets = contentstore.get_all_content_for_course(source_location) assets = contentstore.get_all_content_for_course(source_location)
for asset in assets: _delete_assets(contentstore, assets, commit)
asset_loc = Location(asset["_id"])
id = StaticContent.get_id_from_location(asset_loc)
print "Deleting {0}...".format(id)
if commit:
contentstore.delete(id)
# then delete all course modules # then delete all course modules
modules = modulestore.get_items([source_location.tag, source_location.org, source_location.course, None, None, None]) modules = modulestore.get_items([source_location.tag, source_location.org, source_location.course, None, None, None])
......
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