diff options
Diffstat (limited to 'kpov_judge/tasks/rename_grep_network')
-rw-r--r-- | kpov_judge/tasks/rename_grep_network/task.py | 74 |
1 files changed, 26 insertions, 48 deletions
diff --git a/kpov_judge/tasks/rename_grep_network/task.py b/kpov_judge/tasks/rename_grep_network/task.py index e8ce0b2..948edcf 100644 --- a/kpov_judge/tasks/rename_grep_network/task.py +++ b/kpov_judge/tasks/rename_grep_network/task.py @@ -139,26 +139,6 @@ params_meta = { 'generated': True, }, - # 'progname': { - # 'descriptions': { - # 'si': 'Ime programa', - # 'en': 'Program filename', - # }, - # 'w': False, - # 'public': True, - # 'type': 'filename', - # 'generated': True, - # }, - 'pubseed': { - 'descriptions': { - 'si': 'Nekaj nepredvidenega', - 'en': 'A random seed', - }, - 'w': False, - 'public': True, - 'type': None, - 'generated': True, - }, 'rndseed': { 'descriptions': { 'si': 'random seed za skrito datoteko', @@ -171,30 +151,30 @@ params_meta = { }, } -def task(testip, testuser, passwd, mntdir, magicstr, pubseed): +def task(testip, testuser, passwd, mntdir, magicstr): + import collections from pexpect import pxssh - import random - target = pxssh.pxssh() - target.login(testip, testuser, passwd) - target.sendline('ls ~/') - target.prompt() - home_ls = target.before - target.sendline('cat ~/*I*.txt') - target.prompt() - dst_file_contents = target.before - target.sendline('ls -l ~/*I*.txt') - target.prompt() - dst_ls = target.before - target.sendline('mount') - target.prompt() - mnt = target.before - results = { - 'home_ls': home_ls, - 'dst_ls': dst_ls, - 'mnt': mnt, - 'dst_file_contents': dst_file_contents, - } - target.logout() + + commands = [ + ('home_ls', 'ls ~/'), + ('dst_file_contents', 'cat ~/*I*.txt'), + ('dst_ls', 'ls -l ~/*I*.txt'), + ('mnt', 'mount'), + ] + + results = collections.defaultdict(str) + try: + s = pxssh.pxssh(encoding='utf-8') + s.login(testip, testuser, passwd) + results['ssh'] = True + for test, command in commands: + s.sendline(command) + s.prompt() + if test: + results[test] = s.before + s.logout() + except Exception as ex: + results['ssh'] = str(ex) return results def gen_params(user_id, params_meta): @@ -207,10 +187,6 @@ def gen_params(user_id, params_meta): params['passwd'] = kpov_random_helpers.alnum_gen(r, 8) params['magicstr'] = "".join([r.choice("qwerztlpoQWERTPOL") for i in range(10)]) params['mntdir'] = "/" + kpov_random_helpers.default_generators['filename'](r) - # 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(r, 8) params['rndseed'] = kpov_random_helpers.alnum_gen(r, 8) return params @@ -220,6 +196,8 @@ def task_check(results, params): import re hints = [] score = 0 + if results['ssh'] is not True: + hints += ['ssh failed: ' + results['ssh']] hidden_contents = params['magicstr'] r = random.Random(params['rndseed']) dstfile = "".join([r.choice("qQoOp") for i in range(64)]) + "I.txt" @@ -242,7 +220,7 @@ def task_check(results, params): if results["dst_file_contents"] == expected_contents: score += 3 else: - diff_pos = "" + diff_pos = (0, "") for i, c in enumerate(results["dst_file_contents"]): if len(expected_contents) < i or c != expected_contents[i]: start = max(0, i-10) |