Last active
March 21, 2023 08:31
-
-
Save ioggstream/df31babf83543eb38c3e95b6acc3e761 to your computer and use it in GitHub Desktop.
Print differences between two zip/jar files.
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
import zipfile | |
import yaml | |
import sys | |
def zipdiff(z1, z2): | |
"""A function that compares the files of two zip files and returns a list of files that are result.""" | |
files1 = z1.namelist() | |
files2 = z2.namelist() | |
result = [] | |
for file in files1: | |
if file in files2: | |
if z1.read(file) != z2.read(file): | |
result.append((file, "different")) | |
continue | |
result.append((file, "same")) | |
else: | |
result.append((file, "file not in z2")) | |
for file in files2: | |
if file not in files1: | |
result.append((file, "file not in z1")) | |
return list(sorted(result)) | |
def main(f1, f2): | |
"""A test function that compares two zip files.""" | |
z1 = zipfile.ZipFile(f1, "r") | |
z2 = zipfile.ZipFile(f2, "r") | |
result = zipdiff(z1, z2) | |
print(yaml.safe_dump(result, indent=2, default_flow_style=False)) | |
return result | |
def test_main(): | |
result = main(f1, f2) | |
raise NotImplementedError | |
if __name__ == "__main__": | |
try: | |
progname, f1, f2 = sys.argv[0:3] | |
except IndexError: | |
print("Compare two zip/jar files: %s file1 file2" % (sys.argv[0],)) | |
main(f1, f2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment