laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/33421 )
Change subject: cosmetic: Implement cmd2.Settable backwards-compat via wrapper class ......................................................................
cosmetic: Implement cmd2.Settable backwards-compat via wrapper class
Let's avoid too many open-coded if-clauses and simply wrap it in a compatibility class.
Change-Id: Id234f3fa56fe7eff8e1153d71b9be8a2e88dd112 --- M pySim-shell.py 1 file changed, 30 insertions(+), 20 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/21/33421/1
diff --git a/pySim-shell.py b/pySim-shell.py index b018102..0acd1cf 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -153,6 +153,17 @@ else: return super().run_editor(file_path)
+class Settable2Compat(cmd2.Settable): + """Backwards-compatibility wrapper around cmd2.Settable to support older and newer + releases. See https://github.com/python-cmd2/cmd2/blob/master/CHANGELOG.md""" + def __init__(self, name, val_type, description, settable_object, **kwargs): + if version.parse(cmd2.__version__) < version.parse("2.0.0"): + # pylint: disable=no-value-for-parameter + super().__init__(name, val_type, description, **kwargs) + else: + # pylint: disable=too-many-function-args + super().__init__(name, val_type, description, settable_object, **kwargs) + class PysimApp(Cmd2Compat): CUSTOM_CATEGORY = 'pySim Commands'
@@ -179,26 +190,13 @@ self.json_pretty_print = True self.apdu_trace = False
- if version.parse(cmd2.__version__) < version.parse("2.0.0"): - # pylint: disable=no-value-for-parameter - self.add_settable(cmd2.Settable('numeric_path', bool, 'Print File IDs instead of names', - onchange_cb=self._onchange_numeric_path)) - # pylint: disable=no-value-for-parameter - self.add_settable(cmd2.Settable('conserve_write', bool, 'Read and compare before write', - onchange_cb=self._onchange_conserve_write)) - # pylint: disable=no-value-for-parameter - self.add_settable(cmd2.Settable('json_pretty_print', bool, 'Pretty-Print JSON output')) - # pylint: disable=no-value-for-parameter - 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.add_settable(Settable2Compat('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(Settable2Compat('conserve_write', bool, 'Read and compare before write', self, \ + onchange_cb=self._onchange_conserve_write)) # pylint: disable=too-many-function-args + self.add_settable(Settable2Compat('json_pretty_print', bool, 'Pretty-Print JSON output', self)) # pylint: disable=too-many-function-args + self.add_settable(Settable2Compat('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):