laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/34961?usp=email )
(
5 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: transport: Move printing of reader number/name to generic code ......................................................................
transport: Move printing of reader number/name to generic code
Let's avoid copy+pasting print statements everywhere. The instances do already have a __str__ method for the purpose of printing their name in a generic way.
Change-Id: I663a9ea69bf7e7aaa6502896b6a71ef692f8d844 --- M pySim/transport/__init__.py M pySim/transport/calypso.py M pySim/transport/modem_atcmd.py M pySim/transport/pcsc.py M pySim/transport/serial.py 5 files changed, 24 insertions(+), 19 deletions(-)
Approvals: Jenkins Builder: Verified osmith: Looks good to me, but someone else must approve laforge: Looks good to me, approved
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py index d075878..59d4554 100644 --- a/pySim/transport/__init__.py +++ b/pySim/transport/__init__.py @@ -3,6 +3,7 @@ """ pySim: PCSC reader transport link base """
+import os import abc import argparse from typing import Optional, Tuple @@ -300,4 +301,10 @@ print("No reader/driver specified; falling back to default (Serial reader)") from pySim.transport.serial import SerialSimLink sl = SerialSimLink(opts, **kwargs) + + if os.environ.get('PYSIM_INTEGRATION_TEST') == "1": + print("Using %s reader interface" % (sl.name)) + else: + print("Using reader %s" % sl) + return sl diff --git a/pySim/transport/calypso.py b/pySim/transport/calypso.py index 01bbe23..dd30f80 100644 --- a/pySim/transport/calypso.py +++ b/pySim/transport/calypso.py @@ -76,14 +76,11 @@
class CalypsoSimLink(LinkBase): """Transport Link for Calypso based phones.""" + name = 'Calypso-based (OsmocomBB) reader'
def __init__(self, opts: argparse.Namespace = argparse.Namespace(osmocon_sock="/tmp/osmocom_l2"), **kwargs): sock_path = opts.osmocon_sock super().__init__(**kwargs) - if os.environ.get('PYSIM_INTEGRATION_TEST') == "1": - print("Using Calypso-based (OsmocomBB) reader interface") - else: - print("Using Calypso-based (OsmocomBB) reader at socket %s" % sock_path) # 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 9a4f0a5..88e6253 100644 --- a/pySim/transport/modem_atcmd.py +++ b/pySim/transport/modem_atcmd.py @@ -21,7 +21,6 @@ import time import re import argparse -import os from typing import Optional
from pySim.utils import Hexstr, ResTuple @@ -34,16 +33,13 @@
class ModemATCommandLink(LinkBase): """Transport Link for 3GPP TS 27.007 compliant modems.""" + name = "modem for Generic SIM Access (3GPP TS 27.007)"
def __init__(self, opts: argparse.Namespace = argparse.Namespace(modem_dev='/dev/ttyUSB0', modem_baud=115200), **kwargs): device = opts.modem_dev baudrate = opts.modem_baud super().__init__(**kwargs) - if os.environ.get('PYSIM_INTEGRATION_TEST') == "1": - print("Using modem for Generic SIM Access (3GPP TS 27.007)") - else: - print("Using modem for Generic SIM Access (3GPP TS 27.007) at port %s" % device) 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 b1c424f..8a99e9f 100644 --- a/pySim/transport/pcsc.py +++ b/pySim/transport/pcsc.py @@ -18,7 +18,6 @@ #
import argparse -import os import re from typing import Optional, Union
@@ -34,6 +33,7 @@
class PcscSimLink(LinkBase): """ pySim: PCSC reader transport link.""" + name = 'PC/SC'
def __init__(self, opts: argparse.Namespace = argparse.Namespace(pcsc_dev=0), **kwargs): super().__init__(**kwargs) @@ -57,11 +57,6 @@
self._con = self._reader.createConnection()
- if os.environ.get('PYSIM_INTEGRATION_TEST') == "1": - print("Using PC/SC reader interface") - else: - print("Using PC/SC reader %s" % self) - def __del__(self): try: # FIXME: this causes multiple warnings in Python 3.5.3 diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py index e6803be..fbf907f 100644 --- a/pySim/transport/serial.py +++ b/pySim/transport/serial.py @@ -29,14 +29,11 @@
class SerialSimLink(LinkBase): """ pySim: Transport Link for serial (RS232) based readers included with simcard""" + name = 'Serial'
def __init__(self, opts = argparse.Namespace(device='/dev/ttyUSB0', baudrate=9600), rst: str = '-rts', debug: bool = False, **kwargs): super().__init__(**kwargs) - if os.environ.get('PYSIM_INTEGRATION_TEST') == "1": - print("Using serial reader interface") - else: - print("Using serial reader interface at port %s" % opts.device) if not os.path.exists(opts.device): raise ValueError("device file %s does not exist -- abort" % opts.device) self._sl = serial.Serial(