delver/generate_md5sum_data.py

33 lines
813 B
Python

import os
import hashlib
from glob import glob
from pathlib import Path
import json
DELVER_PATH = './delver/'
def get_files_list(path):
"""Return *.dat files in directory and subdirectories"""
files = [y for x in os.walk(DELVER_PATH) for y in glob(os.path.join(x[0], '*.dat'))]
files_with_norm_path = list()
for file in files:
files_with_norm_path.append(file.replace(os.sep, '/'))
return files_with_norm_path
def calc_md5(file_path):
"""Return files MD5 sum"""
filebytes = Path(file_path).read_bytes()
md5sum = hashlib.md5(filebytes)
return md5sum.hexdigest()
if __name__ == '__main__':
files = get_files_list('./')
print('{')
for file in files:
print('"{path}" : "{sum}",'.format(
path=file, sum=calc_md5(file)))
print('}')