diff --git a/tangostationcontrol/tangostationcontrol/common/entrypoint.py b/tangostationcontrol/tangostationcontrol/common/entrypoint.py new file mode 100644 index 0000000000000000000000000000000000000000..d5b9d4952ee08180162b3bdca7417fff31f456f0 --- /dev/null +++ b/tangostationcontrol/tangostationcontrol/common/entrypoint.py @@ -0,0 +1,21 @@ +import sys + +from tango.server import run + +from tangostationcontrol.common.lofar_logging import configure_logger + + +def entry(Device, **kwargs): + """General device entrypoint""" + + # Remove first argument which is filename + args = sys.argv[1:] + + # Setup logging + configure_logger() + + # Start the device server + if type(Device) is tuple: + return run(Device, args=args, **kwargs) + else: + return run((Device,), args=args, **kwargs) diff --git a/tangostationcontrol/tangostationcontrol/devices/boot.py b/tangostationcontrol/tangostationcontrol/devices/boot.py index 6909e2babe4d5d6b0418d4bbebb750b42e4ddee1..c4021d9d913b09ff8ea95b9deb5e724f45dbc208 100644 --- a/tangostationcontrol/tangostationcontrol/devices/boot.py +++ b/tangostationcontrol/tangostationcontrol/devices/boot.py @@ -23,6 +23,7 @@ import numpy from device_decorators import * +from tangostationcontrol.common.entry import entry from tangostationcontrol.devices.hardware_device import hardware_device from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions @@ -276,10 +277,6 @@ class Boot(hardware_device): # ---------- # Run server # ---------- -def main(args=None, **kwargs): +def main(**kwargs): """Main function of the Boot module.""" - - from tangostationcontrol.common.lofar_logging import configure_logger - configure_logger() - - return run((Boot,), args=args, **kwargs) + return entry(Boot, **kwargs) diff --git a/tangostationcontrol/tangostationcontrol/devices/docker_device.py b/tangostationcontrol/tangostationcontrol/devices/docker_device.py index 5945a152b9c81479f6c5317fa552be023d2ad10a..5f08204d8359a7e4c1f257bc1b2b9a03fb4f1fb3 100644 --- a/tangostationcontrol/tangostationcontrol/devices/docker_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/docker_device.py @@ -22,11 +22,11 @@ import asyncio from device_decorators import * # Additional import +from tangostationcontrol.common.entrypoint import entry from tangostationcontrol.clients.docker_client import DockerClient from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.devices.hardware_device import hardware_device from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions -from tangostationcontrol.common.lofar_version import get_version __all__ = ["Docker", "main"] @@ -122,10 +122,6 @@ class Docker(hardware_device): # ---------- # Run server # ---------- -def main(args=None, **kwargs): +def main(**kwargs): """Main function of the Docker module.""" - - from tangostationcontrol.common.lofar_logging import configure_logger - configure_logger() - - return run((Docker,), args=args, **kwargs) + return entry(Docker, **kwargs) diff --git a/tangostationcontrol/tangostationcontrol/devices/observation.py b/tangostationcontrol/tangostationcontrol/devices/observation.py index 86a730320a72f0d9bac04cef52fed72ead12a1a8..c5b6d469380b4c8eab96eeb31af79405876716a4 100644 --- a/tangostationcontrol/tangostationcontrol/devices/observation.py +++ b/tangostationcontrol/tangostationcontrol/devices/observation.py @@ -11,9 +11,10 @@ from tango.server import Device, run, command, attribute import numpy from time import time -from tangostationcontrol.devices.device_decorators import * +from tangostationcontrol.common.entrypoint import entry from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions from tangostationcontrol.common.lofar_version import get_version +from tangostationcontrol.devices.device_decorators import * from json import loads @@ -110,6 +111,6 @@ class Observation(Device): # ---------- # Run server # ---------- -def main(args = None, **kwargs): +def main(**kwargs): """Main function of the ObservationControl module.""" - return run((Observation,), args = args, **kwargs) + return entry(Observation, **kwargs) diff --git a/tangostationcontrol/tangostationcontrol/devices/observation_control.py b/tangostationcontrol/tangostationcontrol/devices/observation_control.py index 5676a7a183e8b784dd7501c897cefa0c19c041f6..869db4e92831126db76534d5c7c3c7985dab2a34 100644 --- a/tangostationcontrol/tangostationcontrol/devices/observation_control.py +++ b/tangostationcontrol/tangostationcontrol/devices/observation_control.py @@ -14,6 +14,7 @@ import numpy import time from json import loads +from tangostationcontrol.common.entrypoint import entry from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions from tangostationcontrol.common.lofar_version import get_version from tangostationcontrol.devices.device_decorators import * @@ -437,6 +438,6 @@ class ObservationControl(Device): # ---------- # Run server # ---------- -def main(args = None, **kwargs): +def main(**kwargs): """Main function of the ObservationControl module.""" - return run((ObservationControl, Observation), verbose = True, args = args, **kwargs) + return entry((ObservationControl, Observation), verbose=True, **kwargs) diff --git a/tangostationcontrol/tangostationcontrol/devices/opcua_device.py b/tangostationcontrol/tangostationcontrol/devices/opcua_device.py index 078e21b249bcec2ca7de5661ea40bf963ac97394..a6c3bfa285df61923fb4aa6b7b95eb0597fae533 100644 --- a/tangostationcontrol/tangostationcontrol/devices/opcua_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/opcua_device.py @@ -25,11 +25,10 @@ import numpy import asyncio # Additional import -from devices.device_decorators import * - -from clients.opcua_client import OPCUAConnection -from devices.hardware_device import hardware_device -from common.lofar_logging import device_logging_to_python, log_exceptions +from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions +from tangostationcontrol.clients.opcua_client import OPCUAConnection +from tangostationcontrol.devices.device_decorators import * +from tangostationcontrol.devices.hardware_device import hardware_device __all__ = ["opcua_device", "main"] diff --git a/tangostationcontrol/tangostationcontrol/devices/recv.py b/tangostationcontrol/tangostationcontrol/devices/recv.py index ca0d3938bedaf55e057d57355e6cc772889a8b3f..f4f94b2e78822a3e572c47846bd35752ffbe5874 100644 --- a/tangostationcontrol/tangostationcontrol/devices/recv.py +++ b/tangostationcontrol/tangostationcontrol/devices/recv.py @@ -19,8 +19,9 @@ from tango import AttrWriteType import numpy # Additional import -from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper +from tangostationcontrol.common.entrypoint import entry from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions +from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.devices.device_decorators import * from tangostationcontrol.devices.opcua_device import opcua_device @@ -257,10 +258,6 @@ class RECV(opcua_device): # ---------- # Run server # ---------- -def main(args=None, **kwargs): +def main(**kwargs): """Main function of the RECV module.""" - - from tangostationcontrol.common.lofar_logging import configure_logger - configure_logger() - - return run((RECV,), args=args, **kwargs) + return entry(RECV, **kwargs) diff --git a/tangostationcontrol/tangostationcontrol/devices/sdp/sdp.py b/tangostationcontrol/tangostationcontrol/devices/sdp/sdp.py index 661498183d0e45dcb814fb21864a1616a5c2b97b..8d51cbdb14b78cb501eaeff8e7db4ead6a22056a 100644 --- a/tangostationcontrol/tangostationcontrol/devices/sdp/sdp.py +++ b/tangostationcontrol/tangostationcontrol/devices/sdp/sdp.py @@ -19,12 +19,14 @@ from tango import AttrWriteType # Additional import from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.devices.opcua_device import opcua_device +from tangostationcontrol.common.entrypoint import entry from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions import numpy __all__ = ["SDP", "main"] + @device_logging_to_python() class SDP(opcua_device): # ----------------- @@ -69,7 +71,7 @@ class SDP(opcua_device): mandatory=False, default_value=[[0.0] * 12] * 16 ) - + FPGA_sdp_info_station_id_RW_default = device_property( dtype='DevVarULongArray', mandatory=True @@ -171,10 +173,6 @@ class SDP(opcua_device): # ---------- # Run server # ---------- -def main(args=None, **kwargs): +def main(**kwargs): """Main function of the SDP module.""" - - from tangostationcontrol.common.lofar_logging import configure_logger - configure_logger() - - return run((SDP,), args=args, **kwargs) + return entry(SDP, **kwargs) diff --git a/tangostationcontrol/tangostationcontrol/devices/sdp/sst.py b/tangostationcontrol/tangostationcontrol/devices/sdp/sst.py index 1cca268d2d9fd28d24d411050186d71b924dc6a7..08613015db3f50bf1b93ebe7d9b11ac7f98cde03 100644 --- a/tangostationcontrol/tangostationcontrol/devices/sdp/sst.py +++ b/tangostationcontrol/tangostationcontrol/devices/sdp/sst.py @@ -17,6 +17,7 @@ from tango.server import device_property, attribute from tango import AttrWriteType # Additional import +from tangostationcontrol.common.entrypoint import entry from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.clients.opcua_client import OPCUAConnection from tangostationcontrol.clients.statistics_client import StatisticsClient @@ -27,6 +28,7 @@ import numpy __all__ = ["SST", "main"] + class SST(Statistics): STATISTICS_COLLECTOR_CLASS = SSTCollector @@ -113,10 +115,6 @@ class SST(Statistics): # ---------- # Run server # ---------- -def main(args=None, **kwargs): +def main(**kwargs): """Main function of the SST Device module.""" - - from tangostationcontrol.common.lofar_logging import configure_logger - configure_logger() - - return run((SST,), args=args, **kwargs) + return entry(SST, **kwargs) diff --git a/tangostationcontrol/tangostationcontrol/devices/sdp/xst.py b/tangostationcontrol/tangostationcontrol/devices/sdp/xst.py index 98d0725d29b26cab04e494c49efb4036c7bc84e1..4bbdee6a630ea299d5965443396a7662de59e149 100644 --- a/tangostationcontrol/tangostationcontrol/devices/sdp/xst.py +++ b/tangostationcontrol/tangostationcontrol/devices/sdp/xst.py @@ -17,6 +17,7 @@ from tango.server import device_property, attribute from tango import AttrWriteType # Additional import +from tangostationcontrol.common.entrypoint import entry from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.clients.opcua_client import OPCUAConnection from tangostationcontrol.clients.statistics_client import StatisticsClient @@ -151,10 +152,6 @@ class XST(Statistics): # ---------- # Run server # ---------- -def main(args=None, **kwargs): +def main(**kwargs): """Main function of the XST Device module.""" - - from tangostationcontrol.common.lofar_logging import configure_logger - configure_logger() - - return run((XST,), args=args, **kwargs) + return entry(XST, **kwargs) diff --git a/tangostationcontrol/tangostationcontrol/devices/unb2.py b/tangostationcontrol/tangostationcontrol/devices/unb2.py index 495c80da63f38261d152e6ab45b09c3a7025765b..4250e3c99d90c14cb9a3f0240352287f67f4ae4c 100644 --- a/tangostationcontrol/tangostationcontrol/devices/unb2.py +++ b/tangostationcontrol/tangostationcontrol/devices/unb2.py @@ -17,6 +17,7 @@ from tango.server import device_property, attribute from tango import AttrWriteType # Additional import +from tangostationcontrol.common.entrypoint import entry from tangostationcontrol.clients.attribute_wrapper import attribute_wrapper from tangostationcontrol.devices.opcua_device import opcua_device from tangostationcontrol.common.lofar_logging import device_logging_to_python, log_exceptions @@ -146,8 +147,4 @@ class UNB2(opcua_device): # ---------- def main(args=None, **kwargs): """Main function of the UNB2 module.""" - - from tangostationcontrol.common.lofar_logging import configure_logger - configure_logger() - - return run((UNB2,), args=args, **kwargs) + return entry(UNB2, **kwargs)