community-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1867575 - /comdev/reporter.apache.org/trunk/scripts/prettify.py
Date Thu, 26 Sep 2019 13:45:34 GMT
Author: sebb
Date: Thu Sep 26 13:45:34 2019
New Revision: 1867575

URL: http://svn.apache.org/viewvc?rev=1867575&view=rev
Log:
Extract common dump code

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=1867575&r1=1867574&r2=1867575&view=diff
==============================================================================
--- comdev/reporter.apache.org/trunk/scripts/prettify.py (original)
+++ comdev/reporter.apache.org/trunk/scripts/prettify.py Thu Sep 26 13:45:34 2019
@@ -25,6 +25,9 @@ if len(args.file) > 0:
 
 sort_keys = not args.nosort
 
+def dump(input, file):
+    json.dump(input, file, indent=args.indent, sort_keys=sort_keys, ensure_ascii=False)
+
 for arg in args.file:
     print("Reading " + arg)
     input = {}
@@ -35,18 +38,18 @@ for arg in args.file:
         print("Writing " + out)
         if python2:
             with open(out, "w") as f:
-                json.dump(input, f, indent=args.indent, sort_keys=sort_keys, ensure_ascii=False)
+                dump(input, f)
         else:
             with open(out, "w", encoding='utf-8') as f:
-                json.dump(input, f, indent=args.indent, sort_keys=sort_keys, ensure_ascii=False)
+                dump(input, f)
      # we catch exception so can continue to process other files
     except Exception as ex:
         print(ex)
 
-# No inout files provided
+# No input files provided, work as filter
 if len(args.file) == 0:
     try:
         input = json.loads(sys.stdin.buffer.read().decode('UTF-8', errors='replace'))
     except AttributeError:
         input = json.loads(sys.stdin.read().decode('UTF-8', errors='replace'))
-    json.dump(input, sys.stdout, indent=args.indent, sort_keys=sort_keys, ensure_ascii=False)
+    dump(input, sys.stdout)



Mime
View raw message