Skip to content

Instantly share code, notes, and snippets.

@JustinAzoff
Last active September 17, 2015 15:16
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 JustinAzoff/91e70ab98b1944483501 to your computer and use it in GitHub Desktop.
Save JustinAzoff/91e70ab98b1944483501 to your computer and use it in GitHub Desktop.
Diff a tar file with the current contents on the filesystem
#!/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