move stuff to Envmanager
This commit is contained in:
parent
d40ae79991
commit
8835243577
2 changed files with 36 additions and 36 deletions
|
|
@ -1,28 +1,18 @@
|
|||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from dotenv import dotenv_values
|
||||
from loguru import logger
|
||||
|
||||
from src.dirmanager import DirManager
|
||||
from src.env_file_helper import DependencyRule, EnvFile, sort_env_files_by_rule
|
||||
from src.env_manager import EnvFile, EnvManager
|
||||
from src.html_helper import merge_html_files
|
||||
from src.runner import Runner
|
||||
from src.tests_authentik.runner_authentik import RunnerAuthentik
|
||||
from src.tests_nextcloud.runner_nextcloud import RunnerNextcloud
|
||||
from src.tests_wordpress.runner_wordpress import RunnerWordpress
|
||||
from src.utils import rmtree
|
||||
|
||||
# Register all runners here. Each .env file with TYPE=authentik will be run with RunnerAuthentik
|
||||
RUNNER_DICT: dict[str, type[Runner]] = {
|
||||
"authentik": RunnerAuthentik,
|
||||
"wordpress": RunnerWordpress,
|
||||
"nextcloud": RunnerNextcloud,
|
||||
}
|
||||
|
||||
|
||||
class Coordinator:
|
||||
def __init__(self, env_paths_list: list[Path], output_dir: Path, session_id: str) -> None:
|
||||
# logging
|
||||
out_string = "".join([e.name + "\n" for e in env_paths_list])
|
||||
out_string += f"output_dir = {output_dir}\n"
|
||||
out_string += f"session_id = {session_id}"
|
||||
|
|
@ -33,30 +23,9 @@ class Coordinator:
|
|||
self.session_id = session_id
|
||||
|
||||
# parse env files
|
||||
self.env_files: list[EnvFile] = self._getn_env_files_list(env_paths_list)
|
||||
self.dependency_rules: list[DependencyRule] = self._get_dependency_rules(self.env_files)
|
||||
|
||||
@staticmethod
|
||||
def _getn_env_files_list(env_paths: list[Path]) -> list[EnvFile]:
|
||||
"""Returns a list of EnvFile objects created from the given env files"""
|
||||
env_files: list[EnvFile] = []
|
||||
for env_path in env_paths:
|
||||
assert env_path.is_file(), f"the env file {env_path} does not exist"
|
||||
config: dict[str, str] = dotenv_values(env_path) # type: ignore
|
||||
assert "TYPE" in config, f"the env file {env_path} does not specify the required TYPE key."
|
||||
env_type = config["TYPE"]
|
||||
env_files.append(EnvFile(env_path=env_path, config=config, env_type=env_type))
|
||||
return env_files
|
||||
|
||||
@staticmethod
|
||||
def _get_dependency_rules(env_files: list[EnvFile]) -> list[DependencyRule]:
|
||||
dependency_rules: list[DependencyRule] = []
|
||||
for env_file in env_files:
|
||||
child_runner_class = RUNNER_DICT[env_file.env_type]
|
||||
for dependency in child_runner_class.dependencies:
|
||||
dependency_rule = DependencyRule(child=child_runner_class.name, dependency=dependency.name)
|
||||
dependency_rules.append(dependency_rule)
|
||||
return dependency_rules
|
||||
# self.env_files: list[EnvFile] = self._getn_env_files_list(env_paths_list)
|
||||
# self.dependency_rules: list[DependencyRule] = self._get_dependency_rules(self.env_files)
|
||||
self.ENV = EnvManager(env_paths_list)
|
||||
|
||||
def setup_test(self) -> None:
|
||||
logger.info("calling setup_test()")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
from pathlib import Path
|
||||
from typing import NamedTuple
|
||||
|
||||
from dotenv import dotenv_values
|
||||
from loguru import logger
|
||||
|
||||
|
||||
class EnvFile(NamedTuple):
|
||||
env_path: Path
|
||||
|
|
@ -56,3 +59,31 @@ def sort_env_files_by_rule(env_list: list[EnvFile], rules: list[DependencyRule])
|
|||
raise ValueError(
|
||||
"Could not resolve test order. This is possibly due to a circular dependency (a on b, b on c, c on a)"
|
||||
)
|
||||
|
||||
|
||||
class EnvManager:
|
||||
def __init__(self, env_paths_list: list[Path]):
|
||||
self.env_files: list[EnvFile] = self._getn_env_files_list(env_paths_list)
|
||||
self.dependency_rules: list[DependencyRule] = self._get_dependency_rules(self.env_files)
|
||||
|
||||
@staticmethod
|
||||
def _getn_env_files_list(env_paths: list[Path]) -> list[EnvFile]:
|
||||
"""Returns a list of EnvFile objects created from the given env files"""
|
||||
env_files: list[EnvFile] = []
|
||||
for env_path in env_paths:
|
||||
assert env_path.is_file(), f"the env file {env_path} does not exist"
|
||||
config: dict[str, str] = dotenv_values(env_path) # type: ignore
|
||||
assert "TYPE" in config, f"the env file {env_path} does not specify the required TYPE key."
|
||||
env_type = config["TYPE"]
|
||||
env_files.append(EnvFile(env_path=env_path, config=config, env_type=env_type))
|
||||
return env_files
|
||||
|
||||
@staticmethod
|
||||
def _get_dependency_rules(env_files: list[EnvFile]) -> list[DependencyRule]:
|
||||
dependency_rules: list[DependencyRule] = []
|
||||
for env_file in env_files:
|
||||
child_runner_class = RUNNER_DICT[env_file.env_type]
|
||||
for dependency in child_runner_class.dependencies:
|
||||
dependency_rule = DependencyRule(child=child_runner_class.name, dependency=dependency.name)
|
||||
dependency_rules.append(dependency_rule)
|
||||
return dependency_rules
|
||||
Loading…
Add table
Add a link
Reference in a new issue