From patchwork Fri Jul 3 00:14:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 8572 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 BF5AFC2E69 for ; Fri, 3 Jul 2020 00:14:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BFDE360CAF; Fri, 3 Jul 2020 02:14:36 +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="YN5cK8aW"; 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 0855D609C7 for ; Fri, 3 Jul 2020 02:14:35 +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 99524213C; Fri, 3 Jul 2020 02:14:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1593735274; bh=Ohj9+zn2nWRqdDDpCrzPbv0tERDEiXU/N8GfcL7ksMY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YN5cK8aWEJAX85igbUlXYqGBsV6AsDzdPGJwkRa2ReeUzIvlyXOFeKOAM13EbQbwY yNHrZVSW2xqL8DZ4KnN4YT7EjDOu99AsIGTbReF0VBaMIf+Kk+fOjC/9fB+iojEkPf 6VXvz+uDFg2iWKhDwVOo4AuI2ZpeFmyE/2enltWg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Fri, 3 Jul 2020 03:14:15 +0300 Message-Id: <20200703001422.24324-4-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 03/10] utils: raspberrypi: ctt: json_pretty_print: Make output file a class member 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" Instead of passing the output file to every method of the printer class, make it a class member. Signed-off-by: Laurent Pinchart --- .../raspberrypi/ctt/ctt_pretty_print_json.py | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py index 0e9c56234f5c..703a23fe25db 100644 --- a/utils/raspberrypi/ctt/ctt_pretty_print_json.py +++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py @@ -11,7 +11,7 @@ class JSONPrettyPrinter(object): """ Take a collapsed JSON file and make it more readable """ - def __init__(self): + def __init__(self, fout): self.state = { "indent": 0, "inarray": [False], @@ -19,65 +19,67 @@ class JSONPrettyPrinter(object): "skipnewline": True } - def newline(self, fout): - fout.write('\n') - fout.write(' ' * self.state["indent"] * 4) + self.fout = fout - def process_char(self, c, fout): + def newline(self): + self.fout.write('\n') + self.fout.write(' ' * self.state["indent"] * 4) + + def process_char(self, c): if c == '{': if not self.state["skipnewline"]: - self.newline(fout) - fout.write(c) + self.newline() + self.fout.write(c) self.state["indent"] += 1 - self.newline(fout) + self.newline() elif c == '}': self.state["indent"] -= 1 - self.newline(fout) - fout.write(c) + self.newline() + self.fout.write(c) elif c == '[': - self.newline(fout) - fout.write(c) + self.newline() + self.fout.write(c) self.state["indent"] += 1 - self.newline(fout) + self.newline() self.state["inarray"] = [True] + self.state["inarray"] self.state["arraycount"] = [0] + self.state["arraycount"] elif c == ']': self.state["indent"] -= 1 - self.newline(fout) + self.newline() self.state["inarray"].pop(0) self.state["arraycount"].pop(0) - fout.write(c) + self.fout.write(c) elif c == ':': - fout.write(c) - fout.write(' ') + self.fout.write(c) + self.fout.write(' ') elif c == ' ': pass elif c == ',': if not self.state["inarray"][0]: - fout.write(c) - fout.write(' ') - self.newline(fout) + self.fout.write(c) + self.fout.write(' ') + self.newline() else: - fout.write(c) + self.fout.write(c) self.state["arraycount"][0] += 1 if self.state["arraycount"][0] == 16: self.state["arraycount"][0] = 0 - self.newline(fout) + self.newline() else: - fout.write(' ') + self.fout.write(' ') else: - fout.write(c) + self.fout.write(c) self.state["skipnewline"] = (c == '[') - def print(self, string, fout): + def print(self, string): for c in string: - self.process_char(c, fout) + self.process_char(c) def pretty_print_json(str_in, output_filename): with open(output_filename, "w") as fout: - printer = JSONPrettyPrinter() - printer.print(str_in, fout) + printer = JSONPrettyPrinter(fout) + printer.print(str_in) if __name__ == '__main__':