-
Notifications
You must be signed in to change notification settings - Fork 0
/
sha256_writer.py
53 lines (40 loc) · 1.19 KB
/
sha256_writer.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import hashlib
import json
import sys
def get_file_sha265(hashing_file_path: str) -> str:
"""
Compare SHA256
:param source_hash: hash value
:param hashing_file_path: file
:return:
"""
hash_ = hashlib.sha256()
with open(hashing_file_path, 'rb') as hashing_file:
while True:
data = hashing_file.read(65536)
if not data:
break
hash_.update(data)
hash_digest = hash_.hexdigest()
return hash_digest
def main():
file_name_ids = {
'miner-config': 'acryl.conf.sample',
'node-service-package': 'Acryl-node-services.tar.gz',
'node-service-config': 'config.json',
'executable': 'acryl.jar',
'node-services-source-list': 'acryl-node-sources.list'
}
file_hashes = dict.fromkeys(file_name_ids, '')
for file_id, file_name in file_name_ids.items():
sha256_value = get_file_sha265(file_name)
file_hashes[file_id] = sha256_value
with open('versions.json', 'r') as version_file:
old_data = json.load(version_file)
for hash_file_name, hash_value in file_hashes.items():
old_data[hash_file_name]["sha256"] = hash_value
with open('versions.json', 'w') as version_file:
json.dump(old_data, version_file, indent=4)
return
if __name__ == "__main__":
sys.exit(main())