Change in pysim[master]: pySim-shell: Add '--oneline' to read_{binary, record}_decoded

laforge gerrit-no-reply at lists.osmocom.org
Tue Apr 6 18:21:07 UTC 2021


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/23657 )


Change subject: pySim-shell: Add '--oneline' to read_{binary,record}_decoded
......................................................................

pySim-shell: Add '--oneline' to read_{binary,record}_decoded

This allows for single-line output, rather than the default JSON
pretty-printing

Change-Id: I08e0e7b6f0d796626f4d6c3e9a2622c1ee0c210a
---
M pySim/filesystem.py
1 file changed, 16 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/57/23657/1

diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 3eea2f4..73348e1 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -397,10 +397,18 @@
             (data, sw) = self._cmd.rs.read_binary(opts.length, opts.offset)
             self._cmd.poutput(data)
 
+        read_bin_dec_parser = argparse.ArgumentParser()
+        read_bin_dec_parser.add_argument('--oneline', action='store_true',
+                                         help='No JSON pretty-printing, dump as a single line')
+        @cmd2.with_argparser(read_bin_dec_parser)
         def do_read_binary_decoded(self, opts):
             """Read + decode data from a transparent EF"""
             (data, sw) = self._cmd.rs.read_binary_dec()
-            self._cmd.poutput(json.dumps(data, indent=4))
+            if 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.add_argument('--offset', type=int, default=0, help='Byte offset for start of read')
@@ -549,11 +557,17 @@
 
         read_rec_dec_parser = argparse.ArgumentParser()
         read_rec_dec_parser.add_argument('record_nr', type=int, help='Number of record to be read')
+        read_rec_dec_parser.add_argument('--oneline', action='store_true',
+                                         help='No JSON pretty-printing, dump as a single line')
         @cmd2.with_argparser(read_rec_dec_parser)
         def do_read_record_decoded(self, opts):
             """Read + decode a record from a record-oriented EF"""
             (data, sw) = self._cmd.rs.read_record_dec(opts.record_nr)
-            self._cmd.poutput(json.dumps(data, indent=4))
+            if 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.add_argument('record_nr', type=int, help='Number of record to be read')

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/23657
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I08e0e7b6f0d796626f4d6c3e9a2622c1ee0c210a
Gerrit-Change-Number: 23657
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210406/aeedd7e9/attachment.htm>


More information about the gerrit-log mailing list