Created
January 29, 2013 18:47
-
-
Save bpowers/4666551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CANON=/tmp/canon.json | |
cat >$CANON <<EOF | |
#!/usr/bin/env python | |
import json | |
import os | |
import sys | |
def slurp(path): | |
''' | |
Return the contents of a file as a string. | |
Python 2.4 complient. | |
''' | |
try: | |
f = open(path) | |
text = f.read() | |
f.close() | |
return text.strip() | |
except: | |
print(exc_info()[1]) | |
exit(1) | |
def main(path): | |
obj = json.loads(slurp(path)) | |
with open(path, 'wb') as f: | |
f.write(json.dumps(obj, indent=2, sort_keys=True).replace(' \n', '\n')) | |
f.write('\n') | |
f.flush() | |
os.fsync(f) | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print >>sys.stderr, 'usage: %s FILE' % sys.argv[0] | |
exit(1) | |
exit(main(sys.argv[1])) | |
EOF | |
A="`mktemp`" | |
B="`mktemp`" | |
cat $1 >$A | |
cat $2 >$B | |
python $CANON $A | |
python $CANON $B | |
git diff --no-index --color=auto $A $B | |
rm -f $A $B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment