123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- import logging
- from pathlib import Path
- from typing import List
- import arklog
- import sys
- from signal import SIGINT, SIGTERM, signal
- import dacite
- import toml
- from graph_exploring_tool import __version__
- from graph_exploring_tool.graphical.interface import interface
- from graph_exploring_tool.query import QueryTemplate
- def handler(signal_code, _) -> None:
- """Signal handler."""
- logging.debug(f"Shutting down because signal {signal_code} was received.")
- sys.exit(5)
- def load_palette(palette_directory: Path) -> List:
- """"""
- for query_path in palette_directory.rglob("*.toml"):
- logging.debug(f"Loading palette query '{query_path}'.")
- query_configuration = toml.loads(query_path.read_text(encoding="utf-8"))
- yield dacite.from_dict(data_class=QueryTemplate, data=query_configuration)
- def launch():
- """"""
- signal(SIGINT, handler)
- signal(SIGTERM, handler)
- arklog.set_config_logging()
- logging.info(f"GET {__version__}.")
- data_dir = Path(__file__).resolve().parent.parent / Path("data")
- logging.debug(f"Looking for configuration in '{data_dir}'.")
- try:
- configuration = toml.loads((data_dir / Path("configuration.toml")).read_text(encoding="utf-8"))
- except FileNotFoundError as e:
- logging.error(f"Configuration not found. {e}")
- return 8
- endpoint_fuseki = configuration.get("endpoint_fuseki", "http://127.0.0.1:3030/Drivetrain/sparql")
- example_prefix = configuration.get("example_prefix", "")
- example_query = configuration.get("example_query", "")
- logging.debug("Parameters:")
- logging.debug(f" -> {endpoint_fuseki=}")
- logging.debug(f" -> {example_prefix=}")
- logging.debug(f" -> {example_query=}")
- palette = load_palette(data_dir / Path("palette"))
- return interface(endpoint=endpoint_fuseki, example_prefix=example_prefix, example_query=example_query, palette=palette)
- if __name__ == "__main__":
- launch()
|