forked from public/pysim
pySim-shell: Add settable parameter on JSON pretty-printing
Change-Id: Ic095c96733de2b0f359bfe067cd719d38712faff
This commit is contained in:
@@ -208,6 +208,14 @@ Writes will only be performed if the new value is different from the current on-
|
|||||||
|
|
||||||
If disabled, pySim will always write irrespective of the current/new value.
|
If disabled, pySim will always write irrespective of the current/new value.
|
||||||
|
|
||||||
|
json_pretty_print
|
||||||
|
~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
This parameter determines if generated JSON output should (by default) be pretty-printed (multi-line
|
||||||
|
output with indent level of 4 spaces) or not.
|
||||||
|
|
||||||
|
The default value of this parameter is 'true'.
|
||||||
|
|
||||||
debug
|
debug
|
||||||
~~~~~
|
~~~~~
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,16 @@ class PysimApp(cmd2.Cmd):
|
|||||||
self.add_settable(cmd2.Settable('conserve_write', bool, 'Read and compare before write',
|
self.add_settable(cmd2.Settable('conserve_write', bool, 'Read and compare before write',
|
||||||
onchange_cb=self._onchange_conserve_write))
|
onchange_cb=self._onchange_conserve_write))
|
||||||
self.update_prompt()
|
self.update_prompt()
|
||||||
|
self.json_pretty_print = True
|
||||||
|
self.add_settable(cmd2.Settable('json_pretty_print', bool, 'Pretty-Print JSON output'))
|
||||||
|
|
||||||
|
def poutput_json(self, data, force_no_pretty = False):
|
||||||
|
"""line cmd2.putput() but for a json serializable dict."""
|
||||||
|
if force_no_pretty or self.json_pretty_print == False:
|
||||||
|
output = json.dumps(data)
|
||||||
|
else:
|
||||||
|
output = json.dumps(data, indent=4)
|
||||||
|
self.poutput(output)
|
||||||
|
|
||||||
def _onchange_numeric_path(self, param_name, old, new):
|
def _onchange_numeric_path(self, param_name, old, new):
|
||||||
self.update_prompt()
|
self.update_prompt()
|
||||||
|
|||||||
@@ -404,11 +404,7 @@ class TransparentEF(CardEF):
|
|||||||
def do_read_binary_decoded(self, opts):
|
def do_read_binary_decoded(self, opts):
|
||||||
"""Read + decode data from a transparent EF"""
|
"""Read + decode data from a transparent EF"""
|
||||||
(data, sw) = self._cmd.rs.read_binary_dec()
|
(data, sw) = self._cmd.rs.read_binary_dec()
|
||||||
if opts.oneline:
|
self._cmd.poutput_json(data, opts.oneline)
|
||||||
output = json.dumps(data)
|
|
||||||
else:
|
|
||||||
output = json.dumps(data, indent=4)
|
|
||||||
self._cmd.poutput(output)
|
|
||||||
|
|
||||||
upd_bin_parser = argparse.ArgumentParser()
|
upd_bin_parser = argparse.ArgumentParser()
|
||||||
upd_bin_parser.add_argument('--offset', type=int, default=0, help='Byte offset for start of read')
|
upd_bin_parser.add_argument('--offset', type=int, default=0, help='Byte offset for start of read')
|
||||||
@@ -428,7 +424,7 @@ class TransparentEF(CardEF):
|
|||||||
data_json = json.loads(opts.data)
|
data_json = json.loads(opts.data)
|
||||||
(data, sw) = self._cmd.rs.update_binary_dec(data_json)
|
(data, sw) = self._cmd.rs.update_binary_dec(data_json)
|
||||||
if data:
|
if data:
|
||||||
self._cmd.poutput(json.dumps(data, indent=4))
|
self._cmd.poutput_json(data)
|
||||||
|
|
||||||
def __init__(self, fid:str, sfid:str=None, name:str=None, desc:str=None, parent:CardDF=None,
|
def __init__(self, fid:str, sfid:str=None, name:str=None, desc:str=None, parent:CardDF=None,
|
||||||
size={1,None}):
|
size={1,None}):
|
||||||
@@ -563,11 +559,7 @@ class LinFixedEF(CardEF):
|
|||||||
def do_read_record_decoded(self, opts):
|
def do_read_record_decoded(self, opts):
|
||||||
"""Read + decode a record from a record-oriented EF"""
|
"""Read + decode a record from a record-oriented EF"""
|
||||||
(data, sw) = self._cmd.rs.read_record_dec(opts.record_nr)
|
(data, sw) = self._cmd.rs.read_record_dec(opts.record_nr)
|
||||||
if opts.oneline:
|
self._cmd.poutput_json(data, opts.oneline)
|
||||||
output = json.dumps(data)
|
|
||||||
else:
|
|
||||||
output = json.dumps(data, indent=4)
|
|
||||||
self._cmd.poutput(output)
|
|
||||||
|
|
||||||
upd_rec_parser = argparse.ArgumentParser()
|
upd_rec_parser = argparse.ArgumentParser()
|
||||||
upd_rec_parser.add_argument('record_nr', type=int, help='Number of record to be read')
|
upd_rec_parser.add_argument('record_nr', type=int, help='Number of record to be read')
|
||||||
|
|||||||
Reference in New Issue
Block a user