-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupEnv.py
47 lines (40 loc) · 1.43 KB
/
setupEnv.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
# set the home path in each script
import os
# get current working directory as home path
cwd = os.getcwd()
def main() :
# all the script need to replace the variable of home_path
all_scripts = ["query.py", "deployWordpress.py", "call_prom.py", "monitor/podCreate.py", "monitor/weirdPod.py"]
# rewrite all script
rewriteAllScripts(all_scripts)
# rewrite all script
def rewriteAllScripts(all_scripts) :
for script in all_scripts :
# open script
f = open(script, "r+")
file_content = f.readlines()
# find the variable of home_path in each line in the script
home_path_line = findHomePath(file_content)
# no vairable of home_path in the script
if home_path_line == -1 :
print(f"the home_path variable is not found in the {script}")
f.close()
else :
# set the new script content with home path
file_content[home_path_line] = f"home_path = '{cwd}'\n"
# clear the script content at first
f.truncate(0)
# no seek will add weird \x00 at the start
f.seek(0)
# write the home path into script
f.writelines(file_content)
f.close()
# find line index of home_path in the script
def findHomePath(file_content) :
index = 0
for line in file_content :
if "home_path" in line :
return index
index += 1
return -1
main()