summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xkpov_judge/add_task.py25
-rwxr-xr-xkpov_judge/run_test.py109
-rw-r--r--kpov_judge/tasks/set_motd/task.py2
-rwxr-xr-xkpov_judge/test_task.py8
-rwxr-xr-xkpov_judge/web/kpov_judge/kpov_judge.py5
5 files changed, 31 insertions, 118 deletions
diff --git a/kpov_judge/add_task.py b/kpov_judge/add_task.py
index 2453eeb..ec65fd0 100755
--- a/kpov_judge/add_task.py
+++ b/kpov_judge/add_task.py
@@ -10,6 +10,23 @@ import settings
import guestfs
import glob
+def uploading_task_check(results, params):
+ data = urllib.urlencode({
+ 'results': json.dumps(results),
+ 'params': json.dumps(params)
+ })
+ req = urllib2.Request('{task_url}/{task_name}/results.json'.format(task_url=task_url, task_name=task_name), data)
+ response = urllib2.urlopen(req)
+ return response.read()
+
+uploading_task_check_source = inspect.get_source(uploading_task_check)
+
+def dummy_gen_params(user_id, meta):
+ return dict()
+
+dummy_gen_params_source = inspect.get_source(dummy_gen_params)
+
+
if __name__ == '__main__':
if len(sys.argv) != 3:
print "Usage: {0} task_name task_source.py"
@@ -27,7 +44,13 @@ if __name__ == '__main__':
# the following line creates:
# task, task_check, gen_params, prepare_disks, computers, params_meta.
exec(code)
- task_source = inspect.getsource(task)
+ public_meta = dict()
+ for k, v in params_meta:
+ if v.get('public', False):
+ public_meta[k] = v
+ task_source = inspect.getsource(task) + "\n\n" +
+ uploading_task_check_source + "\n\n" +
+ "params_meta = " + str(public_meta) + "\n\n" + dummy_gen_params_source
task_check_source = inspect.getsource(task_check)
gen_params_source = inspect.getsource(gen_params)
prepare_disks_source = inspect.getsource(prepare_disks)
diff --git a/kpov_judge/run_test.py b/kpov_judge/run_test.py
deleted file mode 100755
index 7962a07..0000000
--- a/kpov_judge/run_test.py
+++ /dev/null
@@ -1,109 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-import yaml
-import json
-import urllib
-import urllib2
-import dialog
-import os
-import inspect
-import sys
-
-# SERVER_URL = "http://localhost/kpov_judge/"
-SERVER_URL = "http://kpov.fri.uni-lj.si/kpov_judge/"
-TASK_URL = SERVER_URL + '{task_id}/task.py'
-PARAMS_URL = SERVER_URL + '{task_id}/params.json'
-SUBMIT_URL = SERVER_URL + '{task_id}/results.json'
-
-PARAMS_FILE = os.path.expanduser("~/.kpov_params.yaml")
-
-def get_params(params, param_names, meta, d):
- for name in param_names:
- m = meta.get(name, {})
- if d is not None:
- ret, s = d.inputbox(m.get('opis', name), init=params.get(name, ''))
- if ret == 0 and m.get('w', False):
- params[name] = s
- else:
- if name not in params:
- raise "Missing param: {0}".format(name)
- return params
-
-def auth_open(url, username, password):
- password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
-# Add the username and password.
-# If we knew the realm, we could use it instead of None.
- password_mgr.add_password(None, SERVER_URL, username, password)
- handler = urllib2.HTTPBasicAuthHandler(password_mgr)
-# create "opener" (OpenerDirector instance)
- opener = urllib2.build_opener(handler)
-# use the opener to fetch a URL
-# opener.open(SERVER_URL)
-# Install the opener.
-# Now all calls to urllib2.urlopen use our opener.
- urllib2.install_opener(opener)
-
-def load_checker(response):
- source = response.read()
- t = compile(source, 'task.py', 'exec')
- exec(t)
- args_list = inspect.getargs(task.func_code)[0]
- return task, None, args_list, param_meta
-
-if __name__ == '__main__':
- try:
- try:
- saved_params = yaml.load(open(PARAMS_FILE))
- except:
- print "Missing - creating anew.", PARAMS_FILE
- saved_params = dict()
- if len(sys.argv) > 1 and sys.argv[1] == '-q':
- d = None
- else:
- d = dialog.Dialog(dialog="dialog")
- basic_params = {
- # 'param_name': ('prompt', editable)
- "student_id": {'opis':"Upor. ime:", 'w': True},
- "student_password": {'opis':"Geslo:", 'w': True},
- "task_id": {'opis': "Naloga:", 'w': True}}
- saved_params = get_params(saved_params, ['student_id', 'student_password', 'task_id'], basic_params, d)
- task_id = saved_params['task_id']
- yaml.dump(saved_params, open(PARAMS_FILE, 'w'))
- auth_open(SERVER_URL, saved_params['student_id'], saved_params['student_password'])
- # get parameters
- req = urllib2.Request(PARAMS_URL.format(**saved_params))
- response = urllib2.urlopen(req)
- web_params = json.load(response)
- task_params_dict = saved_params.get('tasks', {})
- task_params = task_params_dict.get(task_id, {})
- saved_params['tasks'] = task_params_dict
- task_params.update(web_params)
- # get task source
- req = urllib2.Request(TASK_URL.format(**saved_params))
- response = urllib2.urlopen(req)
- # load task_check over the net
- task, task_check, args_list, meta = load_checker(response)
- # get missing parameters from user
- task_params = get_params(task_params, args_list, meta, d)
- # save
- # run checker
- valid_task_params = dict()
- for i in args_list:
- valid_task_params[i] = task_params[i]
- saved_params['tasks'][task_id] = valid_task_params
- results = task(**valid_task_params)
- data = urllib.urlencode({
- 'results': json.dumps(results),
- 'params': json.dumps(valid_task_params)
- })
- req = urllib2.Request(SUBMIT_URL.format(**saved_params), data)
- response = urllib2.urlopen(req)
- if d is not None:
- d.msgbox(response.read())
- yaml.dump(saved_params, open(PARAMS_FILE, 'w'))
- # d.add_persistent_args([('background_title', 'KPOVv')])
- except Exception, e:
- yaml.dump(saved_params, open(PARAMS_FILE, 'w'))
- print "problem!"
- print e
diff --git a/kpov_judge/tasks/set_motd/task.py b/kpov_judge/tasks/set_motd/task.py
index 696407c..8213ecd 100644
--- a/kpov_judge/tasks/set_motd/task.py
+++ b/kpov_judge/tasks/set_motd/task.py
@@ -60,6 +60,7 @@ def task(peer_ip, peer_user, peer_passwd, niz):
"Check whether ssh works"
import pxssh
import pexpect
+ return {"hello": 'kitty'}
results = dict()
s = pxssh.pxssh()
s.login (peer_ip, peer_user, peer_passwd, original_prompt=r'{0}@.*:\~\$'.format(peer_user),auto_prompt_reset=False)
@@ -72,6 +73,7 @@ def gen_params(user_id, params_meta):
return kpov_random_helpers.default_gen(user_id, params_meta)
def task_check(results, params):
+ print task_url
niz = params['niz']
niz=niz.replace("#","")
score = 0
diff --git a/kpov_judge/test_task.py b/kpov_judge/test_task.py
index c6f6014..0d12629 100755
--- a/kpov_judge/test_task.py
+++ b/kpov_judge/test_task.py
@@ -149,8 +149,10 @@ if __name__ == '__main__':
# TODO: if the task name is missing or invalid, try to get a list of tasks
# get task source and generate params if neccessarry
try:
- if params['task_url'].startswith('http'):
- http_auth(params['task_url'], params['username'], params['password'])
+ task_url = params['task_url']
+ task_name = params['task_name']
+ if task_url.startswith('http'):
+ http_auth(task_url, params['username'], params['password'])
req = urllib2.Request("{task_url}/{task_name}/task.py".format(**params))
source = urllib2.urlopen(req)
task, task_check, task_params_meta, gen_params = load_task(source)
@@ -169,7 +171,7 @@ if __name__ == '__main__':
task_params = params['task_params'][params['task_name']]
if basic_args.generate_params:
task_params.update(gen_params(params['username'], task_params_meta))
- if params['task_url'].startswith('http'):
+ if task_url.startswith('http'):
req = urllib2.Request("{task_url}/{task_name}/params.json".format(**params))
web_task_params = json.load(urllib2.urlopen(req))
task_params.update(web_task_params)
diff --git a/kpov_judge/web/kpov_judge/kpov_judge.py b/kpov_judge/web/kpov_judge/kpov_judge.py
index a2b1f5c..627ff06 100755
--- a/kpov_judge/web/kpov_judge/kpov_judge.py
+++ b/kpov_judge/web/kpov_judge/kpov_judge.py
@@ -14,11 +14,6 @@ app.config.from_object(settings)
dummy_task = """
def task(neznano_ime_naloge):
- \"""Preveri delovanje klienta.
-
- Keyword arguments:
- nesmiselen_parameter -- Poljuben parameter
- \"""
print "Ta naloga ne obstaja!"
return {'odgovor': 'neznana naloga'}
"""