tools: wasptool: Improve command output for --exec and --eval
This commit is contained in:
parent
6729ac67a5
commit
2e7db3ae19
1 changed files with 24 additions and 3 deletions
|
@ -4,6 +4,7 @@
|
||||||
# Copyright (c) 2020 Daniel Thompson
|
# Copyright (c) 2020 Daniel Thompson
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import io
|
||||||
import random
|
import random
|
||||||
import os.path
|
import os.path
|
||||||
import pexpect
|
import pexpect
|
||||||
|
@ -78,6 +79,16 @@ def paste(c, f, verbose=False, chunk=None):
|
||||||
c.sendline(ln)
|
c.sendline(ln)
|
||||||
c.expect('=== ')
|
c.expect('=== ')
|
||||||
|
|
||||||
|
def print_log(logfile):
|
||||||
|
lines = logfile.getvalue().split('\n')
|
||||||
|
lines = [ l.strip('\x04\r') for l in lines ]
|
||||||
|
|
||||||
|
output = [ l for l in lines if l and l != '>>> ' ]
|
||||||
|
if output:
|
||||||
|
print('~~~')
|
||||||
|
print('\n'.join(output))
|
||||||
|
print('~~~')
|
||||||
|
|
||||||
def handle_eval(c, cmd):
|
def handle_eval(c, cmd):
|
||||||
verbose = bool(c.logfile)
|
verbose = bool(c.logfile)
|
||||||
|
|
||||||
|
@ -86,17 +97,23 @@ def handle_eval(c, cmd):
|
||||||
c.sendline(cmd)
|
c.sendline(cmd)
|
||||||
c.expect('=== ')
|
c.expect('=== ')
|
||||||
|
|
||||||
c.logfile = sys.stdout
|
if not verbose:
|
||||||
|
c.logfile = io.StringIO()
|
||||||
c.send('\x04')
|
c.send('\x04')
|
||||||
c.expect('>>> ')
|
c.expect('>>> ')
|
||||||
if not verbose:
|
if not verbose:
|
||||||
|
print_log(c.logfile)
|
||||||
|
c.logfile.close()
|
||||||
c.logfile = None
|
c.logfile = None
|
||||||
|
|
||||||
def handle_exec(c, fname):
|
def handle_exec(c, fname):
|
||||||
verbose = bool(c.logfile)
|
verbose = bool(c.logfile)
|
||||||
|
|
||||||
|
log = io.StringIO()
|
||||||
|
|
||||||
def chunk():
|
def chunk():
|
||||||
c.logfile = sys.stdout
|
if not verbose:
|
||||||
|
c.logfile = log
|
||||||
c.send('\x04')
|
c.send('\x04')
|
||||||
c.expect('>>> ')
|
c.expect('>>> ')
|
||||||
if not verbose:
|
if not verbose:
|
||||||
|
@ -113,12 +130,16 @@ def handle_exec(c, fname):
|
||||||
|
|
||||||
paste(c, f, verbose, chunk)
|
paste(c, f, verbose, chunk)
|
||||||
|
|
||||||
c.logfile = sys.stdout
|
if not verbose:
|
||||||
|
c.logfile = log
|
||||||
c.send('\x04')
|
c.send('\x04')
|
||||||
c.expect('>>> ')
|
c.expect('>>> ')
|
||||||
if not verbose:
|
if not verbose:
|
||||||
c.logfile = None
|
c.logfile = None
|
||||||
|
|
||||||
|
print_log(log)
|
||||||
|
log.close()
|
||||||
|
|
||||||
def handle_reset(c):
|
def handle_reset(c):
|
||||||
c.send('\x05')
|
c.send('\x05')
|
||||||
c.expect('=== ')
|
c.expect('=== ')
|
||||||
|
|
Loading…
Add table
Reference in a new issue