Skip to content

Instantly share code, notes, and snippets.

@koenbok
Created August 23, 2010 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koenbok/545743 to your computer and use it in GitHub Desktop.
Save koenbok/545743 to your computer and use it in GitHub Desktop.
import sys
import os
import filecmp
import subprocess
assert len(sys.argv) == 3, 'Usage: <script> path1 path2'
def run(command):
subprocess.call([command], shell=True)
class ChangeSet(object):
def __init__(self, path1, path2):
self.path1 = os.path.abspath(path1)
self.path2 = os.path.abspath(path2)
assert path1 != path2, 'Cannot compare same dictionaries'
assert os.path.isdir(path1), '%s is not a directory' % path1
assert os.path.isdir(path2), '%s is not a directory' % path2
self.added = []
self.deleted = []
self.modified = []
self.parse(path1, path2)
def parse(self, path1, path2):
compare = filecmp.dircmp(path1, path2)
j = os.path.join
self.added.extend(map(lambda f: j(path2, f), compare.right_only))
self.deleted.extend(map(lambda f: j(path1, f), compare.left_only))
self.modified.extend(map(lambda f: (j(path1, f), j(path2, f)), compare.diff_files))
map(lambda x: self.parse(os.path.join(path1, x), os.path.join(path2, x)), compare.common_dirs)
cs = ChangeSet(sys.argv[1], sys.argv[2])
# I HAVE NO CLUE HOW TO MARK FILES AS ADDED/DELETED
print 'Added:'
for f in cs.added:
print '%s' % f
# run('ksdiff %s --label=A' % f)
print 'Deleted:'
for f in cs.deleted:
print '%s' % f
# run('ksdiff %s --label=D' % f)
print 'Modified:'
for f in cs.modified:
print '%s -> %s' % f
run('ksdiff %s %s' % f)
# run('ksdiff-wrapper git \"%s" \"%s\"' % (cs.path1, cs.path2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment