[libcamera-devel,01/10] utils: raspberrypi: ctt: json_pretty_print: Fix printer test

Message ID 20200703001422.24324-2-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • utils: raspberrypi: ctt: Improve JSON pretty printer
Related show

Commit Message

Laurent Pinchart July 3, 2020, 12:14 a.m. UTC
The ctt_pretty_print_json.py file supports being run standalone to test
the code. It however suffers from multiple issues:

- The same input file name is hardcoded, and doesn't exist in the
  repository
- The input file name is used instead of JSON data

Fix both issues and make the input file selectable on the command line.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 utils/raspberrypi/ctt/ctt_pretty_print_json.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Kieran Bingham July 3, 2020, 9:24 a.m. UTC | #1
Hi Laurent,

On 03/07/2020 01:14, Laurent Pinchart wrote:
> The ctt_pretty_print_json.py file supports being run standalone to test
> the code. It however suffers from multiple issues:
> 
> - The same input file name is hardcoded, and doesn't exist in the
>   repository

A good fix,

> - The input file name is used instead of JSON data

Ouch ... :S I guess that makes this a better fix ;-)

> 
> Fix both issues and make the input file selectable on the command line.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Great,

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
>  utils/raspberrypi/ctt/ctt_pretty_print_json.py | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py
> index 73383ea09665..18938c828b4e 100644
> --- a/utils/raspberrypi/ctt/ctt_pretty_print_json.py
> +++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py
> @@ -4,6 +4,8 @@
>  #
>  # ctt_pretty_print_json.py - camera tuning tool JSON formatter
>  
> +import sys
> +
>  
>  """
>  takes a collapsed json file and makes it more readable
> @@ -72,4 +74,10 @@ def pretty_print_json(str_in, output_filename):
>  
>  
>  if __name__ == '__main__':
> -    pretty_print_json("../ctt/ref_json/final_imx477.json", "pretty.json")
> +    if len(sys.argv) != 2:
> +        print("Usage: %s filename" % sys.argv[0])
> +        sys.exit(1)
> +
> +    input_filename = sys.argv[1]
> +    with open(input_filename, "r") as fin:
> +        pretty_print_json(fin.read(), "pretty.json")
>

Patch

diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py
index 73383ea09665..18938c828b4e 100644
--- a/utils/raspberrypi/ctt/ctt_pretty_print_json.py
+++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py
@@ -4,6 +4,8 @@ 
 #
 # ctt_pretty_print_json.py - camera tuning tool JSON formatter
 
+import sys
+
 
 """
 takes a collapsed json file and makes it more readable
@@ -72,4 +74,10 @@  def pretty_print_json(str_in, output_filename):
 
 
 if __name__ == '__main__':
-    pretty_print_json("../ctt/ref_json/final_imx477.json", "pretty.json")
+    if len(sys.argv) != 2:
+        print("Usage: %s filename" % sys.argv[0])
+        sys.exit(1)
+
+    input_filename = sys.argv[1]
+    with open(input_filename, "r") as fin:
+        pretty_print_json(fin.read(), "pretty.json")