diff --git a/src/Class_Mod/Hash.py b/src/Class_Mod/Hash.py index 8a96cbd6009e356e4b3011f35778de27d3e58a9c..fb4138405efa4abbffcb4377cf1062df9758290f 100644 --- a/src/Class_Mod/Hash.py +++ b/src/Class_Mod/Hash.py @@ -1,26 +1,30 @@ from Packages import * -def create_hash(spectra): +def create_hash(to_hash): #using the md5 hash function. hash_func = hashlib.md5() - spectra = str(spectra) - encoded_spectra = spectra.encode() - hash_func.update(encoded_spectra) + to_hash = str(to_hash) + encoded_to_hash = to_hash.encode() + hash_func.update(encoded_to_hash) hash = hash_func.hexdigest() return hash -def check_hash(hash): +def check_hash(hash, hash_type): # path to hash file and grep/cat functions for Win subprocess_path = Path("src/data/hash/") # run a grep from the hash onto the hash file - nb_hash = subprocess.run([subprocess_path / 'grep.exe', '-c', hash, subprocess_path / "hash.txt"], shell=True) + nb_hash = subprocess.run([subprocess_path / 'grep.exe', '-c', hash, subprocess_path / str(hash_type + ".txt")], shell=True) # if hash present if 'returncode=0' in str(nb_hash): return 'existing hash' - # if hash not present, add it to the file with cat function + # if hash not present else: - add_hash = subprocess.run(['echo', str(hash) + '>>', subprocess_path / "hash.txt"], shell=True) - if 'returncode=0' in str(add_hash): - return 'hash added' - else: - return 'error while adding the new hash' \ No newline at end of file + return 'missing hash' + +def add_hash(hash, hash_type): + # add it to the file with cat function + add_hash = subprocess.run(['echo', str(hash) + '>>', subprocess_path / str(hash_type + ".txt")], shell=True) + if 'returncode=0' in str(add_hash): + return 'hash added' + else: + return 'error while adding the new hash' \ No newline at end of file