From patchwork Fri Jul 3 00:14:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8575 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 2B5A9BE905 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 EA15C60C58; Fri, 3 Jul 2020 02:14:39 +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="ZmAEorVS"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0E431609C7 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 A11A01450; 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=1593735275; bh=cKxC+ZjyOzongWJSon59Bi6YEc0GqqQHKdyZmhGtTUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZmAEorVSmipXxiCuio/eIxatgU9Tjq5x284aR6DvOlJyE1df/VsM0nwXBlpZutMMD irxeEL5KQtdcMvEqRpXO0EQMjOmnaYchD7kBbCc8pjM7p/yDvw0hxxm+N705NEJwdX cE5aDgTkm+6fhTj+4FkslQnzNBFMn35wYFqB/jZg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Jul 2020 03:14:18 +0300 Message-Id: <20200703001422.24324-7-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 06/10] utils: raspberrypi: ctt: json_pretty_print: Add character write method 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" Add a write method to the JSONPrettyPrinter class to output a character. This will be used to handle state updates when outputting individual characters. Signed-off-by: Laurent Pinchart --- .../raspberrypi/ctt/ctt_pretty_print_json.py | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py index dfa99a6d4034..9d450f6d300c 100644 --- a/utils/raspberrypi/ctt/ctt_pretty_print_json.py +++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py @@ -25,20 +25,23 @@ class JSONPrettyPrinter(object): self.fout.write('\n') self.fout.write(' ' * self.state["indent"] * 4) + def write(self, c): + self.fout.write(c) + def process_char(self, c): if c == '{': if not self.state["skipnewline"]: self.newline() - self.fout.write(c) + self.write(c) self.state["indent"] += 1 self.newline() elif c == '}': self.state["indent"] -= 1 self.newline() - self.fout.write(c) + self.write(c) elif c == '[': self.newline() - self.fout.write(c) + self.write(c) self.state["indent"] += 1 self.newline() self.state["inarray"] = [True] + self.state["inarray"] @@ -48,27 +51,27 @@ class JSONPrettyPrinter(object): self.newline() self.state["inarray"].pop(0) self.state["arraycount"].pop(0) - self.fout.write(c) + self.write(c) elif c == ':': - self.fout.write(c) - self.fout.write(' ') + self.write(c) + self.write(' ') elif c == ',': if not self.state["inarray"][0]: - self.fout.write(c) - self.fout.write(' ') + self.write(c) + self.write(' ') self.newline() else: - self.fout.write(c) + self.write(c) self.state["arraycount"][0] += 1 if self.state["arraycount"][0] == 16: self.state["arraycount"][0] = 0 self.newline() else: - self.fout.write(' ') + self.write(' ') elif c.isspace(): pass else: - self.fout.write(c) + self.write(c) self.state["skipnewline"] = (c == '[') def print(self, string):