Last active
September 17, 2015 15:16
-
-
Save JustinAzoff/91e70ab98b1944483501 to your computer and use it in GitHub Desktop.
Diff a tar file with the current contents on the filesystem
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
#!/usr/bin/env python | |
import difflib | |
import sys | |
import tarfile | |
def read(fn): | |
with open(fn) as f: | |
return f.readlines() | |
def tardiff(fn): | |
tf = tarfile.open(fn) | |
for ti in tf: | |
if not ti.isreg(): | |
continue | |
orig = tf.extractfile(ti) | |
orig_contents = orig.readlines() | |
cur_contents = read(ti.name) | |
if orig_contents == cur_contents: | |
continue | |
#print ti.name, 'is diff' | |
for line in difflib.unified_diff(orig_contents, cur_contents, fromfile='a/' + ti.name, tofile='b/' + ti.name): | |
sys.stdout.write(line) | |
if __name__ == "__main__": | |
tardiff(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment