summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/edit_find_grep_compile_convert
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-07 20:21:31 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2018-10-07 20:21:31 +0200
commit80f050080ce11c6a0cce67c9b0281c09702b00d6 (patch)
treeb486e1f6342bc757dda87df4856084f652895791 /kpov_judge/tasks/edit_find_grep_compile_convert
parent43d7ef057b4ae752a60b947e523b3a56782bf5cd (diff)
parentdbf585c2a59dbcb7f6d803d5756826b562cd7f43 (diff)
Merge branch 'fix-tasks'
Fixes pexpect usage in most tasks. Several other cleanups and minor refactoring.
Diffstat (limited to 'kpov_judge/tasks/edit_find_grep_compile_convert')
-rw-r--r--kpov_judge/tasks/edit_find_grep_compile_convert/task.py77
1 files changed, 26 insertions, 51 deletions
diff --git a/kpov_judge/tasks/edit_find_grep_compile_convert/task.py b/kpov_judge/tasks/edit_find_grep_compile_convert/task.py
index 3d9aafa..7a96a0b 100644
--- a/kpov_judge/tasks/edit_find_grep_compile_convert/task.py
+++ b/kpov_judge/tasks/edit_find_grep_compile_convert/task.py
@@ -1,13 +1,9 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-#
# TODO:
# - check if everything is filled in (computers, params, preparation)
# - improve scoring
# - test
# - switch to a real SSH/SFTP client to properly handle filenames
-
instructions = {
'si':"""
Ustvari dva navidezna računalnika s slikama diskov
@@ -191,52 +187,41 @@ params_meta = {
}
def task(testip, testuser, passwd, magicstr, dstfile, progname, pubseed):
- from pexpect import pxssh
import random
- N_TITA = 40
- target = pxssh.pxssh()
- target.login(testip, testuser, passwd)
- target.sendline('ls -l ~/{}'.format(dstfile))
- target.prompt()
- dst_ls = target.before
- target.sendline('cat ~/{}'.format(dstfile))
- target.prompt()
- dst_file_contents = target.before
- target.sendline('ls ~/'.format(dstfile))
- target.prompt()
- home_ls = target.before
- results = {
- 'dst_ls': dst_ls,
- 'dst_file_contents': dst_file_contents,
- 'home_ls': home_ls,
- }
- tita_return = ""
+
r = random.Random(pubseed)
+ tests = [
+ ('dst_ls', 'ls -l ~/{}'.format(dstfile)),
+ ('dst_file_contents', 'cat ~/{}'.format(dstfile)),
+ ('home_ls', 'ls ~/'.format(dstfile)),
+ ]
+
+ N_TITA = 40
for i in range(N_TITA):
b = r.randint(0, 7)
x = oct(r.randint(37, 127)).replace('o', '')
- target.sendline('echo -e "\\{}" | ~/{} {}'.format(x, progname, b))
- target.prompt()
- tita_return += target.before
- results['tita_return'] = tita_return
- target.logout()
+ tests += [('tita-{:02}'.format(i), 'echo -e "\\{}" | ~/{} {}'.format(x, progname, b))]
+
+ results = kpov_util.ssh_test(testip, testuser, passwd, tests)
+ results['tita_return'] = ''.join(val for key, val in results.items() if key.startswith('tita-'))
+
return results
def gen_params(user_id, params_meta):
import random
params = dict()
r = random.Random(user_id)
- params['testip'] = kpov_random_helpers.IPv4_addr_gen(r,
+ params['testip'] = kpov_util.IPv4_addr_gen(r,
network = '10.94.80.0/19', n_generated=1)[0]
- params['testuser'] = kpov_random_helpers.default_generators['username'](r)
- params['passwd'] = kpov_random_helpers.alnum_gen(r, 8)
+ params['testuser'] = kpov_util.default_generators['username'](r)
+ params['passwd'] = kpov_util.alnum_gen(r, 8)
params['magicstr'] = "".join([r.choice("qwerztlpoQWERTPOL") for i in range(10)])
- params['dstfile'] = kpov_random_helpers.default_generators['filename'](r)
- params['progname'] = kpov_random_helpers.default_generators['filename'](r)
+ params['dstfile'] = kpov_util.default_generators['filename'](r)
+ params['progname'] = kpov_util.default_generators['filename'](r)
while params['dstfile'] == params['progname']:
- params['progname'] = kpov_random_helpers.default_generators['filename'](r)
- params['pubseed'] = kpov_random_helpers.alnum_gen(r, 8)
- params['rndseed'] = kpov_random_helpers.alnum_gen(r, 8)
+ params['progname'] = kpov_util.default_generators['filename'](r)
+ params['pubseed'] = kpov_util.alnum_gen(r, 8)
+ params['rndseed'] = kpov_util.alnum_gen(r, 8)
return params
@@ -258,11 +243,6 @@ def task_check(results, params):
x = start + mid + end
hidden_contents += x + "\r\n"
expected_contents = hidden_contents
- #expected_contents = re.sub(r"^po.*lz\r$",
- # r"pokakalz\r",
- # hidden_contents,
- # re.MULTILINE)
- expected_contents = "cat ~/{}\r\n".format(params['dstfile']) + expected_contents
if results["dst_file_contents"] == expected_contents:
score += 3
else:
@@ -275,7 +255,7 @@ def task_check(results, params):
break
hints += ["wrong file contents\n" + str(diff_pos[1])]
#hints += ["wrong file contents"]
- expected_ls = "ls -l ~/{dstfile}\r\n-rw--w---- 1 {testuser} bilbo .*{dstfile}.*\r\n".format(**params)
+ expected_ls = "-rw--w---- 1 {testuser} bilbo .*{dstfile}.*\r\n".format(**params)
if re.match(expected_ls, results["dst_ls"]):
score += 3
else:
@@ -290,7 +270,6 @@ def task_check(results, params):
b = r.randint(0, 7)
x_i = r.randint(37, 127)
x = oct(x_i).replace('o', '')
- expected_tita += 'echo -e "\\{}" | ~/{} {}\r\n'.format(x, params['progname'], b)
if x_i & (1 << b):
expected_tita += "ta\r\n"
else:
@@ -298,7 +277,6 @@ def task_check(results, params):
if results["tita_return"] == expected_tita:
score += 2
else:
- #hints += [u"program output incorrect\n" + results["tita_return"] + expected_tita]
hints += ["program output incorrect\n" + results["tita_return"]]
return score, hints
@@ -306,10 +284,7 @@ def task_check(results, params):
def prepare_disks(templates, task_params, global_params):
import random
import os
- #print "Haha!"
- #print params
- #print templates
- d = templates['student-entrance2']
+
# first create the file contents to make it easyer to check.
hidden_contents = task_params['magicstr']
r = random.Random(task_params['rndseed'])
@@ -318,12 +293,15 @@ def prepare_disks(templates, task_params, global_params):
x += "".join([r.choice("uiasdfghjkyxcvbnm1234567890ASDFGHJKYZXCVBNM") for i in range(60)])
x += r.choice(["lz", "1z", "Iz", "iz", "l2", "I2", "12"])
hidden_contents += x + "\n"
+
# create hidden file
dir_list = ['Qlipper', 'Thunar', 'blender', 'autostart', 'kazam', 'mc', 'netsurf', 'pulse', 'qupzilla', 'radare2', 'teamviewer', 'texstudio', 'vlc']
ending_list = ['rc', '.conf', '']
start_list = ['net', 'dev', 'doc', 'lib', 'time', 'conf']
r.shuffle(dir_list)
file_letters = ["mod", "co"]
+
+ d = templates['student-entrance2']
for potential_dir in dir_list:
try:
potential_dir = os.path.join('/home/bilbo/.config', potential_dir)
@@ -344,6 +322,3 @@ def prepare_disks(templates, task_params, global_params):
# TODO create some additional files
write_default_config(templates['simpleArbiterDhcpGW'], global_params)
- # finish here
- # rename
-