up demo
This commit is contained in:
parent
153e9bd8f9
commit
6d755ee8dc
8 changed files with 1058 additions and 17 deletions
|
@ -10,15 +10,19 @@ from oedb.utils.logging import logger
|
|||
|
||||
def load_env_from_file():
|
||||
"""
|
||||
Load environment variables from .env file.
|
||||
Load environment variables from .env file at the project root directory.
|
||||
This ensures that database connection parameters are properly set.
|
||||
|
||||
Returns:
|
||||
bool: True if the .env file exists and was loaded, False otherwise.
|
||||
"""
|
||||
if os.path.exists('.env'):
|
||||
logger.info("Loading environment variables from .env file...")
|
||||
with open('.env', 'r') as f:
|
||||
# Determine the project root directory (parent directory of the oedb package)
|
||||
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))
|
||||
env_file_path = os.path.join(project_root, '.env')
|
||||
|
||||
if os.path.exists(env_file_path):
|
||||
logger.info(f"Loading environment variables from {env_file_path}...")
|
||||
with open(env_file_path, 'r') as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith('#'):
|
||||
|
@ -26,7 +30,7 @@ def load_env_from_file():
|
|||
os.environ[key] = value
|
||||
return True
|
||||
else:
|
||||
logger.warning(".env file not found")
|
||||
logger.warning(f".env file not found at {env_file_path}")
|
||||
return False
|
||||
|
||||
def db_connect():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue