From b4a9c0e3c5b9bf79d67f122191b0e9830dba9a30 Mon Sep 17 00:00:00 2001 From: Steffen Ritter Date: Tue, 6 Dec 2022 17:25:54 +0100 Subject: Add argument to format output as json --- inspect.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/inspect.py b/inspect.py index a6a3e9e..e89ffbd 100755 --- a/inspect.py +++ b/inspect.py @@ -4,6 +4,7 @@ import argparse import logging import os import sys +import json from tools import libvmdk, libvslvm, lklfuse, nbdfuse, subfiles, unmount, rmdir from tools.inspect_apps import ( @@ -27,6 +28,8 @@ parser.add_argument("-b", "--backend", type=str, default="nbdfuse", "local filesystem (default: nbdfuse)") parser.add_argument("-v", "--verbose", action="store_true", help="print debug messages") +parser.add_argument("--json", action="store_true", + help="format output as json") args = parser.parse_args() @@ -114,8 +117,14 @@ if lvm_mp: unmount(image_mp) rmdir(image_mp) -print({ +output = { "name": os_info.get("name", ""), "version": os_info.get("version", ""), "apps": apps -}) +} + +if args.json: + print(json.dumps(output, indent = 2)) +else: + print(output) + -- cgit v1.2.3-55-g7522