def get_context_data(self, form, **kwargs): context = super(CreateTestcaseWizard, self).get_context_data(form=form, **kwargs) program = Program.objects.get(pk=self.kwargs['programID']) compiler_command = get_compilation_command(program) execution_command = get_execution_command(program) context.update({'program': program, 'compiler_command': compiler_command, 'execution_command':execution_command}) return context
def get_context_data(self, form, **kwargs): context = super(EditTestcaseWizard, self).get_context_data(form=form, **kwargs) testcase = Testcase.objects.get(pk=self.kwargs['testcaseID']) program = testcase.program compiler_command = get_compilation_command(program) execution_command = get_execution_command(program) context.update({'testcase': testcase, 'compiler_command': compiler_command, 'execution_command':execution_command}) return context
def __init__(self, program_result, program_type): self.program_result = program_result # Used in template. self.compiler_command = get_compilation_command(program_result.program) self.execution_command = get_execution_command(program_result.program) all_obj = TestcaseResult.objects.filter(program_result=program_result) test_type_obj = [a for a in all_obj] self.testResults = [Results.TestcaseResultSaved(obj) for obj in test_type_obj] self.marks = reduce(lambda x,y: x + y.marks, self.testResults, 0)
def get_context_data(self, form, **kwargs): context = super(CreateTestcaseWizard, self).get_context_data(form=form, **kwargs) program = Program.objects.get(pk=self.kwargs['programID']) compiler_command = get_compilation_command(program) execution_command = get_execution_command(program) context.update({ 'program': program, 'compiler_command': compiler_command, 'execution_command': execution_command }) return context
def __init__(self, program_result, program_type): self.program_result = program_result # Used in template. self.compiler_command = get_compilation_command( program_result.program) self.execution_command = get_execution_command( program_result.program) all_obj = TestcaseResult.objects.filter( program_result=program_result) test_type_obj = [a for a in all_obj] self.testResults = [ Results.TestcaseResultSaved(obj) for obj in test_type_obj ] self.marks = reduce(lambda x, y: x + y.marks, self.testResults, 0)
def get_context_data(self, form, **kwargs): context = super(EditTestcaseWizard, self).get_context_data(form=form, **kwargs) testcase = Testcase.objects.get(pk=self.kwargs['testcaseID']) program = testcase.program compiler_command = get_compilation_command(program) execution_command = get_execution_command(program) context.update({ 'testcase': testcase, 'compiler_command': compiler_command, 'execution_command': execution_command }) return context
def detailProgram(request, programID): program = get_object_or_404(Program, pk=programID) testcases = Testcase.objects.filter(program=program) assignment = program.assignment is_due = (timezone.now() >= assignment.deadline) course = assignment.course has_submitted = Upload.objects.filter(owner=request.user, assignment=assignment) all_assignments = Assignment.objects.filter( course=course).order_by('-serial_number') is_moderator = isCourseModerator(course, request.user) if is_moderator: assignments = all_assignments else: assignments = [ a for a in all_assignments if a.publish_on <= timezone.now() ] compiler_command = get_compilation_command(program) execution_command = get_execution_command(program) program_errors = None if not program.is_sane: try: program_errors = ProgramErrors.objects.get(program=program) except ProgramErrors.DoesNotExist: program_errors = None testcase_errors = [] terror_ctype = ContentType.objects.get_for_model(TestcaseErrors) for error in AssignmentErrors.objects.filter(assignment=program.assignment, content_type=terror_ctype): testcase_errors.extend( TestcaseErrors.objects.filter(pk=error.object_id)) get_params = {'source': 'section', 'id': programID} return render_to_response('assignments/detailsProgram.html', { 'program': program, 'testcases': testcases, 'assignment': assignment, 'assignments': assignments, 'date_time': timezone.now(), 'program_errors': program_errors, 'compiler_command': compiler_command, 'execution_command': execution_command, 'course': course, 'is_moderator': is_moderator, 'is_due': is_due, 'has_submitted': has_submitted, 'get_params': get_params, 'testcase_errors': testcase_errors }, context_instance=RequestContext(request))
def __init__(self, program, assignment_result): self.assignment_result = assignment_result self.program = program # Extracting the list of files relevant to only this section. if program.program_files: prgrm_files = get_file_name_list(name=program.program_files.file.name) prgrm_files = " ".join(prgrm_files) else: prgrm_files = "" # Adding the list of files in the assignment model solution to the above list. self.programFiles = program.assignment.student_program_files + " " + prgrm_files self.language = program.assignment.program_language self.compiler_command = get_compilation_command(program) self.execution_command = get_execution_command(program) self.commandExecutor = CommandExecutor()
def __init__(self, program, assignment_result): self.assignment_result = assignment_result self.program = program # Extracting the list of files relevant to only this section. if program.program_files: prgrm_files = get_file_name_list( name=program.program_files.file.name) prgrm_files = " ".join(prgrm_files) else: prgrm_files = "" # Adding the list of files in the assignment model solution to the above list. self.programFiles = program.assignment.student_program_files + " " + prgrm_files self.language = program.assignment.program_language self.compiler_command = get_compilation_command(program) self.execution_command = get_execution_command(program) self.commandExecutor = CommandExecutor()
def detailProgram(request, programID): program = get_object_or_404(Program, pk=programID) testcases = Testcase.objects.filter(program=program) assignment = program.assignment is_due = (timezone.now() >= assignment.deadline) course = assignment.course has_submitted = Upload.objects.filter(owner=request.user, assignment=assignment) all_assignments = Assignment.objects.filter(course=course).order_by('-serial_number') is_moderator = isCourseModerator(course, request.user) if is_moderator: assignments = all_assignments else: assignments = [a for a in all_assignments if a.publish_on <= timezone.now()] compiler_command = get_compilation_command(program) execution_command = get_execution_command(program) program_errors = None if not program.is_sane: try: program_errors = ProgramErrors.objects.get(program=program) except ProgramErrors.DoesNotExist: program_errors = None testcase_errors = [] terror_ctype = ContentType.objects.get_for_model(TestcaseErrors) for error in AssignmentErrors.objects.filter(assignment=program.assignment, content_type=terror_ctype): testcase_errors.extend(TestcaseErrors.objects.filter(pk=error.object_id)) get_params = {'source': 'section', 'id': programID} return render_to_response( 'assignments/detailsProgram.html', {'program':program, 'testcases':testcases, 'assignment':assignment, 'assignments':assignments, 'date_time': timezone.now(), 'program_errors':program_errors, 'compiler_command':compiler_command, 'execution_command':execution_command, 'course':course, 'is_moderator':is_moderator, 'is_due': is_due, 'has_submitted':has_submitted, 'get_params': get_params, 'testcase_errors': testcase_errors}, context_instance=RequestContext(request) )
def run(self): # Compile the solution. If there are errors then write it to the error file and return if compile_required(self.program.language): compiler_command = get_compilation_command(self.program) print "Compiling model solution. Compilation Command - " + compiler_command self.command_output = self.commandExecutor.safe_execute( command=compiler_command, limits=self.get_resource_limit() ) if self.command_output.getReturnCode(): # There was some error. Write it in database. print "Compilation of model solution failed." self.failed = True _, self.error_file = tempfile.mkstemp(prefix="error", dir=self.temp_input_d) f = open(self.error_file, 'w') for a_line in self.command_output.get_stderr(): f.write(a_line) f.close() return # No errors and thus can continue. Run the solution execution_command = get_execution_command(self.program) print "Creating Output. Running following execution command - " + execution_command #if self.testcase.command_line_args: # execution_command = execution_command + self.testcase.command_line_args if self.testcase.std_in_file_name: execution_command = execution_command + " < " + self.testcase.std_in_file_name self.command_output = self.commandExecutor.safe_execute( command=execution_command, limits=self.get_resource_limit() ) self.success = bool(self.command_output.getReturnCode()) self.command_output.printResult() # Delete input files from current directory. And the program files dir_content = os.listdir('./') for a_file in dir_content: if self.is_program_file(a_file): os.remove(a_file) if self.input: for a_file in get_file_name_list(name=self.input): # delete extracted files if os.path.isfile(a_file): os.remove(a_file) # Write standard output to a file and save it in database. directory_content = os.listdir('./') _, self.std_out_file = tempfile.mkstemp(prefix='output', dir="./") out_file = open(self.std_out_file, 'w') for a_line in ["\n".join(self.command_output.get_stdout())]: out_file.write(a_line) out_file.close() # There was some error. Write it in database. if self.command_output.getReturnCode(): self.failed = True _, self.error_file = tempfile.mkstemp(prefix="error", dir=self.temp_input_d) f = open(self.error_file, 'w') for a_line in self.command_output.get_stderr(): f.write(a_line) f.close() # If directory has any content left then make a tar, else set the outfile to the output file. if directory_content: # make a tar self.out_file = self.make_tar(directory_content + [self.std_out_file], self.std_out_file) else: # there are no other files standard output only. self.out_file = self.std_out_file
def run(self): # Compile the solution. If there are errors then write it to the error file and return if compile_required(self.program.language): compiler_command = get_compilation_command(self.program) print "Compiling model solution. Compilation Command - " + compiler_command self.command_output = self.commandExecutor.safe_execute( command=compiler_command, limits=self.get_resource_limit()) if self.command_output.getReturnCode(): # There was some error. Write it in database. print "Compilation of model solution failed." self.failed = True _, self.error_file = tempfile.mkstemp(prefix="error", dir=self.temp_input_d) f = open(self.error_file, 'w') for a_line in self.command_output.get_stderr(): f.write(a_line) f.close() return # No errors and thus can continue. Run the solution execution_command = get_execution_command(self.program) print "Creating Output. Running following execution command - " + execution_command #if self.testcase.command_line_args: # execution_command = execution_command + self.testcase.command_line_args if self.testcase.std_in_file_name: execution_command = execution_command + " < " + self.testcase.std_in_file_name self.command_output = self.commandExecutor.safe_execute( command=execution_command, limits=self.get_resource_limit()) self.success = bool(self.command_output.getReturnCode()) self.command_output.printResult() # Delete input files from current directory. And the program files dir_content = os.listdir('./') for a_file in dir_content: if self.is_program_file(a_file): os.remove(a_file) if self.input: for a_file in get_file_name_list( name=self.input): # delete extracted files if os.path.isfile(a_file): os.remove(a_file) # Write standard output to a file and save it in database. directory_content = os.listdir('./') _, self.std_out_file = tempfile.mkstemp(prefix='output', dir="./") out_file = open(self.std_out_file, 'w') for a_line in ["\n".join(self.command_output.get_stdout())]: out_file.write(a_line) out_file.close() # There was some error. Write it in database. if self.command_output.getReturnCode(): self.failed = True _, self.error_file = tempfile.mkstemp(prefix="error", dir=self.temp_input_d) f = open(self.error_file, 'w') for a_line in self.command_output.get_stderr(): f.write(a_line) f.close() # If directory has any content left then make a tar, else set the outfile to the output file. if directory_content: # make a tar self.out_file = self.make_tar( directory_content + [self.std_out_file], self.std_out_file) else: # there are no other files standard output only. self.out_file = self.std_out_file