From patchwork Mon Jul 25 10:15:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 72708 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1064605qga; Mon, 25 Jul 2016 03:15:33 -0700 (PDT) X-Received: by 10.194.75.198 with SMTP id e6mr14602119wjw.31.1469441732949; Mon, 25 Jul 2016 03:15:32 -0700 (PDT) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id 133si23330838wmx.136.2016.07.25.03.15.32; Mon, 25 Jul 2016 03:15:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EB732A77C7; Mon, 25 Jul 2016 12:15:11 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id E71Yy0TAlt8j; Mon, 25 Jul 2016 12:15:11 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1F6AFA77A7; Mon, 25 Jul 2016 12:15:10 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A2F24A778D for ; Mon, 25 Jul 2016 12:14:24 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PVUN8TqLxOFR for ; Mon, 25 Jul 2016 12:14:24 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from conuserg-11.nifty.com (conuserg-11.nifty.com [210.131.2.78]) by theia.denx.de (Postfix) with ESMTPS id 9C527A7794 for ; Mon, 25 Jul 2016 12:14:17 +0200 (CEST) Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-11.nifty.com with ESMTP id u6PADhxH021296; Mon, 25 Jul 2016 19:13:46 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-11.nifty.com u6PADhxH021296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1469441627; bh=n9Zc55hQoYfD0rhHYrQliA91R2aGuyBzPjbn2TNDneU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KwTufUwOwX5uAfz3Ej39H/OA9x0jhCXtqqCC/qfkf34cdtLS5cEG4rNHBZqQ8NA52 d+XPhiMImwLeDuFHyKQSrKLQayJ01CBMxT1dqlC8gU+r2LHQ9JRPpx7h2wfkTd13/Z aSluTC2g815bhTcqTBIYqHKP/o/jxVqyDEmsKVtRI0frD3UJeX4VcN+QJSVMRdmbw3 O+rQenz6cdi20Yjr1dwGi6XK0+K7TysSDquXR+iaN0lOth6hvGQfxa0s5Qm8zJFJ1o egzBn0FP6LAVjemSCaBTaSv74Mb4eXwVYXfqly2Ei8epryDUKpGEvYB3Tw40hemXxT WwoiKWXg3MomQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Mon, 25 Jul 2016 19:15:26 +0900 Message-Id: <1469441729-5817-6-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1469441729-5817-1-git-send-email-yamada.masahiro@socionext.com> References: <1469441729-5817-1-git-send-email-yamada.masahiro@socionext.com> Cc: Tom Rini , Joe Hershberger Subject: [U-Boot] [PATCH v2 5/8] tools: moveconfig: show diffs of cleaned headers in color X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Show code diff in color if --color option is given. Signed-off-by: Masahiro Yamada --- Changes in v2: - Make diffing into a helper function tools/moveconfig.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) -- 1.9.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/tools/moveconfig.py b/tools/moveconfig.py index 4f07782..4edcb6c 100755 --- a/tools/moveconfig.py +++ b/tools/moveconfig.py @@ -276,13 +276,14 @@ def color_text(color_enabled, color, string): else: return string -def show_diff(a, b, file_path): +def show_diff(a, b, file_path, color_enabled): """Show unidified diff. Arguments: a: A list of lines (before) b: A list of lines (after) file_path: Path to the file + color_enabled: Display the diff in color """ diff = difflib.unified_diff(a, b, @@ -290,7 +291,12 @@ def show_diff(a, b, file_path): tofile=os.path.join('b', file_path)) for line in diff: - print line, + if line[0] == '-' and line[1] != '-': + print color_text(color_enabled, COLOR_RED, line), + elif line[0] == '+' and line[1] != '+': + print color_text(color_enabled, COLOR_GREEN, line), + else: + print line, def update_cross_compile(color_enabled): """Update per-arch CROSS_COMPILE via environment variables @@ -388,14 +394,14 @@ def extend_matched_lines(lines, matched, pre_patterns, post_patterns, extend_pre matched += extended_matched matched.sort() -def cleanup_one_header(header_path, patterns, dry_run): +def cleanup_one_header(header_path, patterns, options): """Clean regex-matched lines away from a file. Arguments: header_path: path to the cleaned file. patterns: list of regex patterns. Any lines matching to these patterns are deleted. - dry_run: make no changes, but still display log. + options: option flags. """ with open(header_path) as f: lines = f.readlines() @@ -436,21 +442,21 @@ def cleanup_one_header(header_path, patterns, dry_run): for i in reversed(matched): tolines.pop(i) - show_diff(lines, tolines, header_path) + show_diff(lines, tolines, header_path, options.color) - if dry_run: + if options.dry_run: return with open(header_path, 'w') as f: for line in tolines: f.write(line) -def cleanup_headers(configs, dry_run): +def cleanup_headers(configs, options): """Delete config defines from board headers. Arguments: configs: A list of CONFIGs to remove. - dry_run: make no changes, but still display log. + options: option flags. """ while True: choice = raw_input('Clean up headers? [y/n]: ').lower() @@ -473,7 +479,7 @@ def cleanup_headers(configs, dry_run): for filename in filenames: if not fnmatch.fnmatch(filename, '*~'): cleanup_one_header(os.path.join(dirpath, filename), - patterns, dry_run) + patterns, options) ### classes ### class Progress: @@ -1145,7 +1151,7 @@ def main(): move_config(configs, options) if configs: - cleanup_headers(configs, options.dry_run) + cleanup_headers(configs, options) if __name__ == '__main__': main()