diff options
-rwxr-xr-x | code_server.py | 5 | ||||
-rw-r--r-- | exam/views.py | 15 | ||||
-rw-r--r-- | test_server.py | 8 |
3 files changed, 20 insertions, 8 deletions
diff --git a/code_server.py b/code_server.py index 4d1663d..1276c76 100755 --- a/code_server.py +++ b/code_server.py @@ -166,11 +166,14 @@ class CodeServer(object): signal.alarm(SERVER_TIMEOUT) # Do whatever testing needed. + success = False try: success, err = self.check_bash_script(ref_path, submit_path, test_case_path) except TimeoutException: - success = False err = self.timeout_msg + except: + type, value = sys.exc_info()[:2] + err = "Error: {0}".format(repr(value)) finally: # Set back any original signal handler. signal.signal(signal.SIGALRM, old_handler) diff --git a/exam/views.py b/exam/views.py index e8e2e73..61179de 100644 --- a/exam/views.py +++ b/exam/views.py @@ -42,7 +42,14 @@ def gen_key(no_of_chars): def get_user_dir(user): """Return the output directory for the user.""" - return join(OUTPUT_DIR, str(user.username)) + user_dir = join(OUTPUT_DIR, str(user.username)) + if not exists(user_dir): + os.mkdir(user_dir) + # Make it rwx by others. + os.chmod(user_dir, stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH \ + | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR \ + | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP) + return user_dir def index(request): """The start page. @@ -133,12 +140,6 @@ def start(request): # Make user directory. user_dir = get_user_dir(user) - if not exists(user_dir): - os.mkdir(user_dir) - # Make it rwx by others. - os.chmod(user_dir, stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH \ - | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR \ - | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP) questions = [ str(_.id) for _ in Question.objects.filter(active=True) ] random.shuffle(questions) diff --git a/test_server.py b/test_server.py index 45401fd..be9f876 100644 --- a/test_server.py +++ b/test_server.py @@ -69,6 +69,14 @@ def test_bash(): 'docs/sample.sh\ndocs/sample.args', '/tmp', language="bash") check_result(result, 'error') + src = '''# Enter your code here. +#!/bin/bash + while [ 1 ] ; do echo "" > /dev/null + ''' + result = code_server.run_code(src, + 'docs/sample.sh\ndocs/sample.args', '/tmp', language="bash") + check_result(result, 'oserror') + if __name__ == '__main__': test_python() test_bash() |