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
This commit is contained in:
Harald Welte 2023-04-27 15:18:13 +02:00 committed by Philipp Maier
parent 87dd020d5f
commit 93aac3abe6
4 changed files with 20 additions and 8 deletions

View File

@ -45,6 +45,7 @@ Please install the following dependencies:
- pyyaml >= 5.1
- termcolor
- colorlog
- packaging
Example for Debian:
```sh

View File

@ -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):

View File

@ -10,3 +10,4 @@ pyyaml>=5.1
termcolor
colorlog
pycryptodome
packaging

View File

@ -20,6 +20,7 @@ setup(
"termcolor",
"colorlog",
"pycryptodome"
"packaging"
],
scripts=[
'pySim-prog.py',