This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/23596 ) Change subject: break circular import between utils + transport ...................................................................... break circular import between utils + transport Move init_reader() from utils.py to transport/__init__.py Change-Id: I168597ac14497fb188a15cb632f32452128bc1c6 --- M pySim-prog.py M pySim-read.py M pySim-shell.py M pySim/transport/__init__.py M pySim/utils.py 5 files changed, 35 insertions(+), 32 deletions(-) git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/96/23596/1 diff --git a/pySim-prog.py b/pySim-prog.py index 662824c..7b1283b 100755 --- a/pySim-prog.py +++ b/pySim-prog.py @@ -34,8 +34,9 @@ import json from pySim.commands import SimCardCommands +from pySim.transport import init_reader from pySim.cards import _cards_classes, card_detect -from pySim.utils import h2b, swap_nibbles, rpad, derive_milenage_opc, calculate_luhn, dec_iccid, init_reader +from pySim.utils import h2b, swap_nibbles, rpad, derive_milenage_opc, calculate_luhn, dec_iccid from pySim.ts_51_011 import EF from pySim.card_handler import * from pySim.utils import * diff --git a/pySim-read.py b/pySim-read.py index 638bd4b..59c5762 100755 --- a/pySim-read.py +++ b/pySim-read.py @@ -33,9 +33,10 @@ from pySim.ts_31_103 import EF_IST_map, EF_ISIM_ADF_map from pySim.commands import SimCardCommands +from pySim.transport import init_reader from pySim.cards import card_detect, Card, UsimCard, IsimCard from pySim.utils import h2b, swap_nibbles, rpad, dec_imsi, dec_iccid, dec_msisdn -from pySim.utils import format_xplmn_w_act, dec_spn, dec_st, init_reader, dec_addr_tlv +from pySim.utils import format_xplmn_w_act, dec_spn, dec_st, dec_addr_tlv from pySim.utils import h2s, format_ePDGSelection def parse_options(): diff --git a/pySim-shell.py b/pySim-shell.py index d27deb7..ef76cb2 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -37,9 +37,10 @@ from pySim.exceptions import * from pySim.commands import SimCardCommands +from pySim.transport import init_reader from pySim.cards import card_detect, Card from pySim.utils import h2b, swap_nibbles, rpad, h2s -from pySim.utils import dec_st, init_reader, sanitize_pin_adm, tabulate_str_list, is_hex +from pySim.utils import dec_st, sanitize_pin_adm, tabulate_str_list, is_hex from pySim.card_handler import card_handler from pySim.filesystem import CardMF, RuntimeState, CardDF, CardADF diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py index f946af8..10475c7 100644 --- a/pySim/transport/__init__.py +++ b/pySim/transport/__init__.py @@ -3,6 +3,8 @@ """ pySim: PCSC reader transport link base """ +from typing import Optional + from pySim.exceptions import * from pySim.utils import sw_match @@ -103,3 +105,30 @@ if not sw_match(rv[1], sw): raise SwMatchError(rv[1], sw.lower()) return rv + +def init_reader(opts) -> Optional[LinkBase]: + """ + Init card reader driver + """ + sl:Optional[LinkBase] = None + try: + if opts.pcsc_dev is not None: + print("Using PC/SC reader interface") + from pySim.transport.pcsc import PcscSimLink + sl = PcscSimLink(opts.pcsc_dev) + elif opts.osmocon_sock is not None: + print("Using Calypso-based (OsmocomBB) reader interface") + from pySim.transport.calypso import CalypsoSimLink + sl = CalypsoSimLink(sock_path=opts.osmocon_sock) + elif opts.modem_dev is not None: + print("Using modem for Generic SIM Access (3GPP TS 27.007)") + from pySim.transport.modem_atcmd import ModemATCommandLink + sl = ModemATCommandLink(device=opts.modem_dev, baudrate=opts.modem_baud) + else: # Serial reader is default + print("Using serial reader interface") + from pySim.transport.serial import SerialSimLink + sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate) + return sl + except Exception as e: + print("Card reader initialization failed with exception:\n" + str(e)) + return None diff --git a/pySim/utils.py b/pySim/utils.py index 8acc0bf..a0d6907 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -4,7 +4,6 @@ """ from typing import Optional, List, Dict, Any, Tuple -from pySim.transport import LinkBase # Copyright (C) 2009-2010 Sylvain Munaut <tnt at 246tNt.com> # @@ -654,34 +653,6 @@ return pin_adm -def init_reader(opts) -> Optional[LinkBase]: - """ - Init card reader driver - """ - sl:Optional[LinkBase] = None - try: - if opts.pcsc_dev is not None: - print("Using PC/SC reader interface") - from pySim.transport.pcsc import PcscSimLink - sl = PcscSimLink(opts.pcsc_dev) - elif opts.osmocon_sock is not None: - print("Using Calypso-based (OsmocomBB) reader interface") - from pySim.transport.calypso import CalypsoSimLink - sl = CalypsoSimLink(sock_path=opts.osmocon_sock) - elif opts.modem_dev is not None: - print("Using modem for Generic SIM Access (3GPP TS 27.007)") - from pySim.transport.modem_atcmd import ModemATCommandLink - sl = ModemATCommandLink(device=opts.modem_dev, baudrate=opts.modem_baud) - else: # Serial reader is default - print("Using serial reader interface") - from pySim.transport.serial import SerialSimLink - sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate) - return sl - except Exception as e: - print("Card reader initialization failed with exception:\n" + str(e)) - return None - - def enc_ePDGSelection(hexstr, mcc, mnc, epdg_priority='0001', epdg_fqdn_format='00'): """ Encode ePDGSelection so it can be stored at EF.ePDGSelection or EF.ePDGSelectionEm. -- To view, visit https://gerrit.osmocom.org/c/pysim/+/23596 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I168597ac14497fb188a15cb632f32452128bc1c6 Gerrit-Change-Number: 23596 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge at osmocom.org> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210403/820ec5b4/attachment.htm>