summaryrefslogtreecommitdiff
path: root/utils/raspberrypi/ctt/ctt_pretty_print_json.py
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2020-05-03 16:49:53 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-05-11 23:54:45 +0300
commitc01cfe14f5540ba96b458088185ac7ae90bb3534 (patch)
treef9112e0195de83ea1b20cf81cb62144cd50174f9 /utils/raspberrypi/ctt/ctt_pretty_print_json.py
parent0db2c8dc75e466e7648dc1b95380495c6a126349 (diff)
libcamera: utils: Raspberry Pi Camera Tuning Tool
Initial implementation of the Raspberry Pi (BCM2835) Camera Tuning Tool. All code is licensed under the BSD-2-Clause terms. Copyright (c) 2019-2020 Raspberry Pi Trading Ltd. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'utils/raspberrypi/ctt/ctt_pretty_print_json.py')
-rw-r--r--utils/raspberrypi/ctt/ctt_pretty_print_json.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py
new file mode 100644
index 00000000..44a9311b
--- /dev/null
+++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (C) 2019, Raspberry Pi (Trading) Limited
+#
+# ctt_pretty_print_json.py - camera tuning tool JSON formatter
+
+"""
+takes a collapsed json file and makes it more readable
+"""
+def process_file(string, fout, state):
+ for c in string:
+ process_char(c, fout, state)
+
+def print_newline(fout, state):
+ fout.write('\n')
+ fout.write(' '*state["indent"]*4)
+
+def process_char(c, fout, state):
+ if c == '{':
+ if not state["skipnewline"]: print_newline(fout, state)
+ fout.write(c)
+ state["indent"] += 1
+ print_newline(fout, state)
+ elif c == '}':
+ state["indent"] -= 1
+ print_newline(fout, state)
+ fout.write(c)
+ elif c == '[':
+ print_newline(fout, state)
+ fout.write(c)
+ state["indent"] += 1
+ print_newline(fout, state)
+ state["inarray"] = [True] + state["inarray"]
+ state["arraycount"] = [0] + state["arraycount"]
+ elif c == ']':
+ state["indent"] -= 1
+ print_newline(fout, state)
+ state["inarray"].pop(0)
+ state["arraycount"].pop(0)
+ fout.write(c)
+ elif c == ':':
+ fout.write(c)
+ fout.write(' ')
+ elif c == ' ':
+ pass
+ elif c == ',':
+ if not state["inarray"][0]:
+ fout.write(c)
+ fout.write(' ')
+ print_newline(fout, state)
+ else:
+ fout.write(c)
+ state["arraycount"][0] += 1
+ if state["arraycount"][0] == 16:
+ state["arraycount"][0] = 0
+ print_newline(fout, state)
+ else:
+ fout.write(' ')
+ else:
+ fout.write(c)
+ state["skipnewline"] = (c == '[')
+
+def pretty_print_json(str_in, output_filename):
+ state = {"indent": 0, "inarray": [False], "arraycount": [], "skipnewline" : True}
+ with open(output_filename, "w") as fout:
+ process_file(str_in, fout, state)
+
+
+if __name__ == '__main__':
+ pretty_print_json("../ctt/ref_json/final_imx477.json", "pretty.json")