*g dZddlZddlZddlZddlmZGddZGddeZGdd eZdS) z pySim: card handler utilities. A 'card handler' is some method by which cards can be inserted/removed into the card reader. For normal smart card readers, this has to be done manually. However, there are also automatic card feeders. N)LinkBasecReZdZdZdefdZd defdZdZdZ d defd Z d Z d Z d S)CardHandlerBasezHAbstract base class representing a mechanism for card insertion/removal.slc||_dSN)r)selfrs @/home/jenkins/workspace/simtester-sanitize/pySim/card_handler.py__init__zCardHandlerBase.__init__$s FfirstcRtdd||dS)aMethod called when pySim needs a new card to be inserted. Args: first : set to true when the get method is called the first time. This is required to prevent blocking when a card is already inserted into the reader. The reader API would not recognize that card as "new card" until it would be removed and re-inserted again. zReady for Programming: endN)print_getr r s r getzCardHandlerBase.get's0 'R0000 %r cPtdd|dS)zLMethod called when pySim failed to program a card. Move card to 'bad' batch.zProgramming failed: rrN)r_errorr s r errorzCardHandlerBase.error5s' $"---- r cPtdd|dS)zMMethod called when pySim failed to program a card. Move card to 'good' batch.zProgramming successful: rrN)r_doners r donezCardHandlerBase.done:s' (b1111 r cdSrrs r rzCardHandlerBase._get? r cdSrrrs r rzCardHandlerBase._errorBrr cdSrrrs r rzCardHandlerBase._doneErr NF) __name__ __module__ __qualname____doc__rr boolrrrrrrrr r rr!sRR8          $            r rc,eZdZdZddefdZdZdZdS) CardHandlerzLManual card handler: User is prompted to insert/remove card from the reader.Fr c\td|j| dS)Nz%Insert card now (or CTRL-C to cancel)) newcardonly)rr wait_for_cardrs r rzCardHandler._getLs2 5666 e)44444r cBtdtddSNzRemove card from readerrrrs r rzCardHandler._errorP  '((( b r cBtdtddSr.r/rs r rzCardHandler._doneTr0r Nr")r#r$r%r&r'rrrrr r r)r)IsXVV55$5555r r)cVeZdZdZdZdedeffd ZdZdZ d d e fd Z d Z d Z xZS)CardHandlerAutoz>Automatic card handler: A machine is used to handle the cards.Tr config_filecbt|tdt|zt |5}t j|t j|_dddn #1swxYwY|j ddu|_ dS)NzCard handler Config-file: )LoaderverboseT) superr rstropenyamlload FullLoadercmdsrr7)r rr4cfg __class__s r r zCardHandlerAuto.__init__^s  *S-=-==>>> +   ?# #do>>>DI ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?y}}Y//47 s&BB Bctdtdtd|d}t|dkrtdt||d}t|dkrtdt|tdtddS)NrzCard handler output:z,---------------------8<---------------------rzstdout:zstderr:)rstriplen)r outstdoutstderrs r __print_outoutzCardHandlerAuto.__print_outoutes b  $%%% <===Q v;;?? )    &MMMQ v;;?? )    &MMM <=== b r ctdt|ztj|gtjtjd}|}|j}|dks|jr|||dkrGtdtdt|zdztj |dSdS)NzCard handler Commandline: T)rFrGshellrrz!Error: Card handler failure! (rc=)) rr9 subprocessPopenPIPE communicate returncoder7_CardHandlerAuto__print_outoutsysexit)r commandprocrErcs r __exec_cmdzCardHandlerAuto.__exec_cmdts *S\\9::: IjojoTSSS   _ 77dl7    $ $ $ 77 "III 5B?#E F F F HRLLLLL 7r Fr ctd||jd|jr|jdSdS)Nz(Transporting card into the reader-bay...r)r_CardHandlerAuto__exec_cmdr>rconnectrs r rzCardHandlerAuto._getsV 8999  %())) 7  GOO       r ctd||jdtddS)Nz%Transporting card to the error-bin...rrrrYr>rs r rzCardHandlerAuto._errors9 5666  '*+++ b r ctd||jdtddS)Nz+Transporting card into the collector bin...rrr\rs r rzCardHandlerAuto._dones9 ;<<<  &)*** b r r")r#r$r%r&r7rr9r rQrYr'rrr __classcell__)r@s@r r3r3YsHHG888#888888    $  r r3) r&rLrRr;pySim.transportrrr)r3rr r r`s0 $$$$$$% % % % % % % % P     /    99999o99999r