diff options
-rwxr-xr-x | kpov_judge/add_task.py | 27 | ||||
-rwxr-xr-x | kpov_judge/create_disk_images.py | 6 | ||||
-rwxr-xr-x | kpov_judge/test_prepare_disks.py | 5 | ||||
-rwxr-xr-x | kpov_judge/test_task.py | 5 | ||||
-rwxr-xr-x | kpov_judge/web/kpov_judge/kpov_judge.py | 13 |
5 files changed, 30 insertions, 26 deletions
diff --git a/kpov_judge/add_task.py b/kpov_judge/add_task.py index ce6713b..4fa250f 100755 --- a/kpov_judge/add_task.py +++ b/kpov_judge/add_task.py @@ -50,27 +50,28 @@ if __name__ == '__main__': except Exception as e: print("Not authenticated:"+str(e)) #no auth or auth config? + source = open(fname).read() - code = compile(source, fname, 'exec') - # the following line creates: - # task, task_check, gen_params, prepare_disks, computers, params_meta. - exec(code) - public_meta = dict() - for k, v in params_meta.items(): + d = {} + # defines task, task_check, gen_params, prepare_disks, computers, params_meta + exec(compile(source, fname, 'exec'), d) + + public_meta = {} + for k, v in d['params_meta'].items(): if v.get('public', False): public_meta[k] = v task_source = "\n\n".join([ - inspect.getsource(task), + inspect.getsource(d['task']), uploading_task_check_source, "params_meta = {}".format(public_meta), 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) - x = list(params_meta.keys()) # check for existence + task_check_source = inspect.getsource(d['task_check']) + gen_params_source = inspect.getsource(d['gen_params']) + prepare_disks_source = inspect.getsource(d['prepare_disks']) + x = list(d['params_meta'].keys()) # check for existence db.computers_meta.remove({'task_id': task_id, 'class_id': class_id}) auto_networks = set([None]) - for k, v in computers.items(): + for k, v in d['computers'].items(): for n in v.get('networks_interfaces', []): auto_networks.add(n.get('network', None)) db.computers_meta.update({ @@ -98,7 +99,7 @@ if __name__ == '__main__': db.gen_params.update({'task_id': task_id, 'class_id': class_id}, {'$set': {'source': gen_params_source}}, upsert=True) db.task_params_meta.update({'task_id': task_id, 'class_id': class_id}, - {'$set': {'params': params_meta}}, upsert=True) + {'$set': {'params': d['params_meta']}}, upsert=True) #instructions = dict([(k, v.encode('utf8')) for k, v in instructions.iteritems()]) #print instructions db.task_instructions.update({'task_id': task_id, 'class_id': class_id}, diff --git a/kpov_judge/create_disk_images.py b/kpov_judge/create_disk_images.py index b3ea93d..b538775 100755 --- a/kpov_judge/create_disk_images.py +++ b/kpov_judge/create_disk_images.py @@ -15,9 +15,9 @@ from util import write_default_config def get_prepare_disks(db, class_id, task_id): prepare_disks_source = db.prepare_disks.find_one({'class_id': class_id, 'task_id':task_id})['source'] - prepare_disks_code = compile(prepare_disks_source, 'prepare_disks.py', 'exec') - exec(prepare_disks_code) - return prepare_disks + d = {} + exec(compile(prepare_disks_source, 'prepare_disks.py', 'exec'), d) + return d['prepare_disks'] def create_snapshot(class_id, task_id, student_id, disk_name, overwrite = True, cow = False): print(os.path.join(settings.DISK_TEMPLATE_PATH, disk_name) + '.*') diff --git a/kpov_judge/test_prepare_disks.py b/kpov_judge/test_prepare_disks.py index 21844a0..bc4bae5 100755 --- a/kpov_judge/test_prepare_disks.py +++ b/kpov_judge/test_prepare_disks.py @@ -158,8 +158,9 @@ if __name__ == '__main__': http_auth(task_url, params['username'], params['password']) req = urllib.request.Request("{task_url}/{task_name}/task.py".format(**params)) source = urllib.request.urlopen(req).read() - t = compile(source, 'task.py', 'exec') - exec(t) + d = {} + exec(compile(source, 'task.py', 'exec'), d) + computers, prepare_disks = d['computers'], d['prepare_disks'] except Exception as e: print(e) exit(1) diff --git a/kpov_judge/test_task.py b/kpov_judge/test_task.py index 4251b50..f01d43d 100755 --- a/kpov_judge/test_task.py +++ b/kpov_judge/test_task.py @@ -91,10 +91,11 @@ def load_task(stream): # task(...) and a dictionary "params_meta". source = stream.read() t = compile(source, 'task.py', 'exec') - exec(t) + d = {} + exec(t, d) # get a list of arguments for task(...) # args_list = inspect.getargs(task.func_code)[0] - return task, task_check, params_meta, gen_params + return d['task'], d['task_check'], d['params_meta'], d['gen_params'] def locate_task(params, argparser, dialog): # first the URL where all tasks are stored diff --git a/kpov_judge/web/kpov_judge/kpov_judge.py b/kpov_judge/web/kpov_judge/kpov_judge.py index 1605089..5d3e791 100755 --- a/kpov_judge/web/kpov_judge/kpov_judge.py +++ b/kpov_judge/web/kpov_judge/kpov_judge.py @@ -90,10 +90,10 @@ def results_post(class_id, task_id, results): params[param_name] = user_params[param_name] try: task_check_source = db.task_checkers.find_one({'class_id': class_id, 'task_id': task_id})['source'] - task_check_code = compile(task_check_source, 'checker.py', 'exec') - exec(task_check_code) + d = {} + exec(compile(task_check_source, 'checker.py', 'exec'), d) # raise Exception(str(params)) - res, hints = task_check(results, params) + res, hints = d['task_check'](results, params) except Exception as e: hints = ["Checker died: " + str(e)] res = 0 @@ -187,11 +187,12 @@ def get_params(class_id, task_id, student_id, db): try: gen_params_source = db.gen_params.find_one({'class_id': class_id, 'task_id': task_id})['source'] gen_params_code = compile(gen_params_source, 'generator.py', 'exec') - exec(gen_params_code) - params = gen_params(student_id, meta) + d = {} + exec(gen_params_code, d) + params = d['gen_params'](student_id, meta) db.task_params.update({'class_id': class_id, 'task_id': task_id, 'student_id': student_id}, {'$set': {'params': params}}, upsert=True) - params = gen_params(student_id, meta) + params = d['gen_params'](student_id, meta) # TODO this is repeated, is it necessary? for computer in db.computers_meta.find({'class_id': class_id, 'task_id': task_id}): try: name = computer.pop('name') |