From c100297855b8ec8652df590cba9795bfc6382d34 Mon Sep 17 00:00:00 2001 From: hploetz Date: Mon, 22 May 2006 05:20:11 +0000 Subject: [PATCH] make the wait for a card abortable by ctrl-c git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@74 f711b948-2313-0410-aaa9-d29f33439f0b --- cyberflex-shell.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cyberflex-shell.py b/cyberflex-shell.py index 4a55634..3a7abba 100755 --- a/cyberflex-shell.py +++ b/cyberflex-shell.py @@ -86,13 +86,26 @@ class Cyberflex_Shell(Shell): if not newState[0]['EventState'] & pycsc.SCARD_STATE_PRESENT: print "Please insert card ..." + last_was_mute = False + while not newState[0]['EventState'] & pycsc.SCARD_STATE_PRESENT \ or newState[0]['EventState'] & pycsc.SCARD_STATE_MUTE: - newState = pycsc.getStatusChange(ReaderStates=[{'Reader': readerName, 'CurrentState':newState[0]['EventState']}]) + try: + newState = pycsc.getStatusChange(ReaderStates=[ + {'Reader': readerName, 'CurrentState':newState[0]['EventState']} + ], Timeout = 100 + ) ## 100 ms latency from Ctrl-C to abort should be almost unnoticeable by the user + except pycsc.PycscException, e: + if e.args[0] == 'Command timeout.': pass ## ugly + else: raise if newState[0]['EventState'] & pycsc.SCARD_STATE_MUTE: - print "Card is mute, please retry ..." + if not last_was_mute: + print "Card is mute, please retry ..." + last_was_mute = True + else: + last_was_mute = False print "Card present: %s" % ((newState[0]['EventState'] & pycsc.SCARD_STATE_PRESENT) and "yes" or "no")