Beispiel #1
0
    def __init__(self, ta_config):
        try:
            self._config = ta_config
            self.students_zip_container = self._config["StudentsZipContainer"]
            self.students_pattern = self._config["StudentsPattern"]
            self.update_student_pattern = self._config["UpdateStudentPattern"]
            self.students_extract_dir = self._config["StudentsExtractDir"]
            self.extract_afresh = self._config["ExtractAfresh"]
            self.students_zips = globbing(self.students_zip_container + os.sep + "*")

            # Parse the students' id and sort them
            self.students = self._parse_students()
            self.students.sort(key=lambda x: x.id)
        except KeyError as e:
            print("[ERROR] " + str(e) + " field was not found in config file.")
            print("Please check `judge.conf` first.")
            exit(1)
        try:
            # Create the temporary directory for output
            # Suppress the error when the directory already exists
            os.makedirs(self.students_extract_dir)
        except OSError as e:
            if e.errno != os.errno.EEXIST:
                print("[ERROR] " + str(e))
                exit(1)
Beispiel #2
0
def ls(*paths, glob=False):
    p = os.path.join(*paths)

    if glob:
        return globbing(p)
    else:
        return os.listdir(p)
Beispiel #3
0
 def __init__(self, config):
     """ Set the member from the config file.
     """
     try:
         self._config = config['Config']
         self.build_command = self._config['BuildCommand']
         self.executable = self._config['Executable']
         self.run_command = self._config['RunCommand']
         self.temp_output_dir = self._config['TempOutputDir']
         self.diff_command = self._config['DiffCommand']
         self.delete_temp_output = self._config['DeleteTempOutput']
         self._ans_dir = self._config['AnswerDir']
         self._ans_ext = self._config['AnswerExtension']
         self._inputs = [
             os.path.abspath(path) for path in globbing(self._config['Inputs'])]
     except KeyError as e:
         print(str(e) +
               " field was not found in config file. " +
               "Please check `judge.conf` first.")
         ERR_HANDLER.handle(exit_or_log='exit')
     try:
         # Create the temporary directory for output
         # Suppress the error when the directory already exists
         os.makedirs(self.temp_output_dir)
     except OSError as e:
         if e.errno != os.errno.EEXIST:
             ERR_HANDLER.handle(str(e))
     # tests contains corresponding input and answer path
     Test = namedtuple('Test', ('test_name', 'input_path', 'answer_path'))
     self.tests = [
         Test(get_filename(path), path,
              expand_path(self._ans_dir, get_filename(path), self._ans_ext)) for path in self._inputs]
     self.tests.sort(key=lambda t: t.test_name)
Beispiel #4
0
    def inputs_to_tests(self, inputs):
        inputs_path = [os.path.abspath(path) for path in globbing(inputs)]

        ret = [
            Test(
                get_filename(path),
                path,
                expand_path(self._ans_dir, get_filename(path), self._ans_ext),
            )
            for path in inputs_path
        ]
        ret.sort(key=lambda t: t.test_name)
        return ret