aboutsummaryrefslogtreecommitdiffstats
path: root/cyberflex-shell.py
diff options
context:
space:
mode:
authorhploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b>2006-05-22 05:20:11 +0000
committerhploetz <hploetz@f711b948-2313-0410-aaa9-d29f33439f0b>2006-05-22 05:20:11 +0000
commitc100297855b8ec8652df590cba9795bfc6382d34 (patch)
tree62070ea461131beeacd8f76f56e04f0c0e39a996 /cyberflex-shell.py
parent4f99f3a507fc22478318cdc86558e42fdb096871 (diff)
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
Diffstat (limited to 'cyberflex-shell.py')
-rwxr-xr-xcyberflex-shell.py17
1 files 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")