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