-
Notifications
You must be signed in to change notification settings - Fork 68
/
_set_constants.py
49 lines (36 loc) · 1.2 KB
/
_set_constants.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
import shutil
import subprocess
import sys
with open('ahk/templates/daemon.ahk') as f:
daemon_script = f.read()
with open('ahk/templates/hotkeys.ahk') as hotkeyfile:
hotkey_script = hotkeyfile.read()
with open('ahk/templates/daemon-v2.ahk') as fv2:
daemon_script_v2 = fv2.read()
with open('ahk/templates/hotkeys-v2.ahk') as hotkeyfilev2:
hotkey_script_v2 = hotkeyfilev2.read()
GIT_EXECUTABLE = shutil.which('git')
if not GIT_EXECUTABLE:
raise RuntimeError('git executable not found')
new_contents = f'''\
# THIS FILE IS AUTOGENERATED BY _set_constants.py
# DO NOT EDIT BY HAND
DAEMON_SCRIPT_TEMPLATE = r"""{daemon_script}
"""
HOTKEYS_SCRIPT_TEMPLATE = r"""{hotkey_script}
"""
DAEMON_SCRIPT_V2_TEMPLATE = r"""{daemon_script_v2}
"""
HOTKEYS_SCRIPT_V2_TEMPLATE = r"""{hotkey_script_v2}
"""
'''
with open('ahk/_constants.py', encoding='utf-8') as f:
constants_text = f.read()
if constants_text != new_contents:
with open('ahk/_constants.py', 'w', encoding='utf-8') as f:
f.write(new_contents)
print('MODIFIED _constants.py', file=sys.stderr)
subprocess.run([GIT_EXECUTABLE, 'add', '--intent-to-add', 'ahk/_constants.py'])
raise SystemExit(1)
else:
raise SystemExit(0)