Merge SettingsManager and SystemControl Things.
This commit is contained in:
parent
bed59c051b
commit
be94df7c8a
7 changed files with 57 additions and 65 deletions
|
|
@ -1,74 +0,0 @@
|
|||
"""OpenFlexure Settings Management.
|
||||
|
||||
This module provides some settings management across the other Things, and
|
||||
for code that currently lives in clients but needs to persist settings on
|
||||
the server.
|
||||
"""
|
||||
|
||||
from collections.abc import Mapping
|
||||
from socket import gethostname
|
||||
from typing import Optional
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
import labthings_fastapi as lt
|
||||
|
||||
from openflexure_microscope_server.utilities import VersionData, robust_version_strings
|
||||
|
||||
|
||||
class SettingsManager(lt.Thing):
|
||||
"""Provides functionality to other Things about the current server state.
|
||||
|
||||
The SettingsManager is used to get information the microscope ID, the hostname
|
||||
and the state of other Things.
|
||||
"""
|
||||
|
||||
_microscope_id: Optional[str] = None
|
||||
|
||||
@lt.thing_setting
|
||||
def microscope_id(self) -> UUID:
|
||||
"""A unique identifier for this microscope."""
|
||||
if self._microscope_id is None:
|
||||
self._microscope_id = str(uuid4())
|
||||
return UUID(self._microscope_id)
|
||||
|
||||
@microscope_id.setter
|
||||
def microscope_id(self, uuid: UUID):
|
||||
# TODO make read only but still settable from disk
|
||||
self._microscope_id = uuid
|
||||
|
||||
@lt.thing_property
|
||||
def hostname(self) -> str:
|
||||
"""The hostname of the microscope, as reported by its operating system."""
|
||||
return gethostname()
|
||||
|
||||
_version_data: Optional[VersionData] = None
|
||||
|
||||
@lt.thing_property
|
||||
def version_data(self) -> VersionData:
|
||||
"""The version string and version source for the server.
|
||||
|
||||
The source may be a commit hash if installed from git. "TOML" if installed from
|
||||
source, or "Dist" if installed from a distribution package.
|
||||
|
||||
If the version or its source cannot be determined an error will be Logged.
|
||||
"""
|
||||
# Don't save as a setting as it may change. Get the version string the first
|
||||
# time the property is requested this boot.
|
||||
if self._version_data is None:
|
||||
self._version_data = robust_version_strings()
|
||||
return self._version_data
|
||||
|
||||
@lt.thing_action
|
||||
def get_things_state(self, metadata_getter: lt.deps.GetThingStates) -> Mapping:
|
||||
"""Metadata summarising the current state of all Things in the server."""
|
||||
return metadata_getter()
|
||||
|
||||
@property
|
||||
def thing_state(self) -> Mapping:
|
||||
"""Summary metadata describing the current state of the Thing."""
|
||||
return {
|
||||
"hostname": self.hostname,
|
||||
"microscope-uuid": str(self.microscope_id),
|
||||
"version": self.version_data.version,
|
||||
"version_source": self.version_data.version_source,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue