dexter has uploaded this change for review.
pySim-shell: clean up method calls in do_switch_channel
The function do_switch_channel method calls methods in RuntimeLchan
that should be private. There is also a code duplication in
RuntimeLchan that should be cleaned up.
Related: OS#6092
Change-Id: Ie5e5f45787abaaf032e1b49f51d447653cf2c996
---
M pySim-shell.py
M pySim/runtime.py
2 files changed, 29 insertions(+), 14 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/15/37615/1
diff --git a/pySim-shell.py b/pySim-shell.py
index e99c365..8f654bd 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -859,9 +859,9 @@
@cmd2.with_argparser(switch_chan_parser)
def do_switch_channel(self, opts):
"""Switch currently active logical channel."""
- self._cmd.lchan._select_pre(self._cmd)
+ self._cmd.lchan.unregister_cmds(self._cmd)
self._cmd.lchan = self._cmd.rs.lchan[opts.chan_nr]
- self._cmd.lchan._select_post(self._cmd)
+ self._cmd.lchan.register_cmds(self._cmd)
self._cmd.update_prompt()
def do_status(self, opts):
diff --git a/pySim/runtime.py b/pySim/runtime.py
index db1641f..71bf8d9 100644
--- a/pySim/runtime.py
+++ b/pySim/runtime.py
@@ -262,7 +262,8 @@
raise ValueError(
"Cannot select unknown file by name %s, only hexadecimal 4 digit FID is allowed" % fid)
- self._select_pre(cmd_app)
+ # unregister commands of old file
+ self.unregister_cmds(cmd_app)
try:
# We access the card through the select_file method of the scc object.
@@ -295,12 +296,6 @@
self._select_post(cmd_app, f, data)
- def _select_pre(self, cmd_app):
- # unregister commands of old file
- if cmd_app and self.selected_file.shell_commands:
- for c in self.selected_file.shell_commands:
- cmd_app.unregister_command_set(c)
-
def _select_post(self, cmd_app, file:Optional[CardFile] = None, select_resp_data = None):
# we store some reference data (see above) about the currently selected file.
# This data must be updated after every select.
@@ -316,9 +311,7 @@
self.selected_file_fcp = None
# register commands of new file
- if cmd_app and self.selected_file.shell_commands:
- for c in self.selected_file.shell_commands:
- cmd_app.register_command_set(c)
+ self.register_cmds(cmd_app)
def select_file(self, file: CardFile, cmd_app=None):
"""Select a file (EF, DF, ADF, MF, ...).
@@ -331,7 +324,9 @@
inter_path = self.selected_file.build_select_path_to(file)
if not inter_path:
raise RuntimeError('Cannot determine path from %s to %s' % (self.selected_file, file))
- self._select_pre(cmd_app)
+
+ # unregister commands of old file
+ self.unregister_cmds(cmd_app)
# be sure the variables that we pass to _select_post contain valid values.
selected_file = self.selected_file
@@ -577,8 +572,14 @@
raise TypeError("Only works with BER-TLV EF")
return self.scc.set_data(self.selected_file.fid, tag, data_hex, conserve=self.rs.conserve_write)
+ def register_cmds(self, cmd_app=None):
+ """Register command set that is associated with the currently selected file"""
+ if cmd_app and self.selected_file.shell_commands:
+ for c in self.selected_file.shell_commands:
+ cmd_app.register_command_set(c)
+
def unregister_cmds(self, cmd_app=None):
- """Unregister all file specific commands."""
+ """Unregister command set that is associated with the currently seleted file"""
if cmd_app and self.selected_file.shell_commands:
for c in self.selected_file.shell_commands:
cmd_app.unregister_command_set(c)
To view, visit change 37615. To unsubscribe, or for help writing mail filters, visit settings.