-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_test_terraform.py
More file actions
51 lines (44 loc) · 2.56 KB
/
Copy pathgenerate_test_terraform.py
File metadata and controls
51 lines (44 loc) · 2.56 KB
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
from os import mkdir, path
from shutil import copyfile
def convert_file(original_file_path, new_file_path):
with open(original_file_path, "r") as original_file:
lines = original_file.readlines()
with open(new_file_path, "w") as new_file:
# warn that this file is auto-generated
new_file.write("# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\
# !!!!!!!!! THIS FILE IS AUTO-GENERATED BY generate_test_terraform.py !!!!!!!!!\n\
# !!!!!!!!!!!!!!!!!!!!!!!!!! EDITS WILL NOT BE SAVED !!!!!!!!!!!!!!!!!!!!!!!!!!\n\
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n")
# make sure every edit is made exactly once
edits_made = {
"code_file_path_sha1": False,
"zipped_code_local": False,
"unstable": False,
}
for line in lines:
if 'source_code_sha1 = sha1(join("", [for f in local.code_files : filesha1(f)]))' in line:
if edits_made["code_file_path_sha1"]:
raise Exception("code_file_path_sha1 was already edited")
edits_made["code_file_path_sha1"] = True
new_file.write(line.replace("filesha1(f)", 'filesha1("../${f}")'))
elif "command = \"zip -r ${local.zipped_code_local} ${join(\" \", local.code_files)}\"" in line:
if edits_made["zipped_code_local"]:
raise Exception("zipped_code_local was already edited")
edits_made["zipped_code_local"] = True
new_file.write(line.replace("\"zip -r ${local.zipped_code_local} ${join(\" \", local.code_files)}\"", "\"${join(\"\", [for f in local.code_files : \"cp ../${f} . &&\"])} zip -r ${local.zipped_code_local} ${join(\" \", local.code_files)}\""))
elif "name = \"gptathome\"" in line:
if edits_made["unstable"]:
raise Exception("unstable was already edited")
edits_made["unstable"] = True
new_file.write(line.replace("\"gptathome\"", "\"gptathome-unstable\""))
else:
new_file.write(line)
for key in edits_made:
if not edits_made[key]:
raise Exception(f"{key} was not edited")
# create .test_env if it doesn't already exist
if not path.exists(".test_env"):
mkdir(".test_env")
convert_file("cloud_function.tf", ".test_env/cloud_function_unstable.tf")
# copy the file commands.json from the root directory to the .test_env directory
copyfile("commands.json", ".test_env/commands.json")