From 21dd3ae9b21877492123b03571946a01bc2d7af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Such=C3=A1nek?= Date: Tue, 31 Oct 2023 09:48:21 +0100 Subject: [PATCH] Init logic for mapping --- pyproject.toml | 1 + requirements.dev.txt | 1 + requirements.txt | 4 ++++ run.sh | 5 +++++ src/smp_importer/logic.py | 40 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+) create mode 100644 requirements.dev.txt create mode 100644 run.sh create mode 100644 src/smp_importer/logic.py diff --git a/pyproject.toml b/pyproject.toml index 739e465..1c90d8c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ requires-python = '>=3.10, <4' dependencies = [ 'fastapi', 'Jinja2', + 'rdflib', ] [project.urls] diff --git a/requirements.dev.txt b/requirements.dev.txt new file mode 100644 index 0000000..f193b62 --- /dev/null +++ b/requirements.dev.txt @@ -0,0 +1 @@ +uvicorn diff --git a/requirements.txt b/requirements.txt index 851d177..5ecbe78 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,10 +2,14 @@ annotated-types==0.6.0 anyio==3.7.1 fastapi==0.104.1 idna==3.4 +isodate==0.6.1 Jinja2==3.1.2 MarkupSafe==2.1.3 pydantic==2.4.2 pydantic_core==2.10.1 +pyparsing==3.1.1 +rdflib==7.0.0 +six==1.16.0 sniffio==1.3.0 starlette==0.27.0 typing_extensions==4.8.0 diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..750b856 --- /dev/null +++ b/run.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +export $(grep -v '^#' .env | xargs) + +uvicorn fip2dmp_importer:app --reload diff --git a/src/smp_importer/logic.py b/src/smp_importer/logic.py new file mode 100644 index 0000000..95e917e --- /dev/null +++ b/src/smp_importer/logic.py @@ -0,0 +1,40 @@ +class _MappingExecutor: + + def __init__(self): + self.result = [] + self.variables = {} + + def reset(self): + self.result = [] + self.variables = {} + + def result_add(self, action: str, **kwargs): + self.result.append({ + 'type': action, + **kwargs, + }) + + def result_debug(self, message: str): + self.result_add(action='debug', message=message) + + def result_add_item(self, path: str, var_name: str): + self.result_add(action='addItem', path=path.split('.'), var=var_name) + + def result_set_reply(self, path: str, value: str): + self.result_add(action='setReply', path=path.split('.'), value=value) + + def result_set_integration_reply(self, path: str, value: str, item_id): + self.result_add(action='setIntegrationReply', path=path.split('.'), value=value, itemId=item_id) + + def get_result_dict(self): + return { + 'actions': self.result, + } + + +def prepare_import_mapping(contents: str, content_type: str) -> dict: + executor = _MappingExecutor() + + # TODO: process contents in custom functions, etc. + + return executor.get_result_dict()