public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [contrib, committed] check_GNU_style.py: Read stdin if file argument is '-'
@ 2017-05-29  7:42 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2017-05-29  7:42 UTC (permalink / raw)
  To: Martin Liška; +Cc: GCC Patches

[-- Attachment #1: Type: text/plain, Size: 155 bytes --]

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

[-- Attachment #2: 0002-check_GNU_style.py-Read-stdin-if-file-argument-is.patch --]
[-- Type: text/x-patch, Size: 2318 bytes --]

check_GNU_style.py: Read stdin if file argument is '-'

2017-05-28  Tom de Vries  <tom@codesourcery.com>

	* 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 @@
 # <http://www.gnu.org/licenses/>.  */
 
 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/')

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-29  7:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-29  7:42 [contrib, committed] check_GNU_style.py: Read stdin if file argument is '-' Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).