refactor: remove controller and multiple execution routes

This commit is contained in:
Thomas Bishop 2025-10-18 18:21:58 +01:00
parent ddbd2225cc
commit 84fe1a0480
4 changed files with 25 additions and 48 deletions

View file

@ -1,38 +1,42 @@
import argparse
from constants import EOLAS_DIRECTORY
from controllers.controller import Controller
from services.database_service import DatabaseService
from services.parse_file_service import ParseFileService
from services.table_service import TableService
database_service = DatabaseService("eolas")
database_connection = database_service.connect()
table_service = TableService(database_connection)
parse_file_service = ParseFileService(EOLAS_DIRECTORY)
controller = Controller(database_service, table_service, parse_file_service)
def main():
parser = argparse.ArgumentParser(
prog="eolas-db", description="Eolas database manager."
prog="eolas-db", description="Eolas database generator."
)
parser.add_argument(
"command",
choices=["populate-database"],
help="Command to execute",
"--source",
type=str,
required=True,
help="Source directory for markdown files",
)
parser.add_argument(
"--target",
type=str,
required=True,
help="Output path for SQLite database file",
)
args = parser.parse_args()
if args.command == "populate-database":
controller.execute("populate")
SOURCE_DIRECTORY = args.source
TARGET_DIRECTORY = args.target
if args.command == "generate-graph":
controller.execute("graph")
database_service = DatabaseService("eolas", TARGET_DIRECTORY)
database_connection = database_service.connect()
table_service = TableService(database_connection)
parse_file_service = ParseFileService(SOURCE_DIRECTORY)
if args.command == "export-tags":
controller.execute("tags")
entries = parse_file_service.parse_source_directory()
table_service.populate_tables(entries)
database_service.disconnect()
if __name__ == "__main__":

View file

@ -1,2 +0,0 @@
EOLAS_DIRECTORY = "/home/thomas/repos/eolas/zk"
GRAPH_OUTPUT_DIRECTORY = "/home/thomas/repos/eolas-db/out"

View file

@ -1,25 +0,0 @@
class Controller:
def __init__(
self,
database_service,
table_service,
parse_file_service,
):
self.database_service = database_service
self.table_service = table_service
self.parse_file_service = parse_file_service
def execute(self, operation):
try:
match operation:
case "populate":
return self.__populate_database()
except Exception as e:
raise Exception(f"ERROR {e}")
finally:
self.database_service.disconnect()
def __populate_database(self):
entries = self.parse_file_service.parse_source_directory()
self.table_service.populate_tables(entries)
self.database_service.disconnect()

View file

@ -4,9 +4,9 @@ from typing import Optional
class DatabaseService:
def __init__(self, db_name):
def __init__(self, db_name, db_path):
self.db_name = db_name
self.db_path = "/home/thomas/repos/eolas-db/db"
self.db_path = db_path
self.connection: Optional[sqlite3.Connection] = None
def connect(self) -> Optional[sqlite3.Connection]: