aboutsummaryrefslogtreecommitdiffstats
path: root/pySim-shell.py
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2021-02-22 17:22:16 +0100
committerPhilipp Maier <pmaier@sysmocom.de>2021-03-18 17:19:17 +0100
commit5d3e2592f7a4073ec6030e6aaa01767d3abbdc7f (patch)
tree5874b83b28db0175e8179be7e59239ac4290ce06 /pySim-shell.py
parentbd8ed2c4dbc3c622e439617195f0adf53f165464 (diff)
pySim-shell: add "dir" command.
pysim-shell does not have a convinient way to list the files available in one directory. Tab completion currently is the only way to obtain a list of the available files. Lets add a dir command to print a file list. Change-Id: Ic06a60e0a0ec54d9bb26e151453ceb49d69e3df7 Related: OS#4963
Diffstat (limited to 'pySim-shell.py')
-rwxr-xr-xpySim-shell.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/pySim-shell.py b/pySim-shell.py
index ce9630a..407204f 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -38,7 +38,7 @@ from pySim.exceptions import *
from pySim.commands import SimCardCommands
from pySim.cards import card_detect, Card
from pySim.utils import h2b, swap_nibbles, rpad, h2s
-from pySim.utils import dec_st, init_reader, sanitize_pin_adm
+from pySim.utils import dec_st, init_reader, sanitize_pin_adm, tabulate_str_list
from pySim.card_handler import card_handler
from pySim.filesystem import CardMF, RuntimeState
@@ -112,6 +112,35 @@ class Iso7816Commands(CommandSet):
(data, sw) = self._cmd.card._scc.verify_chv(opts.chv_nr, opts.code)
self._cmd.poutput(data)
+ dir_parser = argparse.ArgumentParser()
+ dir_parser.add_argument('--fids', help='Show file identifiers', action='store_true')
+ dir_parser.add_argument('--names', help='Show file names', action='store_true')
+ dir_parser.add_argument('--apps', help='Show applications', action='store_true')
+ dir_parser.add_argument('--all', help='Show all selectable identifiers and names', action='store_true')
+
+ @cmd2.with_argparser(dir_parser)
+ def do_dir(self, opts):
+ """Show a listing of files available in currently selected DF or MF"""
+ if opts.all:
+ flags = []
+ elif opts.fids or opts.names or opts.apps:
+ flags = ['PARENT', 'SELF']
+ if opts.fids:
+ flags += ['FIDS', 'AIDS']
+ if opts.names:
+ flags += ['FNAMES', 'ANAMES']
+ if opts.apps:
+ flags += ['ANAMES', 'AIDS']
+ else:
+ flags = ['PARENT', 'SELF', 'FNAMES', 'ANAMES']
+ selectables = list(self._cmd.rs.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.rs.selected_file.fully_qualified_path(True)
+ self._cmd.poutput('/'.join(path_list))
+ path_list = self._cmd.rs.selected_file.fully_qualified_path(False)
+ self._cmd.poutput('/'.join(path_list))
+ self._cmd.poutput(directory_str)
+ self._cmd.poutput("%d files" % len(selectables))