-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev_update_sha1.py
executable file
·38 lines (32 loc) · 1.08 KB
/
dev_update_sha1.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
#!/usr/bin/python3
# This script updates the ?sha1=... parameters in dependency references
import re
import subprocess
def sha1sum(file_path):
output = subprocess.run(['sha1sum', file_path], capture_output=True, text=True)
return output.stdout.split()[0]
def replace_ref(match):
file_name = match.group(1)
print(f' - {file_name}')
file_sha1sum = sha1sum(f'app/{file_name}')
return f'{file_name}?sha1={file_sha1sum}'
def update_refs(file_name):
print(file_name)
refs_re = r'([\w.-]+)\?sha1=[0-9a-f]+'
file_path = f'app/{file_name}'
with open(file_path, 'r', encoding='utf-8') as file:
file_contents = file.read()
file_contents = re.sub(refs_re, replace_ref, file_contents)
with open(file_path, 'w', encoding='utf-8') as file:
file.write(file_contents)
print()
update_refs('main.js')
update_refs('index.html')
update_refs('icon-normal.html')
update_refs('icon-notify.html')
update_refs('demo.html')
update_refs('demo-week.html')
update_refs('help.html')
update_refs('achievements.html')
update_refs('send.html')
update_refs('week.html')