From e33085889f26c76587fdab2ad600ed336dc028b5 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sat, 6 Oct 2018 23:35:00 +0200 Subject: Improve ssh error reporting in some tasks --- kpov_judge/tasks/copy_rename_100_files/task.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'kpov_judge/tasks/copy_rename_100_files/task.py') diff --git a/kpov_judge/tasks/copy_rename_100_files/task.py b/kpov_judge/tasks/copy_rename_100_files/task.py index 9ad4d66..c658d27 100644 --- a/kpov_judge/tasks/copy_rename_100_files/task.py +++ b/kpov_judge/tasks/copy_rename_100_files/task.py @@ -73,16 +73,19 @@ params_meta = { } def task(host, folder): + import collections 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() + results = collections.defaultdict(str) + try: + # ideally, this would be done using a SFTP client instead of pxssh + s = pxssh.pxssh(encoding='utf-8') + s.login(host, 'test', 'test') + results['ssh'] = True + results['files'] = s.run('ls -1').split('\n'), # XXX: file may have newlines + results['contents'] = s.run('cat *'), # XXX: may include other files in $HOME + s.logout() + except Exception as ex: + results['ssh'] = str(ex) return results def gen_params(user_id, params_meta): -- cgit v1.2.1