forked from Polygant/OpenCEX-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_hash.py
More file actions
31 lines (23 loc) · 685 Bytes
/
check_hash.py
File metadata and controls
31 lines (23 loc) · 685 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import hashlib
import os
import sys
def main(name):
with open(name, 'rb') as fl:
hash_str = hashlib.md5(fl.read()).hexdigest()
hash_file_name = f'{name}.hash'
if not os.path.exists(hash_file_name):
with open(hash_file_name, 'w') as fl:
fl.write(hash_str)
print('updated')
else:
with open(hash_file_name, 'r') as fl:
stored_hash = fl.read()
if stored_hash == hash_str:
exit(0)
else:
with open(hash_file_name, 'w') as fl:
fl.write(hash_str)
print('updated')
exit(0)
if __name__ == '__main__':
main(sys.argv[1])