Skip to content

Instantly share code, notes, and snippets.

@luqmaan
Last active August 29, 2015 14:25
Show Gist options
  • Save luqmaan/3c6550192baef671997a to your computer and use it in GitHub Desktop.
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.
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