From 411e9a0459edb9d3520e0f1859fbed2e01cfa800 Mon Sep 17 00:00:00 2001
From: lukken <lukken@astron.nl>
Date: Wed, 3 Nov 2021 15:14:32 +0000
Subject: [PATCH] L2SS-471: apspu and apsct packaged entrypoints

---
 bin/start-ds.sh                               |  2 +-
 docker-compose/device-apsct.yml               |  9 ++---
 docker-compose/device-apspu.yml               |  9 ++---
 docker-compose/device-boot.yml                |  1 +
 tangostationcontrol/setup.cfg                 |  6 ++--
 .../tangostationcontrol/devices/apsct.py      | 33 ++++++-----------
 .../tangostationcontrol/devices/apspu.py      | 35 ++++++-------------
 7 files changed, 32 insertions(+), 63 deletions(-)

diff --git a/bin/start-ds.sh b/bin/start-ds.sh
index e7fab7e93..7b601c4c8 100755
--- a/bin/start-ds.sh
+++ b/bin/start-ds.sh
@@ -25,7 +25,7 @@ else
   mkdir -p /tmp/tangostationcontrol
   python3 setup.py build --build-base /tmp/tangostationcontrol egg_info --egg-base /tmp/tangostationcontrol bdist_wheel --dist-dir /tmp/tangostationcontrol || exit 1
   # shellcheck disable=SC2012
-  sudo pip install "$(ls -Art /tmp/tangostationcontrol/*.whl | tail -n 1)"
+  sudo pip install --force-reinstall "$(ls -Art /tmp/tangostationcontrol/*.whl | tail -n 1)"
 fi
 
 /usr/local/bin/wait-for-it.sh "$TANGO_HOST" --timeout=30 --strict -- "$@"
diff --git a/docker-compose/device-apsct.yml b/docker-compose/device-apsct.yml
index 3d5a2e034..bab24bd77 100644
--- a/docker-compose/device-apsct.yml
+++ b/docker-compose/device-apsct.yml
@@ -32,13 +32,10 @@ services:
         - ..:/opt/lofar/tango:rw
     environment:
       - TANGO_HOST=${TANGO_HOST}
+    working_dir: /opt/lofar/tango
     entrypoint:
-      - /usr/local/bin/wait-for-it.sh
-      - ${TANGO_HOST}
-      - --timeout=30
-      - --strict
-      - --
+      - bin/start-ds.sh
       # configure CORBA to _listen_ on 0:port, but tell others we're _reachable_ through ${HOSTNAME}:port, since CORBA
       # can't know about our Docker port forwarding
-      - python3 -u /opt/lofar/tango/devices/devices/apsct.py STAT -v -ORBendPoint giop:tcp:0:5709 -ORBendPointPublish giop:tcp:${HOSTNAME}:5709
+      - l2ss-apspu Apsct STAT -v  -v -ORBendPoint giop:tcp:0:5709 -ORBendPointPublish giop:tcp:${HOSTNAME}:5709
     restart: on-failure
diff --git a/docker-compose/device-apspu.yml b/docker-compose/device-apspu.yml
index 04b89ac4a..b694b0951 100644
--- a/docker-compose/device-apspu.yml
+++ b/docker-compose/device-apspu.yml
@@ -32,13 +32,10 @@ services:
         - ..:/opt/lofar/tango:rw
     environment:
       - TANGO_HOST=${TANGO_HOST}
+    working_dir: /opt/lofar/tango
     entrypoint:
-      - /usr/local/bin/wait-for-it.sh
-      - ${TANGO_HOST}
-      - --timeout=30
-      - --strict
-      - --
+      - bin/start-ds.sh
       # configure CORBA to _listen_ on 0:port, but tell others we're _reachable_ through ${HOSTNAME}:port, since CORBA
       # can't know about our Docker port forwarding
-      - python3 -u /opt/lofar/tango/devices/devices/apspu.py STAT -v -ORBendPoint giop:tcp:0:5710 -ORBendPointPublish giop:tcp:${HOSTNAME}:5710
+      - l2ss-apspu Apspu STAT -v -ORBendPoint giop:tcp:0:5710 -ORBendPointPublish giop:tcp:${HOSTNAME}:5710
     restart: on-failure
diff --git a/docker-compose/device-boot.yml b/docker-compose/device-boot.yml
index 9a4a13ff7..3db111410 100644
--- a/docker-compose/device-boot.yml
+++ b/docker-compose/device-boot.yml
@@ -31,6 +31,7 @@ services:
       - ..:/opt/lofar/tango:rw
     environment:
       - TANGO_HOST=${TANGO_HOST}
+    working_dir: /opt/lofar/tango
     entrypoint:
       - bin/start-ds.sh
       # configure CORBA to _listen_ on 0:port, but tell others we're _reachable_ through ${HOSTNAME}:port, since CORBA
diff --git a/tangostationcontrol/setup.cfg b/tangostationcontrol/setup.cfg
index daee0edbf..e6101c890 100644
--- a/tangostationcontrol/setup.cfg
+++ b/tangostationcontrol/setup.cfg
@@ -34,6 +34,8 @@ where=./
 
 [options.entry_points]
 console_scripts =
+    l2ss-apsct = tangostationcontrol.devices.apsct:main
+    l2ss-apspu = tangostationcontrol.devices.apspu:main
     l2ss-boot = tangostationcontrol.devices.boot:main
     l2ss-docker-device = tangostationcontrol.devices.docker_device:main
     l2ss-observation = tangostationcontrol.devices.observation:main
@@ -41,10 +43,10 @@ console_scripts =
     l2ss-receiver = tangostationcontrol.devices.recv:main
     l2ss-sdp = tangostationcontrol.devices.sdp.sdp:main
     l2ss-sst = tangostationcontrol.devices.sdp.sst:main
-    l2ss-unb2 = tangostationcontrol.devices.unb2:main
-    l2ss-xst = tangostationcontrol.devices.sdp.xst:main
     l2ss-statistics-reader = tangostationcontrol.statistics_writer.statistics_reader:main
     l2ss-statistics-writer = tangostationcontrol.statistics_writer.statistics_writer:main
+    l2ss-unb2 = tangostationcontrol.devices.unb2:main
+    l2ss-xst = tangostationcontrol.devices.sdp.xst:main
 
 # The following entry points should eventually be removed / replaced
     l2ss-cold-start = tangostationcontrol.toolkit.lts_cold_start:main
diff --git a/tangostationcontrol/tangostationcontrol/devices/apsct.py b/tangostationcontrol/tangostationcontrol/devices/apsct.py
index 78a0626d8..fd795f823 100644
--- a/tangostationcontrol/tangostationcontrol/devices/apsct.py
+++ b/tangostationcontrol/tangostationcontrol/devices/apsct.py
@@ -11,31 +11,25 @@
 
 """
 
-# TODO(Corne): Remove sys.path.append hack once packaging is in place!
-import os, sys
-currentdir = os.path.dirname(os.path.realpath(__file__))
-parentdir = os.path.dirname(currentdir)
-sys.path.append(parentdir)
-
 # PyTango imports
 from tango import DebugIt
 from tango.server import run, command
-from tango.server import device_property, attribute
 from tango import AttrWriteType
 import numpy
 # Additional import
 
-from device_decorators import *
-
-from clients.attribute_wrapper import attribute_wrapper
-from devices.opcua_device import opcua_device
-from common.lofar_logging import device_logging_to_python, log_exceptions
+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.devices.device_decorators import *
+from tangostationcontrol.devices.opcua_device import opcua_device
 
 import logging
 logger = logging.getLogger()
 
 __all__ = ["APSCT", "main"]
 
+
 @device_logging_to_python()
 class APSCT(opcua_device):
     # -----------------
@@ -130,17 +124,10 @@ class APSCT(opcua_device):
         """
         self.opcua_connection.call_method(["CLK_PLL_setup"])
 
+
 # ----------
 # Run server
 # ----------
-def main(args=None, **kwargs):
-    """Main function of the APSCT module."""
-
-    from common.lofar_logging import configure_logger
-    configure_logger()
-
-    return run((APSCT,), args=args, **kwargs)
-
-
-if __name__ == '__main__':
-    main()
+def main(**kwargs):
+    """Main function of the ObservationControl module."""
+    return entry(APSCT, **kwargs)
diff --git a/tangostationcontrol/tangostationcontrol/devices/apspu.py b/tangostationcontrol/tangostationcontrol/devices/apspu.py
index 3daab9c07..88a677fcb 100644
--- a/tangostationcontrol/tangostationcontrol/devices/apspu.py
+++ b/tangostationcontrol/tangostationcontrol/devices/apspu.py
@@ -11,28 +11,20 @@
 
 """
 
-# TODO(Corne): Remove sys.path.append hack once packaging is in place!
-import os, sys
-currentdir = os.path.dirname(os.path.realpath(__file__))
-parentdir = os.path.dirname(currentdir)
-sys.path.append(parentdir)
-
 # PyTango imports
-from tango import DebugIt
-from tango.server import run, command
-from tango.server import device_property, attribute
 from tango import AttrWriteType
 import numpy
 # Additional import
 
-from device_decorators import *
-
-from clients.attribute_wrapper import attribute_wrapper
-from devices.opcua_device import opcua_device
-from common.lofar_logging import device_logging_to_python, log_exceptions
+from tangostationcontrol.devices.device_decorators 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
 
 __all__ = ["APSPU", "main"]
 
+
 @device_logging_to_python()
 class APSPU(opcua_device):
     # -----------------
@@ -71,17 +63,10 @@ class APSPU(opcua_device):
     # Commands
     # --------
 
+
 # ----------
 # Run server
 # ----------
-def main(args=None, **kwargs):
-    """Main function of the APSPU module."""
-
-    from common.lofar_logging import configure_logger
-    configure_logger()
-
-    return run((APSPU,), args=args, **kwargs)
-
-
-if __name__ == '__main__':
-    main()
+def main(**kwargs):
+    """Main function of the ObservationControl module."""
+    return entry(APSPU, **kwargs)
-- 
GitLab