def _load_local_checksum_data() -> dict: if os.path.isfile(path_finder.get_local_checksums_path()) != True: _create_dummy_checksum_data_file() with open(path_finder.get_local_checksums_path()) as local_checksums_file: data_as_dict = toml.load(local_checksums_file) return data_as_dict
def _update_checksum_entry(entry, local_checksum_data): file_path = os.path.join(path_finder.get_nwn_path(), entry["target_dir"]) file_path = os.path.join(file_path, entry["name"]) print("Doing checksum for: ", entry["name"]) # Skip generating a checksum for portraits, since there's so bloody many of them! checksum = "portrait" if entry["target_dir"] != "portraits": checksum = _generate_file_md5(file_path) else: return print ("Checksum: ", checksum) modified_at = time.ctime(os.path.getmtime(file_path)) print ("Modified at: ", modified_at) checksum_entry = {} checksum_entry["name"] = entry["name"] checksum_entry["checksum"] = checksum checksum_entry["modified"] = modified_at found_entry = False if checksum_entry["name"] in local_checksum_data: found_entry = True local_checksum_data[checksum_entry["name"]]["checksum"] = checksum_entry["checksum"] if found_entry == False: local_checksum_data[checksum_entry["name"]] = checksum_entry f = open(path_finder.get_local_checksums_path(),'w') f.write(toml.dumps(local_checksum_data)) f.flush() f.close() return checksum_entry
def _create_dummy_checksum_data_file(): f = open(path_finder.get_local_checksums_path(),'w+') print("Creating dummy checksum data file..") f.write('[files]\n') f.close()