echodict/llama.cpp
version https://git-lfs.github.com/spec/v1 oid sha256:cfc44b7ba25614df70e6b65e3341cae0310163bd32fd31a6b928a542df433faf size 30786
0773
1#!/usr/bin/env python32 3import logging4import os5import hashlib6 7logger = logging.getLogger("verify-checksum-models")8 9 10def sha256sum(file):11 block_size = 16 * 1024 * 1024 # 16 MB block size12 b = bytearray(block_size)13 file_hash = hashlib.sha256()14 mv = memoryview(b)15 with open(file, 'rb', buffering=0) as f:16 while True:17 n = f.readinto(mv)18 if not n:19 break20 file_hash.update(mv[:n])21 22 return file_hash.hexdigest()23 24 25# Define the path to the llama directory (parent folder of script directory)26llama_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))27 28# Define the file with the list of hashes and filenames29hash_list_file = os.path.join(llama_path, "SHA256SUMS")30 31# Check if the hash list file exists32if not os.path.exists(hash_list_file):33 logger.error(f"Hash list file not found: {hash_list_file}")34 exit(1)35 36# Read the hash file content and split it into an array of lines37with open(hash_list_file, "r") as f:38 hash_list = f.read().splitlines()39 40# Create an array to store the results41results = []42 43# Loop over each line in the hash list44for line in hash_list:45 # Split the line into hash and filename46 hash_value, filename = line.split(" ")47 48 # Get the full path of the file by joining the llama path and the filename49 file_path = os.path.join(llama_path, filename)50 51 # Informing user of the progress of the integrity check52 logger.info(f"Verifying the checksum of {file_path}")53 54 # Check if the file exists55 if os.path.exists(file_path):56 # Calculate the SHA256 checksum of the file using hashlib57 file_hash = sha256sum(file_path)58 59 # Compare the file hash with the expected hash60 if file_hash == hash_value:61 valid_checksum = "V"62 file_missing = ""63 else:64 valid_checksum = ""65 file_missing = ""66 else:67 valid_checksum = ""68 file_missing = "X"69 70 # Add the results to the array71 results.append({72 "filename": filename,73 "valid checksum": valid_checksum,74 "file missing": file_missing75 })76 77 78# Print column headers for results table79print("filename".ljust(40) + "valid checksum".center(20) + "file missing".center(20)) # noqa: NP10080print("-" * 80) # noqa: NP10081 82# Output the results as a table83for r in results:84 print(f"{r['filename']:40} {r['valid checksum']:^20} {r['file missing']:^20}") # noqa: NP10085 