From 307734373937f10305a5c10688a77889730f3b54 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Mon, 23 Oct 2023 10:18:04 +0200 Subject: [PATCH] transport: move init message into concrete classes In in the module __init__.py we print an init message (which type of LinkBase class is providing the SimLink). However in __init__.py we tend to have only platform independed code but the message string can already be categorized as platform depened. Let's put the init message into the constructor of the concrete classes of LinkBase. Related: OS#6210 Change-Id: I0a6dd7deb79a5f3e42b29094a1cf2535075fa430 --- pySim/transport/__init__.py | 4 ---- pySim/transport/calypso.py | 2 ++ pySim/transport/modem_atcmd.py | 1 + pySim/transport/pcsc.py | 1 + pySim/transport/serial.py | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py index 581f8e59..5f48657f 100644 --- a/pySim/transport/__init__.py +++ b/pySim/transport/__init__.py @@ -297,20 +297,16 @@ def init_reader(opts, **kwargs) -> LinkBase: Init card reader driver """ if opts.pcsc_dev is not None: - print("Using PC/SC reader interface") from pySim.transport.pcsc import PcscSimLink sl = PcscSimLink(opts.pcsc_dev, **kwargs) 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, **kwargs) 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, **kwargs) else: # Serial reader is default - print("Using serial reader interface") from pySim.transport.serial import SerialSimLink sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate, **kwargs) diff --git a/pySim/transport/calypso.py b/pySim/transport/calypso.py index d7d9649c..3fd99926 100644 --- a/pySim/transport/calypso.py +++ b/pySim/transport/calypso.py @@ -79,6 +79,8 @@ class CalypsoSimLink(LinkBase): def __init__(self, sock_path: str = "/tmp/osmocom_l2", **kwargs): super().__init__(**kwargs) + print("Using Calypso-based (OsmocomBB) reader interface") + # Make sure that a given socket path exists if not os.path.exists(sock_path): raise ReaderError( diff --git a/pySim/transport/modem_atcmd.py b/pySim/transport/modem_atcmd.py index 5e5a3dd6..1b741b0d 100644 --- a/pySim/transport/modem_atcmd.py +++ b/pySim/transport/modem_atcmd.py @@ -35,6 +35,7 @@ class ModemATCommandLink(LinkBase): def __init__(self, device: str = '/dev/ttyUSB0', baudrate: int = 115200, **kwargs): super().__init__(**kwargs) + print("Using modem for Generic SIM Access (3GPP TS 27.007)") self._sl = serial.Serial(device, baudrate, timeout=5) self._echo = False # this will be auto-detected by _check_echo() self._device = device diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py index c7b58786..3f3d06c0 100644 --- a/pySim/transport/pcsc.py +++ b/pySim/transport/pcsc.py @@ -34,6 +34,7 @@ class PcscSimLink(LinkBase): def __init__(self, reader_number: int = 0, **kwargs): super().__init__(**kwargs) + print("Using PC/SC reader interface") r = readers() if reader_number >= len(r): raise ReaderError('No reader found for number %d' % reader_number) diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py index e5f7bdb9..269ec9cf 100644 --- a/pySim/transport/serial.py +++ b/pySim/transport/serial.py @@ -32,6 +32,7 @@ class SerialSimLink(LinkBase): def __init__(self, device: str = '/dev/ttyUSB0', baudrate: int = 9600, rst: str = '-rts', debug: bool = False, **kwargs): super().__init__(**kwargs) + print("Using serial reader interface") if not os.path.exists(device): raise ValueError("device file %s does not exist -- abort" % device) self._sl = serial.Serial(