Skip to content

Commit

Permalink
Merge branch 'remove-contexts' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
David Erb committed Jun 6, 2023
2 parents 364c121 + 3c6d920 commit f918c21
Show file tree
Hide file tree
Showing 50 changed files with 854 additions and 799 deletions.
4 changes: 4 additions & 0 deletions docs/explanations/conventions.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
..
Use the file automatically generated by dae-devops.
.. include:: ../../.dae-devops/docs/conventions.rst
4 changes: 4 additions & 0 deletions docs/explanations/docs_structure.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
..
Use the file automatically generated by dae-devops.
.. include:: ../../.dae-devops/docs/docs_structure.rst
12 changes: 12 additions & 0 deletions docs/explanations/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
:orphan:

Explanations
============

Explanation, or discussions, clarify and illuminate a particular topic. They broaden the documentation's coverage of a topic.

.. toctree::

docs_structure
conventions
todo
7 changes: 7 additions & 0 deletions docs/explanations/todo.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TODO
=======================================================================

- Remove matplotlib from imports done by mib2hdfConvert package to decrease load time and debug volume.
- Make sure we can collect and process mib files which are not in a material subdirectory.
- Add unit tests for the mib_convert task.

4 changes: 4 additions & 0 deletions docs/how-to/developing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
..
Use the file automatically generated by dae-devops.
.. include:: ../../.dae-devops/docs/developing.rst
4 changes: 4 additions & 0 deletions docs/how-to/devops.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
..
Use the file automatically generated by dae-devops.
.. include:: ../../.dae-devops/docs/devops.rst
4 changes: 4 additions & 0 deletions docs/how-to/documenting.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
..
Use the file automatically generated by dae-devops.
.. include:: ../../.dae-devops/docs/documenting.rst
16 changes: 16 additions & 0 deletions docs/how-to/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
:orphan:

How-to Guides
=============

How-to guides take the reader through the steps required to solve a real-world problem.
Practical step-by-step guides for the more experienced user.

.. toctree::

installing
developing
testing
documenting
devops

6 changes: 6 additions & 0 deletions docs/how-to/installing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
..
Use the file automatically generated by dae-devops.
.. include:: ../../.dae-devops/docs/installing.rst

Since this package is just a library, the command line doesn't do anything else besides print the version.
4 changes: 4 additions & 0 deletions docs/how-to/testing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
..
Use the file automatically generated by dae-devops.
.. include:: ../../.dae-devops/docs/testing.rst
13 changes: 10 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
dls-servbase
=======================================================================

Simple HTTP service for database operations.

Agnostic of type of underlying sql client, provides single-writer access to native database and has a predefined database schema for cookies.

.. toctree::
:caption: API-caption
:hidden:
:titlesonly:

api/index
tutorials/index
how-to/index
explanations/index
reference/index
File renamed without changes.
7 changes: 7 additions & 0 deletions docs/api/command_line.rst → docs/reference/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ dls-servbase
:module: dls_servbase_lib.__main__
:func: get_parser
:prog: dls-servbase

dls_servbase_cli.main
-----------------------------------------------------------------------
.. argparse::
:module: dls_servbase_cli.main
:func: get_parser
:prog: python -m dls_servbase_cli.main
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions docs/tutorials/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:orphan:

Tutorials
=========

Tutorials are lessons that take the reader by the hand through a series of steps to complete a project of some kind.
They are what your project needs in order to show a beginner that they can achieve something with it.

.. toctree::

tbd
4 changes: 4 additions & 0 deletions docs/tutorials/tbd.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TBD Tutorial
=======================================================================

TBD
Empty file removed good_config1.yaml
Empty file.
6 changes: 6 additions & 0 deletions src/dls_servbase_api/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
class Keywords:
ENABLE_COOKIES = "dls_servbase_api::keywords::enable_cookies"


# ----------------------------------------------------------------------------------------
class ClassTypes:
AIOHTTP = "dls_servbase_lib.datafaces.aiohttp"
NORMSQL = "dls_servbase_lib.datafaces.normsql"
30 changes: 8 additions & 22 deletions src/dls_servbase_api/datafaces/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
logger = logging.getLogger(__name__)


# ------------------------------------------------------------------------------------------
class Aiohttp:
class Aiohttp(AiohttpClient):
"""
Object implementing client side API for talking to the dls_servbase_dataface 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"],
)

Expand Down Expand Up @@ -50,11 +49,6 @@ async def update(self, table_name, record, where, subs=None, why=None):
"update", table_name, record, where, subs=subs, why=why
)

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

# ----------------------------------------------------------------------------------------
async def set_cookie(self, cookie_dict):
""" """
Expand All @@ -77,7 +71,7 @@ async def update_cookie(self, row):
async def __send_protocolj(self, function, *args, **kwargs):
""""""

return await self.__aiohttp_client.client_protocolj(
return await self.client_protocolj(
{
Keywords.COMMAND: Commands.EXECUTE,
Keywords.PAYLOAD: {
Expand All @@ -89,14 +83,6 @@ async def __send_protocolj(self, function, *args, **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):
async def report_health(self):
""""""

return await self.__aiohttp_client.client_report_health()
return await self.__send_protocolj("report_health")
34 changes: 14 additions & 20 deletions src/dls_servbase_api/datafaces/context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import logging

# Base class.
from dls_utilpack.client_context_base import ClientContextBase

# Things created in the context.
from dls_servbase_api.datafaces.datafaces import (
Datafaces,
Expand All @@ -9,48 +12,39 @@
logger = logging.getLogger(__name__)


class Context:
class Context(ClientContextBase):
"""
Client context for a dls_servbase_dataface object.
On entering, it creates the object according to the specification (a dict).
On exiting, it closes client connection.
The aenter and aexit methods are exposed for use by an enclosing context.
The aenter and aexit methods are exposed for use by an enclosing context and the base class.
"""

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

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

await self.aenter()

# ----------------------------------------------------------------------------------------
async def __aexit__(self, type, value, traceback):
""" """

await self.aexit()
ClientContextBase.__init__(self, specification)

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

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

# If there is more than one dataface, the last one defined will be the default.
dls_servbase_datafaces_set_default(self.__dls_servbase_dataface)
dls_servbase_datafaces_set_default(self.interface)

# Open client session to the service or direct connection.
await self.interface.open_client_session()

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

if self.__dls_servbase_dataface is not None:
await self.__dls_servbase_dataface.close_client_session()
if self.interface is not None:
# Close client session to the service or direct connection.
await self.interface.close_client_session()

# Clear the global variable. Important between pytests.
dls_servbase_datafaces_set_default(None)
File renamed without changes.
23 changes: 23 additions & 0 deletions src/dls_servbase_api/guis/aiohttp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import logging

# Class for an aiohttp client.
from dls_servbase_api.aiohttp_client import AiohttpClient

logger = logging.getLogger(__name__)


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

# ----------------------------------------------------------------------------------------
def __init__(self, specification):

# We will get an umbrella specification which must contain an aiohttp_specification within it.
AiohttpClient.__init__(
self,
specification["type_specific_tbd"]["aiohttp_specification"],
)
11 changes: 11 additions & 0 deletions src/dls_servbase_api/guis/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Keywords:
COMMAND = "dls_servbase_guis::keywords::command"
PAYLOAD = "dls_servbase_guis::keywords::payload"


class Commands:
EXECUTE = "dls_servbase_guis::commands::execute"


class Types:
AIOHTTP = "dls_servbase_lib.guis.aiohttp"
43 changes: 43 additions & 0 deletions src/dls_servbase_api/guis/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import logging

# Base class.
from dls_utilpack.client_context_base import ClientContextBase

# Things created in the context.
from dls_servbase_api.guis.guis import Guis, dls_servbase_guis_set_default

logger = logging.getLogger(__name__)


class Context(ClientContextBase):
"""
Client context for a dls_servbase_gui object.
On entering, it creates the object according to the specification (a dict).
On exiting, it closes client connection.
The aenter and aexit methods are exposed for use by an enclosing context and the base class.
"""

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

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

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

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

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

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

# Clear the global variable. Important between pytests.
dls_servbase_guis_set_default(None)
Loading

0 comments on commit f918c21

Please sign in to comment.