diff --git a/courseware/capa/capa_problem.py b/courseware/capa/capa_problem.py index 2ed579d224..73ef168cf0 100644 --- a/courseware/capa/capa_problem.py +++ b/courseware/capa/capa_problem.py @@ -83,7 +83,7 @@ class LoncapaProblem(object): self.seed=struct.unpack('i', os.urandom(4))[0] ## Parse XML file - log.debug(u"LoncapaProblem() opening file {0}".format(filename)) + #log.debug(u"LoncapaProblem() opening file {0}".format(filename)) file_text = open(filename).read() # Convert startouttext and endouttext to proper # TODO: Do with XML operations diff --git a/courseware/management/__init__.py b/courseware/management/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/courseware/management/commands/__init__.py b/courseware/management/commands/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/courseware/management/commands/check_course.py b/courseware/management/commands/check_course.py new file mode 100644 index 0000000000..e335b13bb8 --- /dev/null +++ b/courseware/management/commands/check_course.py @@ -0,0 +1,50 @@ +import os.path + +from lxml import etree + +from django.core.management.base import BaseCommand +from django.conf import settings +from django.contrib.auth.models import User + +from mitx.courseware.content_parser import course_file +import mitx.courseware.module_render + +class Command(BaseCommand): + help = "Does basic validity tests on course.xml." + def handle(self, *args, **options): + check = True + sample_user = User.objects.all()[0] + print "Attempting to load courseware" + course = course_file(sample_user) + 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 + check = False + print "Confirming all modules render. Nothing should print during this step. " + for module in course.xpath('//problem|//html|//video'): + module_class=mitx.courseware.module_render.modx_modules[module.tag] + # TODO: Abstract this out in render_module.py + try: + instance=module_class(etree.tostring(module), + module.get('id'), + ajax_url='', + state=None, + track_function = lambda x,y,z:None, + render_function = lambda x: {'content':'','destroy_js':'','init_js':'','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): + etree.parse(sections_dir+'/'+f) + else: + print "Skipping check of include files -- no section includes dir ("+sections_dir+")" + if check: + print 'Courseware passes all checks!' + else: + print "Courseware fails some checks" diff --git a/courseware/modules/capa_module.py b/courseware/modules/capa_module.py index 78e9586462..cd740d7dea 100644 --- a/courseware/modules/capa_module.py +++ b/courseware/modules/capa_module.py @@ -131,7 +131,7 @@ class LoncapaModule(XModule): display_due_date_string=content_parser.item(dom2.xpath('/problem/@due')) if len(display_due_date_string)>0: self.display_due_date=dateutil.parser.parse(display_due_date_string) - log.debug("Parsed " + display_due_date_string + " to " + str(self.display_due_date)) + #log.debug("Parsed " + display_due_date_string + " to " + str(self.display_due_date)) else: self.display_due_date=None @@ -140,7 +140,7 @@ class LoncapaModule(XModule): if len(grace_period_string)>0 and self.display_due_date: self.grace_period = content_parser.parse_timedelta(grace_period_string) self.close_date = self.display_due_date + self.grace_period - log.debug("Then parsed " + grace_period_string + " to closing date" + str(self.close_date)) + #log.debug("Then parsed " + grace_period_string + " to closing date" + str(self.close_date)) else: self.grace_period = None self.close_date = self.display_due_date