aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2022-07-19 23:48:45 +0200
committerHarald Welte <laforge@osmocom.org>2022-07-20 19:35:58 +0200
commitb2e4b4a3006a0e190bb53dbc3d0e33da81472e52 (patch)
tree160d4bce4ef8ae767bf588dc21d324cffc436d24
parent3c98d5e91dd3f9c2b7f8d23885c8cfaadbed282b (diff)
introduce fully_qualified_path_str() method
Reduce all the copy+pasted '/'.join(path_list) constructs with a method returning the formatted path string. Change-Id: I5e9bfb425c3a3fade13ca4ccd2b891a0c21ed56d
-rwxr-xr-xpySim-shell.py36
-rw-r--r--pySim/filesystem.py8
2 files changed, 24 insertions, 20 deletions
diff --git a/pySim-shell.py b/pySim-shell.py
index c05fd7a..f9ab115 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -227,9 +227,8 @@ class PysimApp(cmd2.Cmd):
def update_prompt(self):
if self.lchan:
- path_list = self.lchan.selected_file.fully_qualified_path(
- not self.numeric_path)
- self.prompt = 'pySIM-shell (%s)> ' % ('/'.join(path_list))
+ path_str = self.lchan.selected_file.fully_qualified_path_str(not self.numeric_path)
+ self.prompt = 'pySIM-shell (%s)> ' % (path_str)
else:
if self.card:
self.prompt = 'pySIM-shell (no card profile)> '
@@ -483,10 +482,10 @@ class PySimCommands(CommandSet):
self._cmd.lchan.selected_file.get_selectable_names(flags=flags))
directory_str = tabulate_str_list(
selectables, width=79, hspace=2, lspace=1, align_left=True)
- path_list = self._cmd.lchan.selected_file.fully_qualified_path(True)
- self._cmd.poutput('/'.join(path_list))
- path_list = self._cmd.lchan.selected_file.fully_qualified_path(False)
- self._cmd.poutput('/'.join(path_list))
+ path = self._cmd.lchan.selected_file.fully_qualified_path_str(True)
+ self._cmd.poutput(path)
+ path = self._cmd.lchan.selected_file.fully_qualified_path_str(False)
+ self._cmd.poutput(path)
self._cmd.poutput(directory_str)
self._cmd.poutput("%d files" % len(selectables))
@@ -518,8 +517,8 @@ class PySimCommands(CommandSet):
except Exception as e:
skip_df = True
df = self._cmd.lchan.selected_file
- df_path_list = df.fully_qualified_path(True)
- df_skip_reason_str = '/'.join(df_path_list) + \
+ df_path = df.fully_qualified_path_str(True)
+ df_skip_reason_str = df_path + \
"/" + str(f) + ", " + str(e)
if context:
context['DF_SKIP'] += 1
@@ -559,13 +558,13 @@ class PySimCommands(CommandSet):
"currently selected file %s is not a DF or ADF" % str(df))
df_path_list = df.fully_qualified_path(True)
- df_path_list_fid = df.fully_qualified_path(False)
+ df_path = df.fully_qualified_path_str(True)
+ df_path_fid = df.fully_qualified_path_str(False)
- file_str = '/'.join(df_path_list) + "/" + str(filename)
+ file_str = df_path + "/" + str(filename)
self._cmd.poutput(boxed_heading_str(file_str))
- self._cmd.poutput("# directory: %s (%s)" %
- ('/'.join(df_path_list), '/'.join(df_path_list_fid)))
+ self._cmd.poutput("# directory: %s (%s)" % (df_path, df_path_fid))
try:
fcp_dec = self._cmd.lchan.select(filename, self._cmd)
self._cmd.poutput("# file: %s (%s)" % (
@@ -629,8 +628,7 @@ class PySimCommands(CommandSet):
raise RuntimeError(
'Unsupported structure "%s" of file "%s"' % (structure, filename))
except Exception as e:
- bad_file_str = '/'.join(df_path_list) + \
- "/" + str(filename) + ", " + str(e)
+ bad_file_str = df_path + "/" + str(filename) + ", " + str(e)
self._cmd.poutput("# bad file: %s" % bad_file_str)
context['ERR'] += 1
context['BAD'].append(bad_file_str)
@@ -734,11 +732,9 @@ class Iso7816Commands(CommandSet):
def do_select(self, opts):
"""SELECT a File (ADF/DF/EF)"""
if len(opts.arg_list) == 0:
- path_list = self._cmd.lchan.selected_file.fully_qualified_path(True)
- path_list_fid = self._cmd.lchan.selected_file.fully_qualified_path(
- False)
- self._cmd.poutput("currently selected file: " +
- '/'.join(path_list) + " (" + '/'.join(path_list_fid) + ")")
+ path = self._cmd.lchan.selected_file.fully_qualified_path_str(True)
+ path_fid = self._cmd.lchan.selected_file.fully_qualified_path_str(False)
+ self._cmd.poutput("currently selected file: %s (%s)" % (path, path_fid))
return
path = opts.arg_list[0]
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 5e697bf..182889b 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -112,6 +112,14 @@ class CardFile:
else:
return self.fid
+ def fully_qualified_path_str(self, prefer_name: bool = True) -> str:
+ """Return fully qualified path to file as string.
+
+ Args:
+ prefer_name : Preferably build path of names; fall-back to FIDs as required
+ """
+ return '/'.join(self.fully_qualified_path(prefer_name))
+
def fully_qualified_path(self, prefer_name: bool = True) -> List[str]:
"""Return fully qualified path to file as list of FID or name strings.