forked from e1miran/Now-Playing-Serato
-
Notifications
You must be signed in to change notification settings - Fork 11
/
updateshas.py
executable file
·51 lines (40 loc) · 1.38 KB
/
updateshas.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
#!/usr/bin/env python3
''' build a new upgradetable.py '''
import hashlib
import json
import os
import pathlib
import sys
import subprocess
def checksum(filename):
''' generate sha512 '''
hashfunc = hashlib.sha512()
with open(filename, 'rb') as fileh:
while chunk := fileh.read(128 * hashfunc.block_size):
hashfunc.update(chunk)
return hashfunc.hexdigest()
def main():
''' build a new file '''
shafile = sys.argv[1]
oldshas = {}
if os.path.exists(shafile):
with open(shafile, encoding='utf-8') as fhin:
oldshas = json.loads(fhin.read())
for version in sys.argv[2:]:
subprocess.check_call(['git', 'checkout', '--force', version])
for apppath in pathlib.Path(os.path.join('nowplaying', 'templates')).iterdir():
filename = os.path.basename(apppath)
if filename not in oldshas:
oldshas[filename] = {}
hexd = checksum(apppath)
try:
for vers, sha in oldshas[filename].items(): # pylint: disable=unused-variable
if sha == hexd:
raise ValueError
except ValueError:
continue
oldshas[filename][version] = hexd
with open(shafile, 'w', encoding='utf-8') as fhout:
fhout.write(json.dumps(oldshas, indent=2))
if __name__ == '__main__':
main()