-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCreateServiceFiles.py
executable file
·40 lines (33 loc) · 1.2 KB
/
CreateServiceFiles.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
#!/usr/bin/env python3
# This script geenrates prepares the correct service files for use by systemd
# based on your configuration settings in TCMConstants.py
import os
import re
import TCMConstants
replacements = {
"FILEBROWSER_PATH" : TCMConstants.FILEBROWSER_PATH,
"SSD_MOUNT_POINT" : TCMConstants.SSD_MOUNT_POINT,
"PROJECT_PATH" : TCMConstants.PROJECT_PATH,
"PROJECT_USER" : TCMConstants.PROJECT_USER
}
def main():
process_service_file('tcm.service')
process_service_file('tcm-loadSSD.service')
process_service_file('tcm-mergeTeslaCam.service')
process_service_file('tcm-uploadDrive.service')
process_service_file('tcm-startFileBrowser.service')
process_service_file('tcm-removeOld.service')
process_service_file('tcm-downloadTC.service')
def process_service_file(name):
if os.path.isfile(name):
with open(name, "rt") as fin:
with open(name + ".tmp", "wt") as fout:
for line in fin:
fout.write(do_replacements(line))
os.rename(name + ".tmp", name)
def do_replacements(line):
substrs = sorted(replacements, key=len, reverse=True)
regexp = re.compile('|'.join(map(re.escape, substrs)))
return regexp.sub(lambda match: replacements[match.group(0)], line)
if __name__ == '__main__':
main()