community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1763703 - /comdev/reporter.apache.org/trunk/scripts/prettify.py
Date Fri, 07 Oct 2016 09:04:51 GMT
Author: sebb
Date: Fri Oct  7 09:04:51 2016
New Revision: 1763703

URL: http://svn.apache.org/viewvc?rev=1763703&view=rev
Log:
Support use as filter

Modified:
    comdev/reporter.apache.org/trunk/scripts/prettify.py

Modified: comdev/reporter.apache.org/trunk/scripts/prettify.py
URL: http://svn.apache.org/viewvc/comdev/reporter.apache.org/trunk/scripts/prettify.py?rev=1763703&r1=1763702&r2=1763703&view=diff
==============================================================================
--- comdev/reporter.apache.org/trunk/scripts/prettify.py (original)
+++ comdev/reporter.apache.org/trunk/scripts/prettify.py Fri Oct  7 09:04:51 2016
@@ -5,15 +5,17 @@ parser = argparse.ArgumentParser()
 parser.add_argument("--nosort", action='store_true', help="Don't sort the output", default=False)
 parser.add_argument("--clobber",action='store_true', help="Overwrite the input file", default=False)
 parser.add_argument("--indent", type=int, help="Indentation to use for the output file (default
1)", default=1)
-parser.add_argument("file", help="Input file(s)", nargs='*')
+parser.add_argument("file", help="Input file(s) - omit to use as filter", nargs='*')
 args = parser.parse_args()
 
 sorted = "unsorted" if args.nosort else "sorted"
 
 import sys
-if sys.hexversion < 0x030000F0:
+# Any files provided?
+if len(args.file) > 0:
+  if sys.hexversion < 0x030000F0:
     print("Using Python2 (adds trailing spaces), output will be " + sorted + ". Indent =
" + str(args.indent))
-else:
+  else:
     print("Using Python3 (strips trailing spaces), output will be " + sorted + ". Indent
= " + str(args.indent))
 import json
 
@@ -31,4 +33,9 @@ for arg in args.file:
             json.dump(input, f, indent=args.indent, sort_keys=sort_keys)
      # we catch exception so can continue to process other files
     except Exception as ex:
-        print(ex)
\ No newline at end of file
+        print(ex)
+
+# No inout files provided
+if len(args.file) == 0:
+    input = json.loads(sys.stdin.read())
+    json.dump(input, sys.stdout, indent=args.indent, sort_keys=sort_keys)



Mime
View raw message