summaryrefslogtreecommitdiff
path: root/kpov_judge/tasks/edit_find_grep_compile_convert
diff options
context:
space:
mode:
authorgasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2017-03-23 07:40:07 +0000
committergasperfele@fri1.uni-lj.si <gasperfele@fri1.uni-lj.si@5cf9fbd1-b2bc-434c-b4b7-e852f4f63414>2017-03-23 07:40:07 +0000
commitb1b0d75831b3d81c41549358dde122b9fba0c054 (patch)
tree3739ed871351b062c55e116c92fed72f3197aed9 /kpov_judge/tasks/edit_find_grep_compile_convert
parent34384f9ea87355fada45d74b3637b9405c75dea8 (diff)
the edit_find_grep_compile_convert task now works
git-svn-id: https://svn.lusy.fri.uni-lj.si/kpov-public-svn/kpov-public@407 5cf9fbd1-b2bc-434c-b4b7-e852f4f63414
Diffstat (limited to 'kpov_judge/tasks/edit_find_grep_compile_convert')
-rw-r--r--kpov_judge/tasks/edit_find_grep_compile_convert/task.py99
1 files changed, 67 insertions, 32 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 60353fd..705ddf6 100644
--- a/kpov_judge/tasks/edit_find_grep_compile_convert/task.py
+++ b/kpov_judge/tasks/edit_find_grep_compile_convert/task.py
@@ -28,8 +28,9 @@ Brati naj jo ima pravico samo lastnik, pisati lastnik in skupina, poganjati nih
V {dstfile} zamenjaj vse vrstice oblike poXYZlz, kjer so XYZ poljubni znaki, tako, da bo namesto XYZ niz "kaka".
Napiši program v poljubnem programskem jeziku, ki kot argument sprejme število B med 0 in 7.
-Program naj prebere znak s standardnega izhoda in izpiše vrstico z nizom "ta",
-če je B-ti bit v znaku nastavljen na 1, in "ti" sicer.
+Program naj prebere znak s standardnega izhoda.
+Če je B-ti bit v znaku nastavljen na 1, naj izpiše "ta".
+Če je B-ti bit nastavljen na 0, naj program izpiše "ti".
Program poimenuj {progname} in ga spravi v domači imenik {testuser}.
""",
'en': u'''
@@ -71,12 +72,14 @@ computers = {
'network_interfaces': [
{
'network': 'net1',
+ },
+ {
'network': 'net2',
},
],
'flavor': 'm1.tiny',
'config_drive': False,
- }
+ },
'SmallStudent': {
'disks': [
{
@@ -190,20 +193,31 @@ params_meta = {
def task(testip, testuser, passwd, magicstr, dstfile, progname, pubseed):
from pexpect import pxssh
import random
- # ideally, this would be done using a SFTP client instead of pxssh
+ 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': target.run('ls -l ~/{}'.format(dstfile))
- 'dst_file_contents': target.run('cat ~/{}'.format(dstfile))
- 'home_ls': target.run('ls ~/')
+ 'dst_ls': dst_ls,
+ 'dst_file_contents': dst_file_contents,
+ 'home_ls': home_ls,
}
tita_return = ""
r = random.Random(pubseed)
- for i in range(10):
+ for i in range(N_TITA):
b = r.randint(0, 7)
x = oct(r.randint(37, 127)).replace('o', '')
- tita_return += target.run('echo -e "\0{}" | ~/{} {}'.format(x, progname, b))
+ target.sendline('echo -e "\\{}" | ~/{} {}'.format(x, progname, b))
+ target.prompt()
+ tita_return += target.before
results['tita_return'] = tita_return
target.logout()
return results
@@ -221,49 +235,70 @@ def gen_params(user_id, params_meta):
params['progname'] = kpov_random_helpers.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(8)
- params['rndseed'] = kpov_random_helpers.alnum_gen(8)
+ params['pubseed'] = kpov_random_helpers.alnum_gen(r, 8)
+ params['rndseed'] = kpov_random_helpers.alnum_gen(r, 8)
return params
def task_check(results, params):
import os
import re
+ N_TITA = 40
hints = []
score = 0
hidden_contents = params['magicstr']
r = random.Random(params['rndseed'])
for i in range(1000):
- x = "".join([r.choice(["po", "p0", "no", "ko", "fo", "qo"]) for i in range(20)])
- x += "".join([r.choice("uiasdfghjkyxcvbnm1234567890ASDFGHJKYZXCVBNM") for i in range(60)])
- x += r.choice(["lz", "1z", "Iz", "iz", "l2", "I2", "12"])
- hidden_contents += x + "\n\r"
- expected_contents = re.sub("\n\rpo.*lz\n",
- "\n\rpokakalz\n",
- hidden_contents,
- re.MULTILINE)
- expected_contents = re.sub("\n\rpo.*lz$",
- "\n\rpokakalz",
- expected_contents,
- re.MULTILINE)
+ start = "".join([r.choice(["po", "p0", "no", "ko", "fo", "qo"]) for i in range(20)])
+ mid = "".join([r.choice("uiasdfghjkyxcvbnm1234567890ASDFGHJKYZXCVBNM") for i in range(60)])
+ end = r.choice(["lz", "1z", "Iz", "iz", "l2", "I2", "12"])
+ if start[:2] == "po" and end == "lz":
+ start = "po"
+ mid = "kaka"
+ 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:
+ #diff_pos = None
+ #for i, c in enumerate(results["dst_file_contents"]):
+ # if len(expected_contents) < i or c != expected_contents[i]:
+ # start = max(0, i-20)
+ # end = min(len(expected_contents), len(results["dst_file_contents"]), i+200)
+ # diff_pos = (i, expected_contents[start:end], results["dst_file_contents"][start:end])
+ # break
+ #hints += ["wrong file contents\n" + str(diff_pos)]
hints += ["wrong file contents"]
- expected_ls = "-rw--w---- 1 {testuser} bilbo .* {dstfile}".format(**params)
- if re.match(expected_ls, results["dstfile_ls"]):
+ expected_ls = u"ls -l ~/{dstfile}\r\n-rw--w---- 1 {testuser} bilbo .*{dstfile}\r\n".format(**params)
+ if re.match(expected_ls, results["dst_ls"]):
score += 3
else:
- hints += ["missing file or wrong user/permissions"]
+ hints += ["missing file or wrong user/permissions\n" + str((results["dst_ls"], expected_ls))]
if results["home_ls"].find(params['progname']) > -1:
score += 2
else:
hints += ["missing program"]
- expected_tita = ""
+ expected_tita = u""
+ r = random.Random(params['pubseed'])
+ for i in range(N_TITA):
+ b = r.randint(0, 7)
+ x_i = r.randint(37, 127)
+ x = oct(x_i).replace('o', '')
+ expected_tita += u'echo -e "\\{}" | ~/{} {}\r\n'.format(x, params['progname'], b)
+ if x_i & (1 << b):
+ expected_tita += u"ta\r\n"
+ else:
+ expected_tita += u"ti\r\n"
if results["tita_return"] == expected_tita:
score += 2
else:
- hints += ["program output incorrect" + results["tita_return"]]
+ hints += ["program output incorrect\n" + str((results["tita_return"],)) + "\n" + str((expected_tita,))]
return score, hints
@@ -273,7 +308,7 @@ def prepare_disks(templates, task_params, global_params):
#print "Haha!"
#print params
#print templates
- d = templates['SmallStudent']
+ 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'])
@@ -292,16 +327,16 @@ def prepare_disks(templates, task_params, global_params):
try:
potential_dir = os.path.join('/home/bilbo/.config', potential_dir)
d.mkdir(potential_dir)
- d.chown(1002, 1002, potential_dir)
+ d.chown(1001, 1001, potential_dir)
except:
pass
- for i in r.randint(2, 20):
+ for i in range(r.randint(2, 20)):
rndstr2 = r.choice(start_list) + \
r.choice(file_letters) + r.choice(ending_list)
hidden_file_name = os.path.join(potential_dir,
rndstr2)
- d.chown(1002, 1002, hidden_file_name)
d.write(hidden_file_name, hidden_contents)
+ d.chown(1001, 1001, hidden_file_name)
file_letters = ["stamp", "", "dev", "re"]
hidden_contents = "".join([r.choice("asdfghjkyxcvbnm1234567890 \n") for j in range(10000)])
file_letters = file_letters + ["mod", "co"]