fix: load env
This commit is contained in:
parent
00b048f177
commit
98d4db67ea
|
@ -8,6 +8,7 @@ import re
|
||||||
from typing import Set, Dict
|
from typing import Set, Dict
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
@ -21,11 +22,21 @@ logging.basicConfig(
|
||||||
|
|
||||||
def load_env_vars() -> tuple[Path, Path]:
|
def load_env_vars() -> tuple[Path, Path]:
|
||||||
"""Load environment variables and return source and destination directories."""
|
"""Load environment variables and return source and destination directories."""
|
||||||
|
# Load .env file from the same directory as the script
|
||||||
|
script_dir = Path(__file__).parent.parent
|
||||||
|
env_path = script_dir / '.env'
|
||||||
|
|
||||||
|
if not env_path.exists():
|
||||||
|
logging.error(f".env file not found at {env_path}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
load_dotenv(env_path)
|
||||||
|
|
||||||
source_dir = os.getenv('SOURCE_DIR')
|
source_dir = os.getenv('SOURCE_DIR')
|
||||||
dest_dir = os.getenv('DEST_DIR')
|
dest_dir = os.getenv('DEST_DIR')
|
||||||
|
|
||||||
if not source_dir or not dest_dir:
|
if not source_dir or not dest_dir:
|
||||||
logging.error("SOURCE_DIR and DEST_DIR must be set in environment variables")
|
logging.error("SOURCE_DIR and DEST_DIR must be set in .env file")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Expand environment variables like $HOME
|
# Expand environment variables like $HOME
|
||||||
|
|
Loading…
Reference in New Issue