Commit 9a0213bf by Victor Shnayder

Started update of check_course script. It runs again now.

TODO:
  - support picking a different course name
  - make it use current module rendering path, get that working.
parent 63298538
...@@ -10,46 +10,80 @@ from courseware.content_parser import course_file ...@@ -10,46 +10,80 @@ from courseware.content_parser import course_file
import courseware.module_render import courseware.module_render
import xmodule import xmodule
import mitxmako.middleware as middleware
middleware.MakoMiddleware()
def check_names(user, course):
all_ok = True
print "Confirming all problems have alphanumeric names"
for problem in course.xpath('//problem'):
filename = problem.get('filename')
if not filename.isalnum():
print "==============> Invalid (non-alphanumeric) filename", filename
all_ok = False
return all_ok
def check_rendering(user, course):
'''Check that all modules render'''
all_ok = True
print "Confirming all modules render. Nothing should print during this step. "
for module in course.xpath('//problem|//html|//video|//vertical|//sequential|/tab'):
module_class = xmodule.modx_modules[module.tag]
# TODO: Abstract this out in render_module.py
try:
module_class(etree.tostring(module),
module.get('id'),
ajax_url='',
state=None,
track_function = lambda x,y,z:None,
render_function = lambda x: {'content':'','type':'video'})
except Exception as ex:
print "==============> Error in ", etree.tostring(module)
print ""
print ex
all_ok = False
print "Module render check finished"
return all_ok
def check_sections(user, course):
all_ok = True
sections_dir = settings.DATA_DIR + "/sections"
print "Checking that all sections exist and parse properly"
if os.path.exists(sections_dir):
print "Checking all section includes are valid XML"
for f in os.listdir(sections_dir):
sectionfile = sections_dir + '/' + f
print sectionfile
try:
etree.parse(sectionfile)
except Exception as ex:
print "================> Error parsing ", sectionfile
print ex
all_ok = False
print "checked all sections"
else:
print "Skipping check of include files -- no section includes dir ("+sections_dir+")"
return all_ok
class Command(BaseCommand): class Command(BaseCommand):
help = "Does basic validity tests on course.xml." help = "Does basic validity tests on course.xml."
def handle(self, *args, **options): def handle(self, *args, **options):
check = True all_ok = True
sample_user = User.objects.all()[0] sample_user = User.objects.all()[0]
print "Attempting to load courseware" print "Attempting to load courseware"
course = course_file(sample_user) course = course_file(sample_user)
print "Confirming all problems have alphanumeric names"
for problem in course.xpath('//problem'): to_run = [check_names,
filename = problem.get('filename') # check_rendering,
if not filename.isalnum(): check_sections,
print "==============> Invalid (non-alphanumeric) filename", filename ]
check = False for check in to_run:
print "Confirming all modules render. Nothing should print during this step. " all_ok = check(sample_user, course) and all_ok
for module in course.xpath('//problem|//html|//video|//vertical|//sequential|/tab'):
module_class = xmodule.modx_modules[module.tag]
# TODO: Abstract this out in render_module.py
try:
module_class(etree.tostring(module),
module.get('id'),
ajax_url='',
state=None,
track_function = lambda x,y,z:None,
render_function = lambda x: {'content':'','type':'video'})
except:
print "==============> Error in ", etree.tostring(module)
check = False
print "Module render check finished"
sections_dir = settings.DATA_DIR+"sections"
if os.path.exists(sections_dir):
print "Checking all section includes are valid XML"
for f in os.listdir(sections_dir):
print f
etree.parse(sections_dir+'/'+f)
else:
print "Skipping check of include files -- no section includes dir ("+sections_dir+")"
# TODO: print "Checking course properly annotated with preprocess.py" # TODO: print "Checking course properly annotated with preprocess.py"
if all_ok:
if check:
print 'Courseware passes all checks!' print 'Courseware passes all checks!'
else: else:
print "Courseware fails some checks" print "Courseware fails some checks"
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