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
This commit is contained in:
Harald Welte
2023-12-17 12:38:29 +01:00
committed by laforge
parent c108595041
commit 0f177c1d29
6 changed files with 23 additions and 21 deletions

View File

@@ -30,24 +30,24 @@ from pySim.utils import h2b, b2h, Hexstr, ResTuple
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