From 80ce71f58c8baa4b807515105ae8d7529a0fecee Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Mon, 19 Apr 2021 21:24:23 +0200 Subject: [PATCH] pySim-shell: separate export summary with a headline the export summary is printed after the log entry for the last file without separation. This is confusing because it looks like if the summary would refer to the last file only. Lets add a headline to make clear that the last few lines are the "Export summary" Change-Id: I90771e525b2b114bdb41a8e90d298ca991c09c3d Related: OS#4963 --- pySim-shell.py | 11 ++++++----- pySim/utils.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pySim-shell.py b/pySim-shell.py index a8db2635..d6221282 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -39,7 +39,7 @@ from pySim.commands import SimCardCommands from pySim.transport import init_reader, ApduTracer from pySim.cards import card_detect, Card from pySim.utils import h2b, swap_nibbles, rpad, h2s, JsonEncoder -from pySim.utils import dec_st, sanitize_pin_adm, tabulate_str_list, is_hex +from pySim.utils import dec_st, sanitize_pin_adm, tabulate_str_list, is_hex, boxed_heading_str from pySim.card_handler import card_handler from pySim.filesystem import CardMF, RuntimeState, CardDF, CardADF @@ -237,10 +237,8 @@ class PySimCommands(CommandSet): df_path_list = df.fully_qualified_path(True) df_path_list_fid = df.fully_qualified_path(False) - self._cmd.poutput("#" * 80) - file_str = '/'.join(df_path_list) + "/" + str(filename) + " " * 80 - self._cmd.poutput("# " + file_str[0:77] + "#") - self._cmd.poutput("#" * 80) + file_str = '/'.join(df_path_list) + "/" + 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))) try: @@ -288,6 +286,9 @@ class PySimCommands(CommandSet): self.export(opts.filename, context) else: self.walk(0, self.export, context) + + self._cmd.poutput(boxed_heading_str("Export summary")) + self._cmd.poutput("# total files visited: %u" % context['COUNT']) self._cmd.poutput("# bad files: %u" % context['ERR']) for b in context['BAD']: diff --git a/pySim/utils.py b/pySim/utils.py index a0da03a7..2da93a5c 100644 --- a/pySim/utils.py +++ b/pySim/utils.py @@ -841,3 +841,15 @@ class JsonEncoder(json.JSONEncoder): if isinstance(o, BytesIO) or isinstance(o, bytes) or isinstance(o, bytearray): return b2h(o) return json.JSONEncoder.default(self, o) + +def boxed_heading_str(heading, width=80): + """Generate a string that contains a boxed heading.""" + # Auto-enlarge box if heading exceeds length + if len(heading) > width - 4: + width = len(heading) + 4 + + res = "#" * width + fstr = "\n# %-" + str(width - 4) + "s #\n" + res += fstr % (heading) + res += "#" * width + return res