MCPcopy
hub / github.com/agent0ai/agent-zero / save_dotenv_value

Function save_dotenv_value

helpers/dotenv.py:24–43  ·  view source on GitHub ↗
(key: str, value: str)

Source from the content-addressed store, hash-verified

22 return os.getenv(key, default)
23
24def save_dotenv_value(key: str, value: str):
25 if value is None:
26 value = ""
27 dotenv_path = get_dotenv_file_path()
28 if not os.path.isfile(dotenv_path):
29 with open(dotenv_path, "w") as f:
30 f.write("")
31 with open(dotenv_path, "r+") as f:
32 lines = f.readlines()
33 found = False
34 for i, line in enumerate(lines):
35 if re.match(rf"^\s*{key}\s*=", line):
36 lines[i] = f"{key}={value}\n"
37 found = True
38 if not found:
39 lines.append(f"\n{key}={value}\n")
40 f.seek(0)
41 f.writelines(lines)
42 f.truncate()
43 load_dotenv()

Callers 2

__init__Method · 0.90
set_timezoneMethod · 0.90

Calls 5

get_dotenv_file_pathFunction · 0.85
load_dotenvFunction · 0.85
matchMethod · 0.80
openFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected