summaryrefslogtreecommitdiff
path: root/kpov_judge
diff options
context:
space:
mode:
authorgasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2016-09-29 18:45:12 +0000
committergasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2016-09-29 18:45:12 +0000
commit9c6ada33b2df7f45a1606139cc702b536fb9dc41 (patch)
treed01a72c0bc52eb0f0a93c323e5fda3362a94b949 /kpov_judge
parente355b0f3a097ed73143ad2a7f9a42db3243fa63c (diff)
updated test_task.py for the newer versions of python-dialog
git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@349 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
Diffstat (limited to 'kpov_judge')
-rwxr-xr-xkpov_judge/test_task.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/kpov_judge/test_task.py b/kpov_judge/test_task.py
index 702304c..37033d2 100755
--- a/kpov_judge/test_task.py
+++ b/kpov_judge/test_task.py
@@ -16,6 +16,9 @@ from bson.son import SON
import kpov_random_helpers
import random
import argparse
+import locale
+
+locale.setlocale(locale.LC_ALL, ['C', 'utf8'])
# SERVER_URL = "http://localhost/kpov_judge/"
#SERVER_URL = "http://kpov.fri.uni-lj.si/kpov_judge/"
@@ -49,12 +52,13 @@ def get_params_dialog(params, meta, param_name_list=None, dialog=None, language
else:
init = params[name]
ret, s = dialog.inputbox(description, init=init)
- if ret == 0:
+ # print ret, type(ret)
+ if ret == 'ok':
if m.get('w', True):
params[name] = s
elif name not in params:
params[name] = None
- got_param = (ret == 0) and name in params
+ got_param = (ret == 'ok') and name in params
return params
def add_meta_to_argparser(argparser, meta, defaults = {}):
@@ -65,7 +69,7 @@ def add_meta_to_argparser(argparser, meta, defaults = {}):
except:
desc = k
# print("{} {}".format(desc, type(desc)))
- argparser.add_argument('--'+k, nargs=1, help=desc, type=unicode, default=defaults.get(k, None))
+ argparser.add_argument('--'+k, nargs='?', help=desc, type=unicode, default=defaults.get(k, None))
return argparser
def http_auth(url, username, password):
@@ -100,20 +104,24 @@ def locate_task(params, argparser, dialog):
if 'task_url' not in params:
params['task_url'] = TASK_URL
argparser = add_meta_to_argparser(argparser, meta = url_meta, defaults = params)
- args = argparser.parse_args()
+ args, unknown_args = argparser.parse_known_args()
params['task_url'] = args.task_url
if dialog is not None:
params = get_params_dialog(params, url_meta, dialog = dialog)
# then the student's ID (and password if neccessarry)
fetch_params_meta = {
- 'username':{'descriptions': {'si': 'Uporabniško ime', 'en': 'Username'}, },
+ 'username':{'descriptions': {'si': u'Uporabniško ime', 'en': u'Username'}, },
}
- if params['task_url'] is not None and params['task_url'].startswith('http'):
+ if params['task_url'] is not None and (
+ params['task_url'].startswith('http')):
fetch_params_meta['password'] = {'descriptions': {'si': 'Geslo', 'en': 'Password'}, }
# and finally, the name of the task
fetch_params_meta['task_name'] = {'descriptions': {'si': 'Ime naloge', 'en': 'Task name'}, }
argparser = add_meta_to_argparser(argparser, meta = fetch_params_meta, defaults = params)
- args = argparser.parse_args()
+ args, unknown_args = argparser.parse_known_args()
+ # update params with the now known args
+ for k, v in fetch_params_meta.iteritems():
+ params[k] = vars(args).get(k, params.get(k, None))
if dialog is not None:
params = get_params_dialog(params, fetch_params_meta, dialog=dialog)
return argparser, params
@@ -137,14 +145,15 @@ if __name__ == '__main__':
basic_argparser.add_argument('-g', '--generate_params', action='store_true', help='Generate initial values the task parameters', default=False)
basic_argparser.add_argument('-pf','--params_file', nargs='?',
help='a local file containing saved param values', default=PARAMS_FILE)
- basic_args = basic_argparser.parse_args()
+ basic_args, unknown_args = basic_argparser.parse_known_args()
# get default parameters including language
params = load_params(basic_args.params_file)
- basic_argparser.add_argument('-l', '--language', nargs=1,
+ basic_argparser.add_argument('-l', '--language', nargs='?',
help='the language used', default=params.get('language', DEFAULT_LANGUAGE))
- basic_args = basic_argparser.parse_args()
+ basic_args, unknown_args = basic_argparser.parse_known_args()
params['language'] = basic_args.language
- if not basic_args.quiet and Dialog is not None:
+ if not basic_args.help and (
+ not basic_args.quiet and Dialog is not None):
dialog = Dialog(dialog="dialog")
else:
dialog = None
@@ -157,10 +166,12 @@ if __name__ == '__main__':
task_name = params['task_name']
if task_url.startswith('http'):
http_auth(task_url, params['username'], params['password'])
+ print "fetching {task_url}/{task_name}/task.py".format(**params)
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)
except Exception as e:
+ print params
print(e)
if basic_args.help:
argparser.print_help()