Skip to content

Commit f7a615c

Browse files
committed
updating util hash create compare
1 parent 83728a5 commit f7a615c

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

‎llmware/util.py‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,8 @@ def file_checksum(fp, fn, hash_type="sha256"):
10161016
return hash_output
10171017

10181018
@staticmethod
1019-
def create_hash_stamp (fp, save=True, hash_fn="hash_record", hash_type="sha256", **kwargs):
1019+
def create_hash_stamp (fp, save=True, hash_fn="hash_record", hash_type="sha256",
1020+
ignore_file_extensions=None,**kwargs):
10201021

10211022
""" Creates Hash Stamp for all files in a folder.
10221023
@@ -1041,6 +1042,7 @@ def create_hash_stamp (fp, save=True, hash_fn="hash_record", hash_type="sha256",
10411042
fp_files = os.listdir(fp)
10421043

10431044
for file in fp_files:
1045+
10441046
if file == hash_full_name:
10451047

10461048
if save:
@@ -1050,8 +1052,15 @@ def create_hash_stamp (fp, save=True, hash_fn="hash_record", hash_type="sha256",
10501052
logging.warning(f"Utilities - create_hash_stamp - found existing hash_record with same name - "
10511053
f"attempting to create new hash record file with name - {hash_full_name}.")
10521054

1053-
hash_value = Utilities().file_checksum(fp, file, hash_type=hash_type)
1054-
hash_record.update({file: hash_value})
1055+
ignore = False
1056+
if ignore_file_extensions:
1057+
ft = file.split(".")[-1]
1058+
if ft.lower() in ignore_file_extensions or ft.upper() in ignore_file_extensions:
1059+
ignore = True
1060+
1061+
if not ignore:
1062+
hash_value = Utilities().file_checksum(fp, file, hash_type=hash_type)
1063+
hash_record.update({file: hash_value})
10551064

10561065
time_stamp = Utilities().get_current_time_now()
10571066

@@ -1073,7 +1082,8 @@ def create_hash_stamp (fp, save=True, hash_fn="hash_record", hash_type="sha256",
10731082
return full_record
10741083

10751084
@staticmethod
1076-
def compare_hash (fp, hash_fn="hash_record", hash_type="sha256", selected_files=None, ignore_pattern="hash"):
1085+
def compare_hash (fp, hash_fn="hash_record", hash_type="sha256", selected_files=None, ignore_pattern="hash",
1086+
ignore_file_extensions=None):
10771087

10781088
""" Compares two hashes from a folder path (fp) -
10791089
@@ -1097,12 +1107,13 @@ def compare_hash (fp, hash_fn="hash_record", hash_type="sha256", selected_files=
10971107
try:
10981108
hash_file = json.load(open(os.path.join(fp, hash_full_name), "r"))
10991109
except:
1100-
logger.warning(f"Utilities - compare_hash_record - could not find an existing hash file at: "
1110+
logger.debug(f"Utilities - compare_hash_record - could not find an existing hash file at: "
11011111
f"{os.path.join(fp, hash_full_name)}. Will create new hash record, but will not "
11021112
f"be able to provide a meaningful comparison.")
11031113
hash_file = {}
11041114

1105-
new_hash_record = Utilities().create_hash_stamp(fp, hash_fn=hash_fn, hash_type=hash_type, save=False)
1115+
new_hash_record = Utilities().create_hash_stamp(fp, hash_fn=hash_fn, hash_type=hash_type, save=False,
1116+
ignore_file_extensions=ignore_file_extensions)
11061117

11071118
# apply any pruning of certain files
11081119

@@ -1149,10 +1160,10 @@ def compare_hash (fp, hash_fn="hash_record", hash_type="sha256", selected_files=
11491160
confirmed.update({key:value})
11501161
confirmed_files.append(key)
11511162
else:
1152-
logger.warning(f"Utilities - compare_hash - value not matching for key - {key}")
1163+
logger.debug(f"Utilities - compare_hash - value not matching for key - {key}")
11531164
values_changed.append(key)
11541165
else:
1155-
logger.warning(f"Utilities - compare_hash - extra key - {key} - in hash_file not found in original hash")
1166+
logger.debug(f"Utilities - compare_hash - extra key - {key} - in hash_file not found in original hash")
11561167
extra_keys.append(key)
11571168

11581169
output_dict = {"hashed_file_count": hashed_item_count,

0 commit comments

Comments
 (0)