1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import zipfile
- import filecmp
- import os
- import shutil
- def extract_jar(jar_path, extract_path):
- with zipfile.ZipFile(jar_path, 'r') as zip_ref:
- zip_ref.extractall(extract_path)
- def compare_dirs(dir1, dir2):
- comparison = filecmp.dircmp(dir1, dir2)
- if comparison.left_only or comparison.right_only or comparison.diff_files:
- return False
- else:
- for subdir in comparison.common_dirs:
- if not compare_dirs(os.path.join(dir1, subdir), os.path.join(dir2, subdir)):
- return False
- return True
- def compare_jars(jar1, jar2):
- temp_dir1 = 'temp_dir1'
- temp_dir2 = 'temp_dir2'
- # Extract jars
- extract_jar(jar1, temp_dir1)
- extract_jar(jar2, temp_dir2)
- # Compare directories
- are_same = compare_dirs(temp_dir1, temp_dir2)
- # Clean up temp directories
- shutil.rmtree(temp_dir1)
- shutil.rmtree(temp_dir2)
- return are_same
- # Test
- jar1 = '/Users/alvin/Downloads/tmp/rxdp-dm-tag-web.jar'
- jar2 = '/Users/alvin/Downloads/tmp/rxdp-dm-tag-web1.jar'
- print(compare_jars(jar1, jar2)) # If it prints True, jars are same; otherwise, jars are different.
|