Batch upload - simple_compare.py
Browse files- scripts/simple_compare.py +81 -0
scripts/simple_compare.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Simple script to compare two .bin files for exact equality.
|
| 4 |
+
Usage: python simple_compare.py file1.bin file2.bin
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
import hashlib
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def compare_bin_files(file1, file2):
|
| 13 |
+
"""Compare two .bin files for exact equality"""
|
| 14 |
+
|
| 15 |
+
# Check if files exist
|
| 16 |
+
if not os.path.exists(file1):
|
| 17 |
+
print(f"❌ File 1 does not exist: {file1}")
|
| 18 |
+
return False
|
| 19 |
+
|
| 20 |
+
if not os.path.exists(file2):
|
| 21 |
+
print(f"❌ File 2 does not exist: {file2}")
|
| 22 |
+
return False
|
| 23 |
+
|
| 24 |
+
# Get file sizes
|
| 25 |
+
size1 = os.path.getsize(file1)
|
| 26 |
+
size2 = os.path.getsize(file2)
|
| 27 |
+
|
| 28 |
+
print(f"File 1: {file1} ({size1:,} bytes)")
|
| 29 |
+
print(f"File 2: {file2} ({size2:,} bytes)")
|
| 30 |
+
|
| 31 |
+
# Quick size check
|
| 32 |
+
if size1 != size2:
|
| 33 |
+
print(f"❌ Files have different sizes: {size1:,} vs {size2:,}")
|
| 34 |
+
return False
|
| 35 |
+
|
| 36 |
+
# Calculate hashes
|
| 37 |
+
print("Calculating hashes...")
|
| 38 |
+
hash1 = hashlib.sha256()
|
| 39 |
+
hash2 = hashlib.sha256()
|
| 40 |
+
|
| 41 |
+
with open(file1, 'rb') as f1, open(file2, 'rb') as f2:
|
| 42 |
+
while True:
|
| 43 |
+
chunk1 = f1.read(8192) # 8KB chunks
|
| 44 |
+
chunk2 = f2.read(8192)
|
| 45 |
+
|
| 46 |
+
if not chunk1 and not chunk2:
|
| 47 |
+
break # Both files ended
|
| 48 |
+
|
| 49 |
+
if chunk1:
|
| 50 |
+
hash1.update(chunk1)
|
| 51 |
+
if chunk2:
|
| 52 |
+
hash2.update(chunk2)
|
| 53 |
+
|
| 54 |
+
hash1_hex = hash1.hexdigest()
|
| 55 |
+
hash2_hex = hash2.hexdigest()
|
| 56 |
+
|
| 57 |
+
print(f"File 1 hash: {hash1_hex}")
|
| 58 |
+
print(f"File 2 hash: {hash2_hex}")
|
| 59 |
+
|
| 60 |
+
if hash1_hex == hash2_hex:
|
| 61 |
+
print("✅ Files are identical")
|
| 62 |
+
return True
|
| 63 |
+
else:
|
| 64 |
+
print("❌ Files are different")
|
| 65 |
+
return False
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def main():
|
| 69 |
+
if len(sys.argv) != 3:
|
| 70 |
+
print("Usage: python simple_compare.py file1.bin file2.bin")
|
| 71 |
+
sys.exit(1)
|
| 72 |
+
|
| 73 |
+
file1 = sys.argv[1]
|
| 74 |
+
file2 = sys.argv[2]
|
| 75 |
+
|
| 76 |
+
result = compare_bin_files(file1, file2)
|
| 77 |
+
sys.exit(0 if result else 1)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
main()
|