Ejemplo n.º 1
0
    def setup(self):
        # This is the directory where the student program is copied to.
        self.temp_dir = tempfile.mkdtemp(prefix="grader", dir=self.eval_dir)
        os.chdir(self.temp_dir)

        # Copy student solution files to tmp directory.
        extract_or_copy(src=self.submission.filePath.file.name,
                        dest=self.temp_dir)

        # Another temp directory for running solution program. This is the directory where the solution program is copied to.
        self.solution_temp_dir = tempfile.mkdtemp(prefix="solution",
                                                  dir=self.eval_dir)

        directories = [a for a in os.listdir('./') if os.path.isdir(a)]
        if directories:
            os.chdir(directories[0])
        currentDir = os.getcwd()

        # Extract the program file and the input file to the student directory, and the input file to the program directory as well.
        extract_or_copy(src=self.program.program_files.file.name,
                        dest=currentDir)
        self.submittedFiles = get_file_name_list(
            name=self.submission.filePath.file.name)
        input_file = self.store_input_file(self.inputFile, currentDir)
        shutil.copy(src=input_file, dst=self.solution_temp_dir)
Ejemplo n.º 2
0
    def test_passed(self):
        # Create a temporary directory and copy the expected output of the testcase to this file.
        temp_dir = tempfile.mkdtemp(prefix="grader_op_files")
        extract_or_copy(src=self.testcase.output_files.file.name, dest=temp_dir)
        std_output_file = str(self.testcase.std_out_file_name)

        # Other output files are stored in this variable.
        self.output_files = os.listdir(temp_dir)
        self.output_files.remove(std_output_file)

        # Now check for the status of the testcase. Call compare_output().
        is_passed = False
        print "Testcase return code is - ", self.testResults.returnCode
        if self.testResults.returnCode == 0: # Exited normally.
            is_passed = self.compare_output(temp_dir, std_output_file)

        # Remove the temporary directory and return the status of the testcase.
        shutil.rmtree(temp_dir, ignore_errors=True)
        return is_passed
Ejemplo n.º 3
0
    def test_passed(self):
        # Create a temporary directory and copy the expected output of the testcase to this file.
        temp_dir = tempfile.mkdtemp(prefix="grader_op_files")
        extract_or_copy(src=self.testcase.output_files.file.name,
                        dest=temp_dir)
        std_output_file = str(self.testcase.std_out_file_name)

        # Other output files are stored in this variable.
        self.output_files = os.listdir(temp_dir)
        self.output_files.remove(std_output_file)

        # Now check for the status of the testcase. Call compare_output().
        is_passed = False
        print "Testcase return code is - ", self.testResults.returnCode
        if self.testResults.returnCode == 0:  # Exited normally.
            is_passed = self.compare_output(temp_dir, std_output_file)

        # Remove the temporary directory and return the status of the testcase.
        shutil.rmtree(temp_dir, ignore_errors=True)
        return is_passed
Ejemplo n.º 4
0
    def setup(self):
        # This is the directory where the student program is copied to.
        self.temp_dir = tempfile.mkdtemp(prefix="grader", dir=self.eval_dir)
        os.chdir(self.temp_dir)

        # Copy student solution files to tmp directory.
        extract_or_copy(src=self.submission.filePath.file.name, dest=self.temp_dir)

        # Another temp directory for running solution program. This is the directory where the solution program is copied to.
        self.solution_temp_dir = tempfile.mkdtemp(prefix="solution", dir=self.eval_dir)
        
        directories = [a for a in os.listdir('./') if os.path.isdir(a)]
        if directories:
            os.chdir(directories[0])
        currentDir = os.getcwd()

        # Extract the program file and the input file to the student directory, and the input file to the program directory as well.
        extract_or_copy(src=self.program.program_files.file.name, dest=currentDir)
        self.submittedFiles = get_file_name_list(name=self.submission.filePath.file.name)
        input_file = self.store_input_file(self.inputFile, currentDir)
        shutil.copy(src=input_file, dst=self.solution_temp_dir)
Ejemplo n.º 5
0
    def setup(self):
        # create temporary directory.
        self.temp_dir = tempfile.mkdtemp(prefix="solution", dir=self.eval_dir)
        os.chdir(self.temp_dir)

        currentDir = os.getcwd()

        # Copy program files and input files to the directory
        if self.program.program_files :
            extract_or_copy(src=self.program.program_files.file.name, dest=currentDir)
        if self.program.assignment.model_solution:
            extract_or_copy(src=self.program.assignment.model_solution.file.name, dest=currentDir)

        # write input file to temporary file.
        self.temp_input_d = tempfile.mkdtemp(prefix="input")
        if self.input_files:
            self.input = os.path.join(
                                self.temp_input_d,
                                os.path.basename(self.testcase.input_files.file.name)
                            )
            f = open(self.input, 'w')
            for a_line in self.input_files.file:
                f.write(a_line)
            f.close()
            # input file has been written now extract.
            extract_or_copy(src=self.input, dest=currentDir)
        else:
            self.input = ''
Ejemplo n.º 6
0
    def setup(self, submission, program_type):
        # Create a temporary directory inside the evaluation directory. Copy the submission files into this directory.
        src = submission.filePath.file.name # gives absolute path
        self.temp_dir = tempfile.mkdtemp(prefix="grader", dir=self.eval_dir)
        os.chdir(self.temp_dir)
        extract_or_copy(src=src, dest=self.temp_dir)

        # Update or create the assignment result for the submission. Update the submitted files for existing assignment results.
        self.submittedFiles = get_file_name_list(name=src)
        self.assignment_result, _ = AssignmentResults.objects.get_or_create(
                                            submission=submission,
                                            defaults={'submitted_files': "\n".join(self.submittedFiles)}
                                        )
        self.assignment_result.is_stale = False
        self.assignment_result.save()

        # Assuming only 1 directory level, cd to that directory. If the student submitted only 1 file, then dont do anything.
        directories = [a for a in os.listdir('./') if os.path.isdir(a)]
        if directories:
            os.chdir(directories[0])
        currentDir = os.getcwd()

        # Copy the program files (of all sections) to this directory. Note that the solution file is still student's submission.
        programs = ProgramModel.objects.filter(assignment=submission.assignment)
        testcaseList = []
        for program in programs:
            testcaseList.append(Testcase.objects.filter(program=program))
            if program.program_files:
                extract_or_copy(src=program.program_files.file.name, dest=currentDir)

        # Copy input-output files for all testcases. Now we are ready for the evaluation process.
        for testcase in testcaseList:
            for test in testcase:
                if test.input_files:
                    extract_or_copy(src=test.input_files.file.name, dest=currentDir)