diff options
author | ankitjavalkar | 2016-03-22 12:02:47 +0530 |
---|---|---|
committer | ankitjavalkar | 2016-05-05 19:00:33 +0530 |
commit | 597c23866be3ecfdf94c40693b060fe9ebbf6446 (patch) | |
tree | bebb0c8e7aed24fb16e07070f7648305acfad755 /yaksh/code_evaluator.py | |
parent | 0520bf284f9b34782fa90b433d714c887049f339 (diff) | |
download | online_test-597c23866be3ecfdf94c40693b060fe9ebbf6446.tar.gz online_test-597c23866be3ecfdf94c40693b060fe9ebbf6446.tar.bz2 online_test-597c23866be3ecfdf94c40693b060fe9ebbf6446.zip |
Refactor C/CPP code evaluator and add test cases
Diffstat (limited to 'yaksh/code_evaluator.py')
-rw-r--r-- | yaksh/code_evaluator.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/yaksh/code_evaluator.py b/yaksh/code_evaluator.py index 535daa3..b777b67 100644 --- a/yaksh/code_evaluator.py +++ b/yaksh/code_evaluator.py @@ -3,7 +3,7 @@ from SimpleXMLRPCServer import SimpleXMLRPCServer import pwd import os import stat -from os.path import isdir, dirname, abspath, join, isfile +from os.path import isdir, dirname, abspath, join, isfile, exists import signal from multiprocessing import Process, Queue import subprocess @@ -144,15 +144,31 @@ class CodeEvaluator(object): def check_code(self): raise NotImplementedError("check_code method not implemented") + # def create_submit_code_file(self, file_name): + # """ Write the code (`answer`) to a file and set the file path""" + # submit_f = open(file_name, 'w') + # submit_f.write(self.user_answer.lstrip()) + # submit_f.close() + # submit_path = abspath(submit_f.name) + + # return submit_path + def create_submit_code_file(self, file_name): - """ Write the code (`answer`) to a file and set the file path""" - submit_f = open(file_name, 'w') - submit_f.write(self.user_answer.lstrip()) - submit_f.close() - submit_path = abspath(submit_f.name) + """ Set the file path for code (`answer`)""" + submit_path = abspath(file_name) + if not exists(submit_path): + submit_f = open(submit_path, 'w') + submit_f.close() return submit_path + + def write_to_submit_code_file(self, file_path, user_answer): + """ Write the code (`answer`) to a file""" + submit_f = open(file_path, 'w') + submit_f.write(user_answer.lstrip()) + submit_f.close() + def _set_file_as_executable(self, fname): os.chmod(fname, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP |