add file exists check to load_json_to_environ
This commit is contained in:
parent
050d8cde38
commit
db70a49bad
1 changed files with 9 additions and 2 deletions
|
|
@ -7,6 +7,8 @@ from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.parse import urlunparse
|
from urllib.parse import urlunparse
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BaseUrl:
|
class BaseUrl:
|
||||||
|
|
@ -28,7 +30,7 @@ def get_datetime_string() -> str:
|
||||||
return current_datetime.strftime("%Y-%m-%d-%H-%M-%S")
|
return current_datetime.strftime("%Y-%m-%d-%H-%M-%S")
|
||||||
|
|
||||||
|
|
||||||
def rmtree(root_dir: Path):
|
def rmtree(root_dir: Path) -> None:
|
||||||
"""removes a folder with content recursively"""
|
"""removes a folder with content recursively"""
|
||||||
if not root_dir.is_dir():
|
if not root_dir.is_dir():
|
||||||
return
|
return
|
||||||
|
|
@ -50,8 +52,13 @@ def generate_random_string(length: int, punctuation=False) -> str:
|
||||||
return random_string
|
return random_string
|
||||||
|
|
||||||
|
|
||||||
def load_json_to_environ(cred_file: Path):
|
def load_json_to_environ(cred_file: Path) -> None:
|
||||||
"""Load the contents of a json file directly into os.environ. Variable names are inherited"""
|
"""Load the contents of a json file directly into os.environ. Variable names are inherited"""
|
||||||
|
|
||||||
|
if not cred_file.is_file():
|
||||||
|
logger.warning(f"{cred_file} could not be found, no credentials loaded")
|
||||||
|
return
|
||||||
|
|
||||||
with open(cred_file, "r") as f:
|
with open(cred_file, "r") as f:
|
||||||
CREDENTIALS = json.load(f)
|
CREDENTIALS = json.load(f)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue