forked from tera-toolbox/tera-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_manifest.py
33 lines (27 loc) · 932 Bytes
/
build_manifest.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
import os
import json
import hashlib
def is_blacklisted(file):
(head, tail) = os.path.split(os.path.normpath(file))
return any(head.startswith(dir) for dir in {
'.git',
'mods',
}) or file in {
'build_manifest.py',
'manifest.json',
'config.json',
}
def list_files(dir):
files = [os.path.normpath(os.path.join(root, f)).replace('\\', '/') for root, dirs, files in os.walk(dir) for f in files]
return [f for f in files if not is_blacklisted(f)]
def hash(files):
hashes = {}
for path in files:
with open(path, 'rb') as fh:
data = fh.read()
hashes[path] = hashlib.sha256(data).hexdigest()
return hashes
manifest = {'files': hash(list_files('./'))}
with open('manifest.json', 'w') as fh:
#fh.write(json.dumps(manifest).replace(' ', ''))
fh.write(json.dumps(manifest, indent=2)) # for better diff readability