transport: Pass argparse.Namespace directly into transport classes

It's odd that the individual transport driver specifies their argparse
options but then the core transport part evaluates them individually.
This means we cannot add new options within a transport.

Let's pass the Namespace instance into the constructor of the
specific transport to improve this.

Change-Id: Ib977007dd605ec9a9c09a3d143d2c2308991a12c
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index 2ffb9c3..e0e1e62 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -289,17 +289,15 @@
     """
     if opts.pcsc_dev is not None:
         from pySim.transport.pcsc import PcscSimLink
-        sl = PcscSimLink(opts.pcsc_dev, **kwargs)
+        sl = PcscSimLink(opts, **kwargs)
     elif opts.osmocon_sock is not None:
         from pySim.transport.calypso import CalypsoSimLink
-        sl = CalypsoSimLink(sock_path=opts.osmocon_sock, **kwargs)
+        sl = CalypsoSimLink(opts, **kwargs)
     elif opts.modem_dev is not None:
         from pySim.transport.modem_atcmd import ModemATCommandLink
-        sl = ModemATCommandLink(
-             device=opts.modem_dev, baudrate=opts.modem_baud, **kwargs)
+        sl = ModemATCommandLink(opts, **kwargs)
     else:  # Serial reader is default
         print("No reader/driver specified; falling back to default (Serial reader)")
         from pySim.transport.serial import SerialSimLink
-        sl = SerialSimLink(device=opts.device,
-                           baudrate=opts.baudrate, **kwargs)
+        sl = SerialSimLink(opts, **kwargs)
     return sl
diff --git a/pySim/transport/calypso.py b/pySim/transport/calypso.py
index 98330a9..01bbe23 100644
--- a/pySim/transport/calypso.py
+++ b/pySim/transport/calypso.py
@@ -77,7 +77,8 @@
 class CalypsoSimLink(LinkBase):
     """Transport Link for Calypso based phones."""
 
-    def __init__(self, sock_path: str = "/tmp/osmocom_l2", **kwargs):
+    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")
diff --git a/pySim/transport/modem_atcmd.py b/pySim/transport/modem_atcmd.py
index 71f76e2..9a4f0a5 100644
--- a/pySim/transport/modem_atcmd.py
+++ b/pySim/transport/modem_atcmd.py
@@ -35,7 +35,10 @@
 class ModemATCommandLink(LinkBase):
     """Transport Link for 3GPP TS 27.007 compliant modems."""
 
-    def __init__(self, device: str = '/dev/ttyUSB0', baudrate: int = 115200, **kwargs):
+    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)")
diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py
index 762908c..6afcdac 100644
--- a/pySim/transport/pcsc.py
+++ b/pySim/transport/pcsc.py
@@ -34,18 +34,18 @@
 class PcscSimLink(LinkBase):
     """ pySim: PCSC reader transport link."""
 
-    def __init__(self, reader_number: int = 0, **kwargs):
+    def __init__(self, opts: argparse.Namespace = argparse.Namespace(pcsc_dev=0), **kwargs):
         super().__init__(**kwargs)
         if os.environ.get('PYSIM_INTEGRATION_TEST') == "1":
             print("Using PC/SC reader interface")
         else:
-            print("Using PC/SC reader number %u" % reader_number)
+            print("Using PC/SC reader number %u" % opts.pcsc_dev)
         r = readers()
-        if reader_number >= len(r):
-            raise ReaderError('No reader found for number %d' % reader_number)
-        self._reader = r[reader_number]
+        if opts.pcsc_dev >= len(r):
+            raise ReaderError('No reader found for number %d' % opts.pcsc_dev)
+        self._reader = r[opts.pcsc_dev]
         self._con = self._reader.createConnection()
-        self._reader_number = reader_number
+        self._reader_number = opts.pcsc_dev
 
     def __del__(self):
         try:
diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py
index ad800ed..e6803be 100644
--- a/pySim/transport/serial.py
+++ b/pySim/transport/serial.py
@@ -30,24 +30,24 @@
 class SerialSimLink(LinkBase):
     """ pySim: Transport Link for serial (RS232) based readers included with simcard"""
 
-    def __init__(self, device: str = '/dev/ttyUSB0', baudrate: int = 9600, rst: str = '-rts',
+    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" % device)
-        if not os.path.exists(device):
-            raise ValueError("device file %s does not exist -- abort" % device)
+            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(
-            port=device,
+            port=opts.device,
             parity=serial.PARITY_EVEN,
             bytesize=serial.EIGHTBITS,
             stopbits=serial.STOPBITS_TWO,
             timeout=1,
             xonxoff=0,
             rtscts=0,
-            baudrate=baudrate,
+            baudrate=opts.baudrate,
         )
         self._rst_pin = rst
         self._debug = debug