From patchwork Mon May 29 07:37:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 768039 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wbpVY667Bz9s5L for ; Mon, 29 May 2017 17:37:41 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="g+KBz9zJ"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Etza1TDtz4H6ME2ksHGCSK9SPSjXrtOaUpolYfdp/ll6JuMI+D qxa5wMLAbpuSCsz328Z1Q9kPWmLD0KQJrng7P2qzjGQgZ50q5Qi3ZbfxAtPCEAAX H/D3aPjVKqNJPsKfQpzTHUyzBe7y3qJOHofKEShRrd7DVW5ePqaOc2ZAg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=uxPGlUCpnMxP0q65wx6nb/fWTvE=; b=g+KBz9zJ8z/uXV6xqNz8 zgtyLl357KyeZXpdn398ENm4cdwMSDNVEz86UFrn5NmdyYpyhhzPqPceZWgAfscQ 5A4QhbXdl107JRw9AiDtL5hC0fFVD6UrtfbXwfudQnxNgi7IvqWq/YcOq4jagM+D 0UOTjQf+VG4dpiZ5K0ZpWLs= Received: (qmail 60702 invoked by alias); 29 May 2017 07:37:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 60685 invoked by uid 89); 29 May 2017 07:37:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 29 May 2017 07:37:28 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-04.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1dFFF5-0004t9-73 from Tom_deVries@mentor.com ; Mon, 29 May 2017 00:37:31 -0700 Received: from [127.0.0.1] (137.202.0.87) by SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Mon, 29 May 2017 08:37:27 +0100 To: =?UTF-8?Q?Martin_Li=c5=a1ka?= CC: GCC Patches From: Tom de Vries Subject: [contrib, committed] check_GNU_style.py: Read stdin if file argument is '-' Message-ID: Date: Mon, 29 May 2017 09:37:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.1 MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) Hi, this patch makes check_GNU_style.py read from stdin if the file argument is '-', similar to what check_GNU_style.sh does. Committed. Thanks, - Tom check_GNU_style.py: Read stdin if file argument is '-' 2017-05-28 Tom de Vries * check_GNU_style_lib.py (check_GNU_style_file): Treat file argument as file handle. Add and handle file_encoding argument. * check_GNU_style.py (main): Handle '-' file argument. Call check_GNU_style_file with file handle as argument. --- contrib/check_GNU_style.py | 10 +++++++++- contrib/check_GNU_style_lib.py | 5 ++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/contrib/check_GNU_style.py b/contrib/check_GNU_style.py index 6970ddf..61faa29 100755 --- a/contrib/check_GNU_style.py +++ b/contrib/check_GNU_style.py @@ -21,6 +21,7 @@ # . */ import argparse +import sys from check_GNU_style_lib import check_GNU_style_file def main(): @@ -30,6 +31,13 @@ def main(): help = 'Display format', choices = ['stdio', 'quickfix']) args = parser.parse_args() - check_GNU_style_file(args.file, args.format) + filename = args.file + format = args.format + + if filename == '-': + check_GNU_style_file(sys.stdin, None, format) + else: + with open(filename, 'rb') as diff_file: + check_GNU_style_file(diff_file, 'utf-8', format) main() diff --git a/contrib/check_GNU_style_lib.py b/contrib/check_GNU_style_lib.py index d924e68..e1031df 100755 --- a/contrib/check_GNU_style_lib.py +++ b/contrib/check_GNU_style_lib.py @@ -223,7 +223,7 @@ class LineLengthTest(unittest.TestCase): self.assertEqual(r.console_error, self.check.limit * 'a' + error_string(' = 123;')) -def check_GNU_style_file(file, format): +def check_GNU_style_file(file, file_encoding, format): checks = [LineLengthCheck(), SpacesCheck(), TrailingWhitespaceCheck(), SentenceSeparatorCheck(), SentenceEndOfCommentCheck(), SentenceDotEndCheck(), FunctionParenthesisCheck(), @@ -231,8 +231,7 @@ def check_GNU_style_file(file, format): BracesOnSeparateLineCheck(), TrailinigOperatorCheck()] errors = [] - with open(file, 'rb') as diff_file: - patch = PatchSet(diff_file, encoding = 'utf-8') + patch = PatchSet(file, encoding=file_encoding) for pfile in patch.added_files + patch.modified_files: t = pfile.target_file.lstrip('b/')