diff options
author | Supreeth Herle <herlesupreeth@gmail.com> | 2020-03-18 11:38:00 +0100 |
---|---|---|
committer | Supreeth Herle <herlesupreeth@gmail.com> | 2020-03-22 10:17:03 +0100 |
commit | 4c306ab200891837e2a7b729d88495ec78f20540 (patch) | |
tree | f130f168ddf54e9c41483028320b5fd7909cef3f /pySim | |
parent | e4e98316a8bfabc9b1ce6952c1721d5c093cc9c1 (diff) |
pySim-read.py: Added a common card detection function for both pySim-prog.py and pySim-read.py
This function is used to detect the card type and return Card class/Card subclasses object
if its a know card or else None. Also, an initial step towards refactoring of code.
Change-Id: I71f57c6403dc933bd9d54f90df3d3fe105b4f66f
Diffstat (limited to 'pySim')
-rw-r--r-- | pySim/cards.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/pySim/cards.py b/pySim/cards.py index fe7f0fd..a43da9c 100644 --- a/pySim/cards.py +++ b/pySim/cards.py @@ -1104,3 +1104,31 @@ def card_autodetect(scc): card.reset() return card return None + +def card_detect(ctype, scc): + # Detect type if needed + card = None + ctypes = dict([(kls.name, kls) for kls in _cards_classes]) + + if ctype in ("auto", "auto_once"): + for kls in _cards_classes: + card = kls.autodetect(scc) + if card: + print("Autodetected card type: %s" % card.name) + card.reset() + break + + if card is None: + print("Autodetection failed") + return None + + if ctype == "auto_once": + ctype = card.name + + elif ctype in ctypes: + card = ctypes[ctype](scc) + + else: + raise ValueError("Unknown card type: %s" % ctype) + + return card |