summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrabhu Ramachandran2011-11-19 15:52:04 +0530
committerPrabhu Ramachandran2011-11-19 15:52:04 +0530
commitdb74ad784752eea326982c4e84faf9ec3768e006 (patch)
treeca87cc096936b57fceeb80794d7a5ac5d555c850
parent759d1da9a8e8221f999550042fbcb96ac5083607 (diff)
downloadonline_test-db74ad784752eea326982c4e84faf9ec3768e006.tar.gz
online_test-db74ad784752eea326982c4e84faf9ec3768e006.tar.bz2
online_test-db74ad784752eea326982c4e84faf9ec3768e006.zip
Configure server port and timeout in settings.py
Also updated documentation.
-rw-r--r--README.txt14
-rw-r--r--exam/xmlrpc_clients.py4
-rwxr-xr-xpython_server.py11
-rw-r--r--settings.py6
4 files changed, 23 insertions, 12 deletions
diff --git a/README.txt b/README.txt
index 5b576fc..f86e1fd 100644
--- a/README.txt
+++ b/README.txt
@@ -13,7 +13,7 @@ To install/deploy this app follow the steps below:
3. Add questions by editing the sample_questions.xml or any other xml
file in the same format and then run the following::
- $ python manage.py load_questions sample_questions.xml
+ $ python manage.py load_questions_xml sample_questions.xml
Note that you can supply multiple xml files as arguments and all of
those will be added to the database.
@@ -23,16 +23,22 @@ To install/deploy this app follow the steps below:
$ sudo python python_server.py
- Using sudo is necessary since the server is run as the user "nobody".
+ Using sudo is necessary since the server is run as the user "nobody". This
+ runs on port 8001 by default and may be changed in the settings in the
+ variable SERVER_PORT. The SERVER_TIMEOUT also can be changed there. This
+ is the maximum time allowed to execute the submitted code.
5. Now, run::
$ python manage.py runserver <desired_ip>:<desired_port>
+
+ For deployment use Apache or a real webserver, see below for more
+ information.
- 6. Go to http://server_ip:server_port/admin
+ 6. Go to http://deserved_host_or_ip:desired_port/admin
7. Login with your credentials and look at the questions and modify if
- needed.
+ needed. Create a new Quiz, set the date and duration.
8. Now ask users to login at:
http://server_ip:server_port/exam
diff --git a/exam/xmlrpc_clients.py b/exam/xmlrpc_clients.py
index 1bc5513..be2f8b1 100644
--- a/exam/xmlrpc_clients.py
+++ b/exam/xmlrpc_clients.py
@@ -1,5 +1,5 @@
from xmlrpclib import ServerProxy
+from ..settings import SERVER_PORT
# Connect to the python server.
-python_server = ServerProxy('http://localhost:8001')
- \ No newline at end of file
+python_server = ServerProxy('http://localhost:%d'%(SERVER_PORT))
diff --git a/python_server.py b/python_server.py
index dee5631..20d7440 100755
--- a/python_server.py
+++ b/python_server.py
@@ -10,9 +10,8 @@ import pwd
import os
from os.path import isdir
import signal
+from settings import SERVER_PORT, SERVER_TIMEOUT
-# Timeout for the code to run in seconds.
-TIMEOUT = 2
def run_as_nobody():
# Set the effective uid
@@ -34,7 +33,7 @@ def run_code(answer, test_code, in_dir=None):
If the optional `in_dir` keyword argument is supplied it changes the
directory to that directory (it does not change it back to the original when
done). This function also timesout when the function takes more than
- TIMEOUT seconds to run to prevent runaway code.
+ SERVER_TIMEOUT seconds to run to prevent runaway code.
Returns
-------
@@ -47,7 +46,7 @@ def run_code(answer, test_code, in_dir=None):
# Add a new signal handler for the execution of this code.
old_handler = signal.signal(signal.SIGALRM, timeout_handler)
- signal.alarm(TIMEOUT)
+ signal.alarm(SERVER_TIMEOUT)
success = False
tb = None
@@ -58,7 +57,7 @@ def run_code(answer, test_code, in_dir=None):
_tests = compile(test_code, '<string>', mode='exec')
exec _tests in g
except TimeoutException:
- err = 'Code took more than %s seconds to run.'%TIMEOUT
+ err = 'Code took more than %s seconds to run.'%SERVER_TIMEOUT
except AssertionError:
type, value, tb = sys.exc_info()
info = traceback.extract_tb(tb)
@@ -84,7 +83,7 @@ def run_code(answer, test_code, in_dir=None):
def main():
run_as_nobody()
- server = SimpleXMLRPCServer(("localhost", 8001))
+ server = SimpleXMLRPCServer(("localhost", SERVER_PORT))
server.register_function(run_code)
server.serve_forever()
diff --git a/settings.py b/settings.py
index f540c1b..11a44a2 100644
--- a/settings.py
+++ b/settings.py
@@ -5,6 +5,12 @@ from os.path import dirname, join, basename, abspath
DEBUG = True
TEMPLATE_DEBUG = DEBUG
+# The port the Python server should run on.
+SERVER_PORT = 8001
+
+# Timeout for the code to run in seconds.
+SERVER_TIMEOUT = 2.0
+
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)