From fd97b0391b7364927061487604b187541dab6510 Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 20 Jun 2016 14:55:08 +0530 Subject: changed evaluators to support file based questions --- yaksh/java_code_evaluator.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'yaksh/java_code_evaluator.py') diff --git a/yaksh/java_code_evaluator.py b/yaksh/java_code_evaluator.py index c64aa3b..dde2ec2 100644 --- a/yaksh/java_code_evaluator.py +++ b/yaksh/java_code_evaluator.py @@ -8,6 +8,7 @@ import importlib # local imports from code_evaluator import CodeEvaluator +from copy_delete_files import CopyDeleteFiles class JavaCodeEvaluator(CodeEvaluator): @@ -21,7 +22,14 @@ class JavaCodeEvaluator(CodeEvaluator): def teardown(self): super(JavaCodeEvaluator, self).teardown() # Delete the created file. - os.remove(self.submit_code_path) + os.remove(self.submit_code_path) + if os.path.exists(self.user_output_path): + os.remove(self.user_output_path) + if os.path.exists(self.ref_output_path): + os.remove(self.ref_output_path) + if self.files_list: + file_delete = CopyDeleteFiles() + file_delete.delete_files(self.files_list) def get_commands(self, clean_ref_code_path, user_code_directory): compile_command = 'javac {0}'.format(self.submit_code_path), @@ -35,14 +43,17 @@ class JavaCodeEvaluator(CodeEvaluator): output_path = "{0}{1}.class".format(directory, file_name) return output_path - def compile_code(self, user_answer, test_case): + def compile_code(self, user_answer, file_paths, test_case): + self.files_list = [] if self.compiled_user_answer and self.compiled_test_code: return None else: ref_code_path = test_case clean_ref_code_path, clean_test_case_path = \ self._set_test_code_file_path(ref_code_path) - + if file_paths: + file_copy = CopyDeleteFiles() + self.files_list = file_copy.copy_files(file_paths) if not isfile(clean_ref_code_path): msg = "No file at %s or Incorrect path" % clean_ref_code_path return False, msg @@ -83,7 +94,7 @@ class JavaCodeEvaluator(CodeEvaluator): return self.compiled_user_answer, self.compiled_test_code - def check_code(self, user_answer, test_case): + def check_code(self, user_answer, file_paths, test_case): """ Function validates student code using instructor code as reference.The first argument ref_code_path, is the path to instructor code, it is assumed to have executable permission. @@ -123,7 +134,6 @@ class JavaCodeEvaluator(CodeEvaluator): success, err = True, "Correct answer" else: err = stdout + "\n" + stderr - os.remove(self.ref_output_path) else: err = "Error:" try: @@ -135,7 +145,6 @@ class JavaCodeEvaluator(CodeEvaluator): err = err + "\n" + e except: err = err + "\n" + main_err - os.remove(self.user_output_path) else: err = "Compilation Error:" try: @@ -147,5 +156,4 @@ class JavaCodeEvaluator(CodeEvaluator): err = err + "\n" + e except: err = err + "\n" + stdnt_stderr - return success, err -- cgit From df9a893b91b4adb39f01b88f6b6d96359db37f47 Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 11 Jul 2016 16:37:50 +0530 Subject: changed file module name in evaluators --- yaksh/java_code_evaluator.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'yaksh/java_code_evaluator.py') diff --git a/yaksh/java_code_evaluator.py b/yaksh/java_code_evaluator.py index dde2ec2..ff76317 100644 --- a/yaksh/java_code_evaluator.py +++ b/yaksh/java_code_evaluator.py @@ -8,7 +8,7 @@ import importlib # local imports from code_evaluator import CodeEvaluator -from copy_delete_files import CopyDeleteFiles +from file_utils import copy_files, delete_files class JavaCodeEvaluator(CodeEvaluator): @@ -27,9 +27,8 @@ class JavaCodeEvaluator(CodeEvaluator): os.remove(self.user_output_path) if os.path.exists(self.ref_output_path): os.remove(self.ref_output_path) - if self.files_list: - file_delete = CopyDeleteFiles() - file_delete.delete_files(self.files_list) + if self.files: + delete_files(self.files) def get_commands(self, clean_ref_code_path, user_code_directory): compile_command = 'javac {0}'.format(self.submit_code_path), @@ -44,7 +43,7 @@ class JavaCodeEvaluator(CodeEvaluator): return output_path def compile_code(self, user_answer, file_paths, test_case): - self.files_list = [] + self.files = [] if self.compiled_user_answer and self.compiled_test_code: return None else: @@ -52,8 +51,7 @@ class JavaCodeEvaluator(CodeEvaluator): clean_ref_code_path, clean_test_case_path = \ self._set_test_code_file_path(ref_code_path) if file_paths: - file_copy = CopyDeleteFiles() - self.files_list = file_copy.copy_files(file_paths) + self.files = copy_files(file_paths) if not isfile(clean_ref_code_path): msg = "No file at %s or Incorrect path" % clean_ref_code_path return False, msg -- cgit