add option to add filepath to the current session

This commit is contained in:
2025-03-26 14:00:30 +01:00
parent 6deda74a80
commit 72ede57a82
3 changed files with 66 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING, Final
import requests
@@ -26,17 +27,29 @@ class Session:
self,
base_headers: HttpContentHeaders,
) -> None:
self._data_path: Path | None = None
self._creds: ApiCredentials | None = None
self._base_url: str | None = None
self._headers = base_headers
self._session_token: str | None = None
self._logged_in: bool = False
@property
def data_path(self) -> Path:
assert self._data_path is not None, "accessed data path not set"
return self._data_path
@property
def creds(self) -> ApiCredentials:
assert self._creds is not None, "accessed credentials not set"
return self._creds
def set_data_path(
self,
path: str,
):
self._data_path = validate_path(path)
def set_credentials(
self,
username: str,
@@ -185,6 +198,18 @@ class Session:
return response, status
def validate_path(
str_path: str,
) -> Path:
path = Path(str_path).resolve()
if not path.exists():
raise FileNotFoundError(f"Provided path >{path}< seems not to exist.")
elif not path.is_dir():
raise FileNotFoundError(f"Provided path >{path}< seems not to be a directory.")
return path
def validate_credentials(
username: str,
password: str,

View File

@@ -11,6 +11,12 @@ from delta_barth.constants import HTTP_BASE_CONTENT_HEADERS
SESSION: Final[Session] = Session(HTTP_BASE_CONTENT_HEADERS)
def set_data_path(
path: str,
) -> None:
SESSION.set_data_path(path)
def set_credentials(
username: str,
password: str,
@@ -30,6 +36,7 @@ def get_credentials() -> str: # pragma: no cover
return creds.model_dump_json()
# ** legacy: not part of external API
def set_base_url(
base_url: str,
) -> None: # pragma: no cover