switch from prints to logging.debug. Also refactor some duplicate code
This commit is contained in:
@@ -2,6 +2,8 @@ from xmodule.contentstore.content import StaticContent
|
||||
from xmodule.modulestore import Location
|
||||
from xmodule.modulestore.mongo import MongoModuleStore
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
def clone_course(modulestore, contentstore, source_location, dest_location, delete_original=False):
|
||||
# first check to see if the modulestore is Mongo backed
|
||||
@@ -109,7 +111,7 @@ def _delete_modules_except_course(modulestore, modules, source_location, commit)
|
||||
"""
|
||||
for module in modules:
|
||||
if module.category != 'course':
|
||||
print "Deleting {0}...".format(module.location)
|
||||
logging.debug("Deleting {0}...".format(module.location))
|
||||
if commit:
|
||||
# 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:
|
||||
@@ -117,6 +119,18 @@ def _delete_modules_except_course(modulestore, modules, source_location, commit)
|
||||
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):
|
||||
"""
|
||||
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):
|
||||
|
||||
# first delete all of the thumbnails
|
||||
thumbs = contentstore.get_all_content_thumbnails_for_course(source_location)
|
||||
for thumb in thumbs:
|
||||
thumb_loc = Location(thumb["_id"])
|
||||
id = StaticContent.get_id_from_location(thumb_loc)
|
||||
print "Deleting {0}...".format(id)
|
||||
if commit:
|
||||
contentstore.delete(id)
|
||||
_delete_assets(contentstore, thumbs, commit)
|
||||
|
||||
# then delete all of the assets
|
||||
assets = contentstore.get_all_content_for_course(source_location)
|
||||
for asset in assets:
|
||||
asset_loc = Location(asset["_id"])
|
||||
id = StaticContent.get_id_from_location(asset_loc)
|
||||
print "Deleting {0}...".format(id)
|
||||
if commit:
|
||||
contentstore.delete(id)
|
||||
_delete_assets(contentstore, assets, commit)
|
||||
|
||||
# then delete all course modules
|
||||
modules = modulestore.get_items([source_location.tag, source_location.org, source_location.course, None, None, None])
|
||||
|
||||
Reference in New Issue
Block a user