20 lines
645 B
Python
20 lines
645 B
Python
import os
|
|
|
|
class EnvironmentService:
|
|
def __init__(self):
|
|
self.LINE_COMMENTED = '#'
|
|
self.VALUE_SEPARATOR = '='
|
|
|
|
def LoadEnvFile(self, filepath:str):
|
|
with open(filepath, 'r') as file:
|
|
for line in file:
|
|
line = line.strip()
|
|
if line and not line.startswith(self.LINE_COMMENTED) and self.VALUE_SEPARATOR in line:
|
|
key,value = line.split(self.VALUE_SEPARATOR, 1)
|
|
self.Set(key, value) # os.environ[key] = value
|
|
|
|
def Get(self, key:str):
|
|
return os.getenv(key)
|
|
|
|
def Set(self, key: str, value):
|
|
os.environ[key] = value |