0

I need to compare the contents of two tar.gz files to if the files have been updated, changed or deleted.

The command suggested on Diff between two .tar.gz file lists in liunx Would help if I can get the result as a list or something I can iterate over and run regex.

diff <(tar -tvf 1.tar.gz | sort) <(tar -tvf 2.tar.gz | sort)

I tried using subprocess but I'm not sure how to translate the "<" which I learned are output redirects for tar and sort. I tried doing something like

file1 = subprocess.Popen(('tar', '-tvf', 1.tar.gz), stdout=subprocess.PIPE)
results_1 = file1.communicate()[0]
file2 = subprocess.Popen(('tar', '-tvf', 2.tar.gz), stdout=subprocess.PIPE)
results_2 = file1.communicate()[0]

diff = subprocess.Popen(['diff',results_1,results_2], stdout=subprocess.PIPE)

That starts priting one of the stdouts of first two commands and ends in

:File name too long

I also tried to run the entire command using the (apparently) unforgivable shell=True, but that gives me:

/bin/sh: -c: line 0: syntax error near unexpected token `('

I would like to use this using python 2.7 and/or not to exotic external libraries, but if python 3.X is requried or and entirely different way to check if files in two tar files are known to anybody, I'd like to hear it :)

  • Do you need to know which files have been updated, changed or deleted or it's enought to know that tar files are different ? – Yaroslav Surzhikov Sep 13 '17 at 04:34
  • the [subprocess tag info](https://stackoverflow.com/tags/subprocess/info) has the link to [Multiple pipes in subprocess](https://stackoverflow.com/q/28840575/4279) that implements `someprogram <(someprocess) <(anotherprocess)` bash command using `subprocess` module. – jfs Sep 13 '17 at 05:40

0 Answers0