pySim-shell: print device info in case an exception occurs

When an exception occurs while initializing or handling the card we
print a traceback, but we do not print any info that allows us to
identify the device that was involved when the exception occurred. Let's
include the device path or number in the error message before we print
the traceback.

In order to make it easier to print the device information, let's add a
__str__() method to all of our devices. This method shall return the
device number or path.

Related: OS#6210
Change-Id: I200463e692245da40ea6d5b609bfc0ca02d15bdb
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py
index c8079f6..1dd8d18 100644
--- a/pySim/transport/__init__.py
+++ b/pySim/transport/__init__.py
@@ -68,6 +68,10 @@
         self.proactive_handler = proactive_handler
 
     @abc.abstractmethod
+    def __str__(self):
+        """Implementation specific method for printing an information to identify the device."""
+
+    @abc.abstractmethod
     def _send_apdu_raw(self, pdu: Hexstr) -> ResTuple:
         """Implementation specific method for sending the PDU."""
 
diff --git a/pySim/transport/calypso.py b/pySim/transport/calypso.py
index 34fc646..b827d88 100644
--- a/pySim/transport/calypso.py
+++ b/pySim/transport/calypso.py
@@ -90,6 +90,9 @@
         self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
         self.sock.connect(sock_path)
 
+        # Remember socket path
+        self._sock_path = sock_path
+
     def __del__(self):
         self.sock.close()
 
@@ -156,3 +159,6 @@
         sw = rsp[-2:]
 
         return b2h(data), b2h(sw)
+
+    def __str__(self):
+        return "osmocon:%s" % (self._sock_path)
diff --git a/pySim/transport/modem_atcmd.py b/pySim/transport/modem_atcmd.py
index e99762d..58d6f9d 100644
--- a/pySim/transport/modem_atcmd.py
+++ b/pySim/transport/modem_atcmd.py
@@ -169,3 +169,6 @@
         sw = rsp_pdu[-4:].decode().lower()
         log.debug('Command response: %s, %s',  data, sw)
         return data, sw
+
+    def __str__(self):
+        return "modem:%s" % self._device
diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py
index a01917f..41c4c19 100644
--- a/pySim/transport/pcsc.py
+++ b/pySim/transport/pcsc.py
@@ -39,6 +39,7 @@
             raise ReaderError('No reader found for number %d' % reader_number)
         self._reader = r[reader_number]
         self._con = self._reader.createConnection()
+        self._reader_number = reader_number
 
     def __del__(self):
         try:
@@ -91,3 +92,6 @@
 
         # Return value
         return i2h(data), i2h(sw)
+
+    def __str__(self):
+        return "PCSC:%u[%s]" % (self._reader_number,  self._reader)
diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py
index 998d1d8..f4b1621 100644
--- a/pySim/transport/serial.py
+++ b/pySim/transport/serial.py
@@ -236,3 +236,6 @@
 
         # Return value
         return b2h(data), b2h(sw)
+
+    def __str__(self):
+        return "serial:%s" % (self._sl.name)