aboutsummaryrefslogtreecommitdiffstats
path: root/pySim-shell.py
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2023-04-27 15:18:13 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2023-05-17 17:30:49 +0200
commit93aac3abe6b536984f369bc4d07087801fb97807 (patch)
tree86832948dd0a6196ddbc8e36cd1865cb49e6b2d7 /pySim-shell.py
parent87dd020d5fbcfadb994d5c808868ee6a0d178fe6 (diff)
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 <anselor@gmail.com> Date: 2020-08-19 20:01:50 and Commit 8f981f37eddcccc919329245b85fd44d5975a6a7 Author: Eric Lin <anselor@gmail.com> Date: 2021-03-16 17:25:34 This commit is based on pySim gerrit change: Ifce40410587c85ae932774144b9548b154ee8ad0 Change-Id: I38efe4702277ee092a5542d7d659df08cb0adeff
Diffstat (limited to 'pySim-shell.py')
-rwxr-xr-xpySim-shell.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/pySim-shell.py b/pySim-shell.py
index bf97b6f..fab5d09 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):