2022-06-11 14:00:45 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# IMPORTS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
from src.thirdparty.code import *;
|
|
|
|
|
|
|
|
from models.generated.commands import *;
|
|
|
|
from src.models.config import *
|
|
|
|
from src.endpoints import *;
|
|
|
|
from src.core.calls import *;
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# EXPORTS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
'run_command',
|
|
|
|
'run_command_from_json',
|
|
|
|
];
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# API METHODS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
@run_safely(tag='api-from-json')
|
|
|
|
def run_command_from_json(command_json: str) -> Result[CallResult, CallError]:
|
|
|
|
command = command_from_json(command_json);
|
|
|
|
return run_command(command);
|
|
|
|
|
|
|
|
@run_safely(tag='api-from-command')
|
|
|
|
def run_command(command: Command) -> Result[CallResult, CallError]:
|
|
|
|
if isinstance(command, CommandTarjan):
|
|
|
|
return endpoint_tarjan(command);
|
|
|
|
if isinstance(command, CommandTsp):
|
|
|
|
return endpoint_tsp(command);
|
|
|
|
elif isinstance(command, CommandHirschberg):
|
|
|
|
return endpoint_hirschberg(command);
|
2022-06-14 01:35:10 +02:00
|
|
|
elif isinstance(command, CommandRucksack):
|
|
|
|
return endpoint_rucksack(command);
|
2022-06-11 14:00:45 +02:00
|
|
|
raise Exception(f'No endpoint set for `{command.name.value}`-command type.');
|