From 93aac3abe6b536984f369bc4d07087801fb97807 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 27 Apr 2023 15:18:13 +0200 Subject: [PATCH] pySim-shell: fix compatibility problem with cmd2 >= 2.0.0 (Settable) In cmd2 relase 2.0.0 the constructor of Settable adds a settable_object parameter, which apparantly was optional at first, but then became mandatory. Older versions must not have the settable_object parameter but versions from 2.0.0 on require it. Let's add a version check so that we stay compatible to cmd2 versions below and above 2.0.0. See also: https://github.com/python-cmd2/cmd2 Commit 486734e85988d0d0160147b0b44a37759c833e8a Author: Eric Lin Date: 2020-08-19 20:01:50 and Commit 8f981f37eddcccc919329245b85fd44d5975a6a7 Author: Eric Lin Date: 2021-03-16 17:25:34 This commit is based on pySim gerrit change: Ifce40410587c85ae932774144b9548b154ee8ad0 Change-Id: I38efe4702277ee092a5542d7d659df08cb0adeff --- README.md | 1 + pySim-shell.py | 25 +++++++++++++++++-------- requirements.txt | 1 + setup.py | 1 + 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a6986534..1246d943 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Please install the following dependencies: - pyyaml >= 5.1 - termcolor - colorlog + - packaging Example for Debian: ```sh diff --git a/pySim-shell.py b/pySim-shell.py index bf97b6fa..fab5d096 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -23,6 +23,7 @@ import json import traceback import cmd2 +from packaging import version from cmd2 import style, fg from cmd2 import CommandSet, with_default_category, with_argparser import argparse @@ -146,18 +147,26 @@ class PysimApp(cmd2.Cmd): self.ch = ch self.numeric_path = False - self.add_settable(cmd2.Settable('numeric_path', bool, 'Print File IDs instead of names', - onchange_cb=self._onchange_numeric_path)) self.conserve_write = True - self.add_settable(cmd2.Settable('conserve_write', bool, 'Read and compare before write', - onchange_cb=self._onchange_conserve_write)) self.json_pretty_print = True - self.add_settable(cmd2.Settable('json_pretty_print', - bool, 'Pretty-Print JSON output')) self.apdu_trace = False - self.add_settable(cmd2.Settable('apdu_trace', bool, 'Trace and display APDUs exchanged with card', - onchange_cb=self._onchange_apdu_trace)) + if version.parse(cmd2.__version__) < version.parse("2.0.0"): + self.add_settable(cmd2.Settable('numeric_path', bool, 'Print File IDs instead of names', + onchange_cb=self._onchange_numeric_path)) + self.add_settable(cmd2.Settable('conserve_write', bool, 'Read and compare before write', + onchange_cb=self._onchange_conserve_write)) + self.add_settable(cmd2.Settable('json_pretty_print', bool, 'Pretty-Print JSON output')) + self.add_settable(cmd2.Settable('apdu_trace', bool, 'Trace and display APDUs exchanged with card', + onchange_cb=self._onchange_apdu_trace)) + else: + self.add_settable(cmd2.Settable('numeric_path', bool, 'Print File IDs instead of names', self, \ + onchange_cb=self._onchange_numeric_path)) # pylint: disable=too-many-function-args + self.add_settable(cmd2.Settable('conserve_write', bool, 'Read and compare before write', self, \ + onchange_cb=self._onchange_conserve_write)) # pylint: disable=too-many-function-args + self.add_settable(cmd2.Settable('json_pretty_print', bool, 'Pretty-Print JSON output', self)) # pylint: disable=too-many-function-args + self.add_settable(cmd2.Settable('apdu_trace', bool, 'Trace and display APDUs exchanged with card', self, \ + onchange_cb=self._onchange_apdu_trace)) # pylint: disable=too-many-function-args self.equip(card, rs) def equip(self, card, rs): diff --git a/requirements.txt b/requirements.txt index 4144a1ca..bfdbd624 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,3 +10,4 @@ pyyaml>=5.1 termcolor colorlog pycryptodome +packaging diff --git a/setup.py b/setup.py index 210d307f..132dfe2e 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,7 @@ setup( "termcolor", "colorlog", "pycryptodome" + "packaging" ], scripts=[ 'pySim-prog.py',