1
0
Fork 0

tools: wasptool: Improve error reporting if we can't sync

Signed-off-by: Daniel Thompson <daniel@redfelineninja.org.uk>
This commit is contained in:
Daniel Thompson 2020-10-21 20:49:48 +01:00
parent 2bb0837440
commit 2b244ec2a3

View file

@ -29,13 +29,27 @@ def sync(c):
Sending a random print ensure the final export (of the prompt)
does not accidentally match a previously issued prompt.
"""
verbose = bool(c.logfile)
tag = ''.join([random.choice(string.ascii_uppercase) for i in range(6)])
c.send('\x03')
c.expect('>>> ')
c.sendline(f'print("{tag[:3]}""{tag[3:]}")')
c.expect(tag)
c.expect('>>> ')
try:
if not verbose:
c.logfile = io.StringIO()
c.send('\x03')
c.expect('>>> ')
c.sendline(f'print("{tag[:3]}""{tag[3:]}")')
c.expect(tag)
c.expect('>>> ')
if not verbose:
c.logfile.close()
c.logfile = None
except pexpect.exceptions.EOF:
print("ERROR: Cannot sync with device")
print_log(c.logfile)
sys.exit(1)
def unsync(c):
"""Set the watch running again.