dexter has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/34692?usp=email )
( 4 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one. )Change subject: pySim-shell: print device info in case an exception occurs ...................................................................... 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 --- M pySim-shell.py M pySim-trace.py 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 7 files changed, 46 insertions(+), 3 deletions(-) Approvals: osmith: Looks good to me, but someone else must approve laforge: Looks good to me, but someone else must approve Jenkins Builder: Verified fixeria: Looks good to me, approved diff --git a/pySim-shell.py b/pySim-shell.py index 79b4d8b..56655ba 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -374,7 +374,7 @@ rc = self.equip(card, rs) except: self.poutput("") - self.poutput("Card initialization failed with an exception:") + self.poutput("Card initialization (%s) failed with an exception:" % str(self.sl)) self.poutput("---------------------8<---------------------") traceback.print_exc() self.poutput("---------------------8<---------------------") @@ -489,7 +489,7 @@ return except: self.poutput("") - self.poutput("Card handling failed with an exception:") + self.poutput("Card handling (%s) failed with an exception:" % str(self.sl)) self.poutput("---------------------8<---------------------") traceback.print_exc() self.poutput("---------------------8<---------------------") @@ -1031,7 +1031,7 @@ rs, card = init_card(sl) app = PysimApp(card, rs, sl, ch, opts.script) except: - print("Card initialization failed with an exception:") + print("Card initialization (%s) failed with an exception:" % str(sl)) print("---------------------8<---------------------") traceback.print_exc() print("---------------------8<---------------------") diff --git a/pySim-trace.py b/pySim-trace.py index 325fb8c..eb29ed1 100755 --- a/pySim-trace.py +++ b/pySim-trace.py @@ -48,6 +48,9 @@ self._debug = debug self._atr = h2i('3B9F96801F878031E073FE211B674A4C753034054BA9') + def __str__(self): + return "dummy" + def _send_apdu_raw(self, pdu): #print("DummySimLink-apdu: %s" % pdu) return [], '9000' 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) -- To view, visit https://gerrit.osmocom.org/c/pysim/+/34692?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: pysim Gerrit-Branch: master Gerrit-Change-Id: I200463e692245da40ea6d5b609bfc0ca02d15bdb Gerrit-Change-Number: 34692 Gerrit-PatchSet: 6 Gerrit-Owner: dexter <pma...@sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: dexter <pma...@sysmocom.de> Gerrit-Reviewer: fixeria <vyanits...@sysmocom.de> Gerrit-Reviewer: laforge <lafo...@osmocom.org> Gerrit-Reviewer: osmith <osm...@sysmocom.de> Gerrit-MessageType: merged