diff --git a/lib/lofar2_config.py b/lib/lofar2_config.py new file mode 100755 index 0000000000000000000000000000000000000000..581eea4f73a4d276613123ec9bf86bdb7e97a0ea --- /dev/null +++ b/lib/lofar2_config.py @@ -0,0 +1,13 @@ +#! /usr/bin/env python3 + +import logging + + +def configure_logging(): + # Always also log the hostname because it makes the origin of the log clear. + import socket + hostname = socket.gethostname() + # Set up logging in a way that it can be understood by a human reader, be + # easily grep'ed, be parsed with a couple of shell commands and + # easily fed into an Kibana/Elastic search system. + logging.basicConfig(format = '%(asctime)s.%(msecs)d %(levelname)s - HOST="{}" PID="%(process)d" TNAME="%(threadName)s" TID="%(thread)d" FILE="%(pathname)s" LINE="%(lineno)d" FUNC="%(funcName)s" MSG="%(message)s"'.format(hostname), datefmt = '%Y-%m-%dT%H:%M:%S', level = logging.INFO, Force = True) diff --git a/lib/startup.py b/lib/startup.py new file mode 100755 index 0000000000000000000000000000000000000000..f98097f994afc340fdb168311bcb524445658f1d --- /dev/null +++ b/lib/startup.py @@ -0,0 +1,37 @@ +#! /usr/bin/env python3 + + +def startup(device: str, force_restart: bool): + ''' + Start a LOFAR Tango device: + pcc = startup(device = 'LTS/PCC/1', force_restart = False) + ''' + import tango + proxy = tango.DeviceProxy(device) + state = proxy.state() + + if force_restart is True: + print("Forcing device {} restart.".format(device)) + proxy.off() + state = proxy.state() + if state is not tango._tango.DevState.OFF: + print("Device {} cannot perform off although restart has been enforced, state = {}. Please investigate.".format(device, state)) + return proxy + if state is not tango._tango.DevState.OFF: + print("Device {} is not in OFF state, cannot start it. state = {}".format(device, state)) + return proxy + print("Device {} is in OFF, performing initialisation.".format(device)) + proxy.initialise() + state = proxy.state() + if state is not tango._tango.DevState.STANDBY: + print("Device {} cannot perform initialise, state = {}. Please investigate.".format(device, state)) + return proxy + print("Device {} is in STANDBY, performing on.".format(device)) + proxy.on() + state = proxy.state() + if state is not tango._tango.DevState.ON: + print("Device {} cannot perform on, state = {}. Please investigate.".format(device, state)) + else: + print("Device {} has successfully reached ON state.".format(device)) + return proxy +