Skip to content
Snippets Groups Projects
Commit 75c78bc7 authored by Thomas Juerges's avatar Thomas Juerges
Browse files

Merge branch 'master' into 2021-03-22T14.42.30-branched_from_master-Makefile_refactoring

parents c24173a9 b9e49e63
Branches
Tags
1 merge request!21Small refactoring of the Makefile
...@@ -3,7 +3,7 @@ from tango import AttrWriteType ...@@ -3,7 +3,7 @@ from tango import AttrWriteType
import numpy import numpy
from src.wrappers import only_when_on, fault_on_error from util.wrappers import only_when_on, fault_on_error
import logging import logging
logger = logging.getLogger() logger = logging.getLogger()
...@@ -61,8 +61,8 @@ class attribute_wrapper(attribute): ...@@ -61,8 +61,8 @@ class attribute_wrapper(attribute):
if access == AttrWriteType.READ_WRITE: if access == AttrWriteType.READ_WRITE:
""" if the attribute is of READ_WRITE type, assign the RW and write function to it""" """ if the attribute is of READ_WRITE type, assign the RW and write function to it"""
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def read_RW(device): def read_RW(device):
# print("read_RW {}, {}x{}, {}, {}".format(me.name, me.dim_x, me.dim_y, me.attr_type, me.value)) # print("read_RW {}, {}x{}, {}, {}".format(me.name, me.dim_x, me.dim_y, me.attr_type, me.value))
""" """
...@@ -74,8 +74,8 @@ class attribute_wrapper(attribute): ...@@ -74,8 +74,8 @@ class attribute_wrapper(attribute):
raise Exception("Attribute read_RW function error, attempted to read value_dict with key: `%s`, are you sure this exists?", raise Exception("Attribute read_RW function error, attempted to read value_dict with key: `%s`, are you sure this exists?",
self) from e self) from e
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def write_RW(device, value): def write_RW(device, value):
""" """
_write_RW writes a value to this attribute _write_RW writes a value to this attribute
...@@ -91,8 +91,8 @@ class attribute_wrapper(attribute): ...@@ -91,8 +91,8 @@ class attribute_wrapper(attribute):
else: else:
""" if the attribute is of READ type, assign the read function to it""" """ if the attribute is of READ type, assign the read function to it"""
@only_when_on @only_when_on()
@fault_on_error @fault_on_error()
def read_R(device): def read_R(device):
""" """
_read_R reads the attribute value, stores it and returns it" _read_R reads the attribute value, stores it and returns it"
......
File moved
File moved
...@@ -16,12 +16,12 @@ from tango.server import Device, command ...@@ -16,12 +16,12 @@ from tango.server import Device, command
from tango import DevState, DebugIt from tango import DevState, DebugIt
# Additional import # Additional import
from src.attribute_wrapper import attribute_wrapper from util.attribute_wrapper import attribute_wrapper
from src.lofar_logging import log_exceptions from util.lofar_logging import log_exceptions
__all__ = ["hardware_device"] __all__ = ["hardware_device"]
from src.wrappers import only_in_states from util.wrappers import only_in_states, fault_on_error
#@log_exceptions() #@log_exceptions()
class hardware_device(Device): class hardware_device(Device):
...@@ -74,6 +74,8 @@ class hardware_device(Device): ...@@ -74,6 +74,8 @@ class hardware_device(Device):
@command() @command()
@only_in_states([DevState.FAULT, DevState.OFF]) @only_in_states([DevState.FAULT, DevState.OFF])
@DebugIt() @DebugIt()
@fault_on_error()
@log_exceptions()
def Initialise(self): def Initialise(self):
""" """
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state. Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
...@@ -83,24 +85,27 @@ class hardware_device(Device): ...@@ -83,24 +85,27 @@ class hardware_device(Device):
self.set_state(DevState.INIT) self.set_state(DevState.INIT)
self.setup_value_dict() self.setup_value_dict()
self.initialise() self.configure_for_initialise()
self.set_state(DevState.STANDBY) self.set_state(DevState.STANDBY)
@command() @command()
@only_in_states([DevState.STANDBY]) @only_in_states([DevState.STANDBY])
@DebugIt() @DebugIt()
@fault_on_error()
@log_exceptions()
def On(self): def On(self):
""" """
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state. Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
:return:None :return:None
""" """
self.on() self.configure_for_on()
self.set_state(DevState.ON) self.set_state(DevState.ON)
@command() @command()
@DebugIt() @DebugIt()
@log_exceptions()
def Off(self): def Off(self):
""" """
Command to ask for shutdown of this device. Command to ask for shutdown of this device.
...@@ -114,7 +119,7 @@ class hardware_device(Device): ...@@ -114,7 +119,7 @@ class hardware_device(Device):
# Turn off # Turn off
self.set_state(DevState.OFF) self.set_state(DevState.OFF)
self.off() self.configure_for_off()
# Turn off again, in case of race conditions through reconnecting # Turn off again, in case of race conditions through reconnecting
self.set_state(DevState.OFF) self.set_state(DevState.OFF)
...@@ -122,6 +127,7 @@ class hardware_device(Device): ...@@ -122,6 +127,7 @@ class hardware_device(Device):
@command() @command()
@only_in_states([DevState.ON, DevState.INIT, DevState.STANDBY]) @only_in_states([DevState.ON, DevState.INIT, DevState.STANDBY])
@DebugIt() @DebugIt()
@log_exceptions()
def Fault(self): def Fault(self):
""" """
FAULT state is used to indicate our connection with the OPC-UA server is down. FAULT state is used to indicate our connection with the OPC-UA server is down.
...@@ -132,18 +138,18 @@ class hardware_device(Device): ...@@ -132,18 +138,18 @@ class hardware_device(Device):
:return:None :return:None
""" """
self.fault() self.configure_for_fault()
self.set_state(DevState.FAULT) self.set_state(DevState.FAULT)
# functions that can be overloaded # functions that can be overloaded
def fault(self): def configure_for_fault(self):
pass pass
def off(self): def configure_for_off(self):
pass pass
def on(self): def configure_for_on(self):
pass pass
def initialise(self): def configure_for_initialise(self):
pass pass
def always_executed_hook(self): def always_executed_hook(self):
......
File moved
import logging import logging
from functools import wraps from functools import wraps
import sys
# Always also log the hostname because it makes the origin of the log clear. # Always also log the hostname because it makes the origin of the log clear.
import socket import socket
......
...@@ -34,4 +34,3 @@ def startup(device: str, force_restart: bool): ...@@ -34,4 +34,3 @@ def startup(device: str, force_restart: bool):
else: else:
print("Device {} has successfully reached ON state.".format(device)) print("Device {} has successfully reached ON state.".format(device))
return proxy return proxy
...@@ -22,12 +22,13 @@ def only_in_states(allowed_states): ...@@ -22,12 +22,13 @@ def only_in_states(allowed_states):
return wrapper return wrapper
def only_when_on(func): def only_when_on():
""" """
Wrapper to call and return the wrapped function if the device is Wrapper to call and return the wrapped function if the device is
in the ON state. Otherwise None is returned and nothing in the ON state. Otherwise None is returned and nothing
will be called. will be called.
""" """
def inner(func):
@wraps(func) @wraps(func)
def when_on_wrapper(self, *args, **kwargs): def when_on_wrapper(self, *args, **kwargs):
if self.get_state() == DevState.ON: if self.get_state() == DevState.ON:
...@@ -37,10 +38,13 @@ def only_when_on(func): ...@@ -37,10 +38,13 @@ def only_when_on(func):
return when_on_wrapper return when_on_wrapper
def fault_on_error(func): return inner
def fault_on_error():
""" """
Wrapper to catch exceptions. Sets the device in a FAULT state if any occurs. Wrapper to catch exceptions. Sets the device in a FAULT state if any occurs.
""" """
def inner(func):
@wraps(func) @wraps(func)
def error_wrapper(self, *args, **kwargs): def error_wrapper(self, *args, **kwargs):
try: try:
...@@ -51,3 +55,5 @@ def fault_on_error(func): ...@@ -51,3 +55,5 @@ def fault_on_error(func):
return None return None
return error_wrapper return error_wrapper
return inner
This diff is collapsed.
version: '2' version: '2'
services: services:
maria-db: archiver-maria-db:
image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mariadb_hdbpp:latest image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mariadb_hdbpp:latest
container_name: archiver-maria-db container_name: archiver-maria-db
network_mode: ${NETWORK_MODE} network_mode: ${NETWORK_MODE}
...@@ -23,7 +23,7 @@ services: ...@@ -23,7 +23,7 @@ services:
depends_on: depends_on:
- databaseds - databaseds
- dsconfig - dsconfig
- maria-db - archiver-maria-db
environment: environment:
- TANGO_HOST=${TANGO_HOST} - TANGO_HOST=${TANGO_HOST}
- HdbManager=archiving/hdbpp/confmanager01 - HdbManager=archiving/hdbpp/confmanager01
...@@ -40,7 +40,7 @@ services: ...@@ -40,7 +40,7 @@ services:
depends_on: depends_on:
- databaseds - databaseds
- dsconfig - dsconfig
- maria-db - archiver-maria-db
environment: environment:
- TANGO_HOST=${TANGO_HOST} - TANGO_HOST=${TANGO_HOST}
- HdbManager=archiving/hdbpp/confmanager01 - HdbManager=archiving/hdbpp/confmanager01
......
...@@ -16,7 +16,7 @@ services: ...@@ -16,7 +16,7 @@ services:
depends_on: depends_on:
- databaseds - databaseds
- dsconfig - dsconfig
- maria-db - archiver-maria-db
- hdbpp-es - hdbpp-es
- hdbpp-cm - hdbpp-cm
volumes: volumes:
......
...@@ -13,7 +13,7 @@ RUN sudo jupyter nbextension enable jupyter_bokeh --py --sys-prefix ...@@ -13,7 +13,7 @@ RUN sudo jupyter nbextension enable jupyter_bokeh --py --sys-prefix
# Install profiles for ipython & jupyter # Install profiles for ipython & jupyter
COPY ipython-profiles /opt/ipython-profiles/ COPY ipython-profiles /opt/ipython-profiles/
RUN sudo chown tango.tango -R /opt/ipython-profiles RUN sudo chmod a+rw -R /opt/ipython-profiles
COPY jupyter-kernels /usr/local/share/jupyter/kernels/ COPY jupyter-kernels /usr/local/share/jupyter/kernels/
# Install patched jupyter executable # Install patched jupyter executable
...@@ -27,5 +27,6 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/ ...@@ -27,5 +27,6 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/
RUN sudo chmod +x /usr/bin/tini RUN sudo chmod +x /usr/bin/tini
# Make sure Jupyter can write to the home directory # Make sure Jupyter can write to the home directory
ENV HOME=/home/tango ENV HOME=/home/user
RUN chmod a+rwx /home/tango RUN sudo mkdir -p $HOME
RUN sudo chmod a+rwx $HOME
%% Cell type:code id:waiting-chance tags:
``` python
import time
import numpy
```
%% Cell type:code id:moving-alexandria tags:
``` python
d=DeviceProxy("LTS/ini_device/1")
```
%% Cell type:code id:ranking-aluminum tags:
``` python
state = str(d.state())
if state == "OFF":
d.initialise()
time.sleep(1)
state = str(d.state())
if state == "STANDBY":
d.on()
state = str(d.state())
if state == "ON":
print("Device is now in on state")
```
%% Output
Device is now in on state
%% Cell type:code id:beneficial-evidence tags:
``` python
attr_names = d.get_attribute_list()
for i in attr_names:
try:
exec("print(i, d.{})".format(i))
except:
pass
```
%% Output
double_scalar_RW [0.]
double_scalar_R [1.2]
bool_scalar_RW [False]
bool_scalar_R [ True]
int_scalar_RW [0]
int_scalar_R [5]
str_scalar_RW ('',)
str_scalar_R ('this is',)
double_spectrum_RW [0. 0. 0. 0.]
double_spectrum_R [1.2 2.3 3.4 4.5]
bool_spectrum_RW [False False False False]
bool_spectrum_R [ True True False False]
int_spectrum_RW [0 0 0 0]
int_spectrum_R [1 2 3 4]
str_spectrum_RW ('', '', '', '')
str_spectrum_R ('"a"', ' "b"', ' "c"', ' "d"')
double_image_RW [[0. 0. 0.]
[0. 0. 0.]]
double_image_R [[1.2 2.3 3.4]
[4.5 5.6 6.7]]
bool_image_RW [[False False False]
[False False False]]
bool_image_R [[ True True False]
[False True False]]
int_image_RW [[0 0 0]
[0 0 0]]
int_image_R [[1 2 3]
[4 5 6]]
str_image_RW (('', '', ''), ('', '', ''))
str_image_R (('"a"', ' "b"', ' "c"'), (' "d"', ' "e"', ' "f"'))
State <function __get_command_func.<locals>.f at 0x7f3efee95c80>
Status <function __get_command_func.<locals>.f at 0x7f3efee95c80>
%% Cell type:code id:sharing-mechanics tags:
``` python
d.int_scalar_RW
```
%% Output
array([0])
%% Cell type:code id:2f03759a tags:
``` python
d.str_image_RW = [["1", "2", "3"],["4", "5", "6"]]
```
%% Cell type:code id:3187f3bb tags:
``` python
d.str_image_RW
```
%% Output
(('1', '2', '3'), ('4', '5', '6'))
%% Cell type:code id:eb406dce tags:
``` python
numpy.str_(["a", "b", "c", "d", "e", "f"])
```
%% Output
"['a', 'b', 'c', 'd', 'e', 'f']"
%% Cell type:code id:7b270085 tags:
``` python
array = []
string = '"a", "b", "c", "d", "e", "f"'
for i in string.split(","):
value = numpy.str_(i)
array.append(value)
len(array)
```
%% Output
6
%% Cell type:code id:69ecc437 tags:
``` python
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment