-
Notifications
You must be signed in to change notification settings - Fork 229
Expand file tree
/
Copy pathci.env.py
More file actions
31 lines (25 loc) · 951 Bytes
/
ci.env.py
File metadata and controls
31 lines (25 loc) · 951 Bytes
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
import os
from pathlib import Path
def upsert_property(lines, key, value):
target = f"{key}="
replaced = False
new_lines = []
for line in lines:
if line.startswith(target):
new_lines.append(f"{target}{value}\n")
replaced = True
else:
new_lines.append(line)
if not replaced and value:
new_lines.append(f"{target}{value}\n")
return new_lines
def main():
app_id = os.environ.get("AGORA_APP_ID", "")
app_cert = os.environ.get("AGORA_APP_CERT", "") or os.environ.get("AGORA_APP_CERTIFICATE", "")
local_properties = Path("./local.properties")
lines = local_properties.read_text().splitlines(keepends=True) if local_properties.exists() else []
lines = upsert_property(lines, "AGORA_APP_ID", app_id)
lines = upsert_property(lines, "AGORA_APP_CERT", app_cert)
local_properties.write_text("".join(lines))
if __name__ == "__main__":
main()