Last active
August 29, 2015 14:25
-
-
Save luqmaan/3c6550192baef671997a to your computer and use it in GitHub Desktop.
Call kaleidoscope from python. Useful for diffing/comparing two dictionaries. I do this sometimes in nosetests.
This file contains hidden or 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
def ksdiff(a, b): | |
import subprocess | |
import os | |
if not os.path.exists('/usr/local/bin/ksdiff'): | |
raise Exception('where is ur ksdiff m8') | |
else: | |
a_path = '/tmp/ksdiff_a.txt' | |
b_path = '/tmp/ksdiff_b.txt' | |
with open(a_path, 'w') as fh: | |
fh.write(str(a)) | |
with open(b_path, 'w') as fh: | |
fh.write(str(b)) | |
command = '/usr/local/bin/ksdiff --diff {} {}'.format(a_path, b_path) | |
return subprocess.call(command, shell=True) | |
def ksdiffjson(a, b): | |
a = json.dumps(a, indent=4, sort_keys=True) | |
b = json.dumps(b, indent=4, sort_keys=True) | |
return ksdiff(a, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment