diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2018-10-07 20:21:31 +0200 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2018-10-07 20:21:31 +0200 |
commit | 80f050080ce11c6a0cce67c9b0281c09702b00d6 (patch) | |
tree | b486e1f6342bc757dda87df4856084f652895791 /kpov_judge/tasks/copy_rename_100_files | |
parent | 43d7ef057b4ae752a60b947e523b3a56782bf5cd (diff) | |
parent | dbf585c2a59dbcb7f6d803d5756826b562cd7f43 (diff) |
Merge branch 'fix-tasks'
Fixes pexpect usage in most tasks. Several other cleanups and minor
refactoring.
Diffstat (limited to 'kpov_judge/tasks/copy_rename_100_files')
-rw-r--r-- | kpov_judge/tasks/copy_rename_100_files/task.py | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/kpov_judge/tasks/copy_rename_100_files/task.py b/kpov_judge/tasks/copy_rename_100_files/task.py index 9ad4d66..051f9f7 100644 --- a/kpov_judge/tasks/copy_rename_100_files/task.py +++ b/kpov_judge/tasks/copy_rename_100_files/task.py @@ -1,6 +1,3 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# # TODO: # - check if everything is filled in (computers, params, preparation) # - improve scoring @@ -73,17 +70,10 @@ params_meta = { } def task(host, folder): - from pexpect import pxssh - - # ideally, this would be done using a SFTP client instead of pxssh - target = pxssh.pxssh() - target.login(host, 'test', 'test') - results = { - 'files': target.run('ls -1').split('\n'), # XXX: file may have newlines - 'contents': target.run("cat *"), # XXX: may include other files in $HOME - } - target.logout() - return results + return kpov_util.ssh_test(host, 'test', 'test', ( + ('files', 'ls -1'), # XXX: file may have newlines + ('contents', 'cat *'), # XXX: may include other files in $HOME + )) def gen_params(user_id, params_meta): pass @@ -93,10 +83,13 @@ def task_check(results, params): score = 0 hints = [] + if results['ssh'] is not True: + hints += ['ssh failed: ' + results['ssh']] + matched = 0 files = os.listdir(params['folder']) for fn in files: - if fn in results['files']: + if fn in results['files'].splitlines(): matched += 1 if matched > 0: score = 1 @@ -110,12 +103,12 @@ def task_check(results, params): score += 3 else: hints += ["wrong number of files"] - rl = results['contents'].split('\n') + rl = results['contents'].splitlines() rl.sort() tl = [] for fn in files: - with open(fn) as f: - tl += f.read().upper().split('\n') + with open(os.path.join(params['folder'], fn)) as f: + tl += f.read().upper().splitlines() tl.sort() if rl == tl: score += 4 |