laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/32532 
)

Change subject: pySim-shell: fix compatibility problem with cmd2 >= 2.0.0 
(Settable)
......................................................................

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 <anse...@gmail.com>
Date:   2020-08-19 20:01:50

and

Commit 8f981f37eddcccc919329245b85fd44d5975a6a7
Author: Eric Lin <anse...@gmail.com>
Date: 2021-03-16 17:25:34

This commit is based on pySim gerrit change:
Ifce40410587c85ae932774144b9548b154ee8ad0

Change-Id: I38efe4702277ee092a5542d7d659df08cb0adeff
---
M README.md
M pySim-shell.py
M requirements.txt
M setup.py
4 files changed, 50 insertions(+), 8 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved




diff --git a/README.md b/README.md
index a698653..1246d94 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,7 @@
  - pyyaml >= 5.1
  - termcolor
  - colorlog
+ - packaging

 Example for Debian:
 ```sh
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 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 @@
         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 4144a1c..bfdbd62 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -10,3 +10,4 @@
 termcolor
 colorlog
 pycryptodome
+packaging
diff --git a/setup.py b/setup.py
index 210d307..132dfe2 100644
--- a/setup.py
+++ b/setup.py
@@ -20,6 +20,7 @@
         "termcolor",
         "colorlog",
         "pycryptodome"
+        "packaging"
     ],
     scripts=[
         'pySim-prog.py',

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/32532
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I38efe4702277ee092a5542d7d659df08cb0adeff
Gerrit-Change-Number: 32532
Gerrit-PatchSet: 17
Gerrit-Owner: dexter <pma...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanits...@sysmocom.de>
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-CC: osmith <osm...@sysmocom.de>
Gerrit-MessageType: merged

Reply via email to