From patchwork Fri Jul 3 00:14:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8576 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8A70AC2E69 for ; Fri, 3 Jul 2020 00:14:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4FD02609C7; Fri, 3 Jul 2020 02:14:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bojpdbHn"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6B9DD60C82 for ; Fri, 3 Jul 2020 02:14:36 +0200 (CEST) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0106F9CB; Fri, 3 Jul 2020 02:14:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1593735276; bh=7hroq+IlpH3NtH5Uj9dOXaPGPeSNlTT7GPsKpXxkETk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bojpdbHnU9izoaIUIk03rTkmouPrvp1BxZHZNjuOx33ntMaZIYDOt/gq1AtrhQF+B QLOag33hsn6JQvfQL9pSHgJ2OjWoFiA7rwHqe0WmIBAQAjzzQvyGzneeCuSUuefc13 ShRnC2NecrCl/4xLhMZjiWQEKWQWbqoYUvrc954Y= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Jul 2020 03:14:19 +0300 Message-Id: <20200703001422.24324-8-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200703001422.24324-1-laurent.pinchart@ideasonboard.com> References: <20200703001422.24324-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 07/10] utils: raspberrypi: ctt: json_pretty_print: Fix indentation handling X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Indentation is handled by outputting spaces right after outputting a newline character. That works in most cases, but would result in the input '{}' being printed as { } instead of { } Fix it by outputting the indentation before outputting the next character after a newline. The indentation value will be updated by then. Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt_pretty_print_json.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py index 9d450f6d300c..f1c61347d8fc 100644 --- a/utils/raspberrypi/ctt/ctt_pretty_print_json.py +++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py @@ -16,16 +16,20 @@ class JSONPrettyPrinter(object): "indent": 0, "inarray": [False], "arraycount": [], - "skipnewline": True + "skipnewline": True, + "need_indent": False, } self.fout = fout def newline(self): self.fout.write('\n') - self.fout.write(' ' * self.state["indent"] * 4) + self.state["need_indent"] = True def write(self, c): + if self.state["need_indent"]: + self.fout.write(' ' * self.state["indent"] * 4) + self.state["need_indent"] = False self.fout.write(c) def process_char(self, c):