Skip to content

Commit

Permalink
removes contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
David Erb committed Jun 6, 2023
1 parent 7bf0576 commit 019b252
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 197 deletions.
35 changes: 0 additions & 35 deletions src/echolocator_api/context_base.py

This file was deleted.

51 changes: 6 additions & 45 deletions src/echolocator_api/guis/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,21 @@
# Class for an aiohttp client.
from echolocator_api.aiohttp_client import AiohttpClient

# Dataface protocolj things.
from echolocator_api.guis.constants import Commands, Keywords

logger = logging.getLogger(__name__)


# ------------------------------------------------------------------------------------------
class Aiohttp:
class Aiohttp(AiohttpClient):
"""
Object implementing client side API for talking to the echolocator_gui server.
Object implementing client side API for talking to the echolocator_lib gui server.
Please see doctopic [A01].
"""

# ----------------------------------------------------------------------------------------
def __init__(self, specification=None):
self.__specification = specification
def __init__(self, specification):

self.__aiohttp_client = AiohttpClient(
# We will get an umbrella specification which must contain an aiohttp_specification within it.
AiohttpClient.__init__(
self,
specification["type_specific_tbd"]["aiohttp_specification"],
)

# ----------------------------------------------------------------------------------------
def specification(self):
return self.__specification

# ----------------------------------------------------------------------------------------
async def report_health(self):
""""""
return await self.__send_protocolj("report_health")

# ----------------------------------------------------------------------------------------
async def __send_protocolj(self, function, *args, **kwargs):
""""""

return await self.__aiohttp_client.client_protocolj(
{
Keywords.COMMAND: Commands.EXECUTE,
Keywords.PAYLOAD: {
"function": function,
"args": args,
"kwargs": kwargs,
},
},
)

# ----------------------------------------------------------------------------------------
async def close_client_session(self):
""""""

if self.__aiohttp_client is not None:
await self.__aiohttp_client.close_client_session()

# ----------------------------------------------------------------------------------------
async def client_report_health(self):
""""""

return await self.__aiohttp_client.client_report_health()
8 changes: 4 additions & 4 deletions src/echolocator_api/guis/context.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import logging

# Base class.
from echolocator_api.context_base import ContextBase
from dls_utilpack.client_context_base import ClientContextBase

# Things created in the context.
from echolocator_api.guis.guis import Guis, echolocator_guis_set_default

logger = logging.getLogger(__name__)


class Context(ContextBase):
class Context(ClientContextBase):
"""
Client context for a echolocator_gui object.
On entering, it creates the object according to the specification (a dict).
Expand All @@ -20,14 +20,14 @@ class Context(ContextBase):

# ----------------------------------------------------------------------------------------
def __init__(self, specification):
self.__specification = specification
ClientContextBase.__init__(self, specification)

# ----------------------------------------------------------------------------------------
async def aenter(self):
""" """

# Build the object according to the specification.
self.interface = Guis().build_object(self.__specification)
self.interface = Guis().build_object(self.specification)

# If there is more than one gui, the last one defined will be the default.
echolocator_guis_set_default(self.interface)
Expand Down
5 changes: 5 additions & 0 deletions src/echolocator_api/guis/guis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def echolocator_guis_get_default():
return __default_echolocator_gui


def echolocator_guis_has_default():
global __default_echolocator_gui
return __default_echolocator_gui is not None


# -----------------------------------------------------------------------------------------


Expand Down
6 changes: 3 additions & 3 deletions src/echolocator_cli/subcommands/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
# Xchembku client context.
from xchembku_api.datafaces.context import Context as XchembkuDatafacesContext

# Things created in the context.
from echolocator_api.guis.guis import echolocator_guis_get_default

# Base class for cli subcommands.
from echolocator_cli.subcommands.base import ArgKeywords, Base

# Rockingest context creator.
from echolocator_lib.guis.context import Context as GuiContext

# Things created in the context.
from echolocator_lib.guis.guis import echolocator_guis_get_default

logger = logging.getLogger()


Expand Down
Empty file.
62 changes: 0 additions & 62 deletions src/echolocator_lib/contexts/base.py

This file was deleted.

15 changes: 6 additions & 9 deletions src/echolocator_lib/guis/context.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
import logging

# Base class which maps flask requests to methods.
from echolocator_lib.contexts.base import Base as ContextBase
# Base class for an asyncio server context.
from dls_utilpack.server_context_base import ServerContextBase

# Things created in the context.
from echolocator_lib.guis.guis import Guis, echolocator_guis_set_default
from echolocator_lib.guis.guis import Guis

logger = logging.getLogger(__name__)


thing_type = "echolocator_lib.echolocator_guis.context"


class Context(ContextBase):
class Context(ServerContextBase):
"""
Object representing an event echolocator_dataface connection.
"""

# ----------------------------------------------------------------------------------------
def __init__(self, specification):
ContextBase.__init__(self, thing_type, specification)
ServerContextBase.__init__(self, thing_type, specification)

# ----------------------------------------------------------------------------------------
async def aenter(self):
""" """

self.server = Guis().build_object(self.specification())

# If there is more than one gui, the last one defined will be the default.
echolocator_guis_set_default(self.server)

if self.context_specification.get("start_as") == "coro":
await self.server.activate_coro()

Expand All @@ -41,7 +38,7 @@ async def aenter(self):
await self.server.start_process()

# ----------------------------------------------------------------------------------------
async def aexit(self):
async def aexit(self, type, value, traceback):
""" """
logger.debug(f"[DISSHU] {thing_type} aexit")

Expand Down
21 changes: 0 additions & 21 deletions src/echolocator_lib/guis/guis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,6 @@

logger = logging.getLogger(__name__)

# -----------------------------------------------------------------------------------------
__default_echolocator_gui = None


def echolocator_guis_set_default(echolocator_gui):
global __default_echolocator_gui
__default_echolocator_gui = echolocator_gui


def echolocator_guis_get_default():
global __default_echolocator_gui
if __default_echolocator_gui is None:
raise RuntimeError("echolocator_guis_get_default instance is None")
return __default_echolocator_gui


def echolocator_guis_has_default():
global __default_echolocator_gui
return __default_echolocator_gui is not None


# -----------------------------------------------------------------------------------------


Expand Down
7 changes: 4 additions & 3 deletions tests/test_droplocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
# Client context creator.
from echolocator_api.guis.context import Context as GuiClientContext

# Object managing gui
from echolocator_api.guis.guis import echolocator_guis_get_default

# GUI constants.
from echolocator_lib.guis.constants import Commands, Cookies, Keywords

# Server context creator.
from echolocator_lib.guis.context import Context as GuiServerContext

# Object managing gui
from echolocator_lib.guis.guis import echolocator_guis_get_default

# Base class for the tester.
from tests.base import Base

Expand Down Expand Up @@ -91,6 +91,7 @@ async def _main_coroutine(self, constants, output_directory):
async with xchembku_client_context:
# Start the server context xchembku which starts the process.
async with xchembku_server_context:
# Start the servbase (cookies) server.
async with servbase_dataface_context:
# Start the gui client context.
async with gui_client_context:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_export_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
# Client context creator.
from echolocator_api.guis.context import Context as GuiClientContext

# Object managing gui
from echolocator_api.guis.guis import echolocator_guis_get_default

# GUI constants.
from echolocator_lib.guis.constants import Commands, Keywords

# Server context creator.
from echolocator_lib.guis.context import Context as GuiServerContext

# Object managing gui
from echolocator_lib.guis.guis import echolocator_guis_get_default

# Base class for the tester.
from tests.base import Base

Expand Down
6 changes: 3 additions & 3 deletions tests/test_export_to_soakdb3.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
# Client context creator.
from echolocator_api.guis.context import Context as GuiClientContext

# Object managing gui
from echolocator_api.guis.guis import echolocator_guis_get_default

# GUI constants.
from echolocator_lib.guis.constants import Commands, Keywords

# Server context creator.
from echolocator_lib.guis.context import Context as GuiServerContext

# Object managing gui
from echolocator_lib.guis.guis import echolocator_guis_get_default

# Base class for the tester.
from tests.base import Base

Expand Down
6 changes: 3 additions & 3 deletions tests/test_fetch_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
# Client context creator.
from echolocator_api.guis.context import Context as GuiClientContext

# Object managing gui
from echolocator_api.guis.guis import echolocator_guis_get_default

# GUI constants.
from echolocator_lib.guis.constants import Commands, Cookies, Keywords

# Server context creator.
from echolocator_lib.guis.context import Context as GuiServerContext

# Object managing gui
from echolocator_lib.guis.guis import echolocator_guis_get_default

# Base class for the tester.
from tests.base import Base

Expand Down
Loading

0 comments on commit 019b252

Please sign in to comment.