diff --git a/inject.rb b/inject.rb index 9ed9128..23fe4fe 100755 --- a/inject.rb +++ b/inject.rb @@ -3,6 +3,7 @@ require 'rubygems' require 'json' require 'fileutils' +require 'stringio' def inject FileUtils.cp_r(mojo_ext_path, target_mojo_ext_path) @@ -27,9 +28,15 @@ def sources_file end def save_sources! + # capture pretty-print output to string + pretty_json = StringIO.new + orig_stdout = $stdout + $stdout = pretty_json + jj sources + $stdout = orig_stdout + pretty_json.rewind() FileUtils.mv(sources_file, File.join(project_path, 'sources.json-backup')) - File.open(sources_file, 'w') {|f| f.puts(sources.to_json)} - `./prettyprint.py "#{sources_file}" "#{sources_file}"` + File.open(sources_file, 'w') {|f| f.puts(pretty_json.read)} end def project_path diff --git a/prettyprint.py b/prettyprint.py deleted file mode 100755 index c3ce629..0000000 --- a/prettyprint.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env python - -""" -Convert JSON data to human-readable form. - -Usage: - prettyJSON.py inputFile [outputFile] -""" - -import sys -import simplejson as json - - -def main(args): - try: - inputFile = open(args[1]) - input = json.load(inputFile) - inputFile.close() - except IndexError: - usage() - return False - if len(args) < 3: - print json.dumps(input, sort_keys = False, indent = 4) - else: - outputFile = open(args[2], "w") - json.dump(input, outputFile, sort_keys = False, indent = 4) - outputFile.close() - return True - - -def usage(): - print __doc__ - - -if __name__ == "__main__": - sys.exit(not main(sys.argv))