From 5975c91e91dffd1c8b22c9b7db7379a09cf13eba Mon Sep 17 00:00:00 2001
From: Jorrit Schaap <schaap@astron.nl>
Date: Tue, 9 Feb 2016 11:31:54 +0000
Subject: [PATCH] Task #8887: moved main function to lib, import it in bin
 script

---
 .../Services/src/RATaskSpecified.py           | 28 +++++++++++++++++++
 .../Services/src/rataskspecifiedservice       | 26 ++---------------
 2 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/SAS/ResourceAssignment/Services/src/RATaskSpecified.py b/SAS/ResourceAssignment/Services/src/RATaskSpecified.py
index e05047d467f..c57c6089bab 100755
--- a/SAS/ResourceAssignment/Services/src/RATaskSpecified.py
+++ b/SAS/ResourceAssignment/Services/src/RATaskSpecified.py
@@ -226,3 +226,31 @@ class RATaskSpecified(OTDBBusListener):
 
     logger.info("Result sent")
 
+
+def main():
+    import sys
+    import logging
+    from optparse import OptionParser
+    from lofar.common.util import waitForInterrupt
+    from lofar.sas.resourceassignment.rataskspecified.config import DEFAULT_NOTIFICATION_BUSNAME, RATASKSPECIFIED_NOTIFICATIONNAME
+    DEFAULT_OTDB_BUSNAME = 'lofar.otdb.status'
+
+    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
+
+    # Check the invocation arguments
+    parser = OptionParser("%prog [options]",
+                          description="run the rataskspecified service")
+    parser.add_option("-o", "--otdb_bus", dest="otdb_busname", type="string", default=DEFAULT_OTDB_BUSNAME,
+                      help="Bus or queue OTDB operates on")
+    parser.add_option("-b", "--notification_bus", dest="notification_bus", type="string", default=DEFAULT_NOTIFICATION_BUSNAME,
+                      help="Bus or queue we publish resource requests on")
+    parser.add_option("-s", "--notification_subject", dest="notification_subject", type="string", default=RATASKSPECIFIED_NOTIFICATIONNAME,
+                      help="The subject of the event messages which this service publishes")
+    (options, args) = parser.parse_args()
+
+    with RATaskSpecified(RATASKSPECIFIED_NOTIFICATIONNAME, otdb_busname=options.otdb_busname, my_busname=options.notification_bus) as jts:
+        waitForInterrupt()
+
+
+if __name__ == "__main__":
+    main()
diff --git a/SAS/ResourceAssignment/Services/src/rataskspecifiedservice b/SAS/ResourceAssignment/Services/src/rataskspecifiedservice
index 8140e688fd5..1faf339ea90 100644
--- a/SAS/ResourceAssignment/Services/src/rataskspecifiedservice
+++ b/SAS/ResourceAssignment/Services/src/rataskspecifiedservice
@@ -25,30 +25,8 @@ Daemon that listens to OTDB status changes to PRESCHEDULED, requests
 the parset of such jobs (+ their predecessors), and posts them on the bus.
 """
 
-from lofar.sas.resourceassignment.rataskspecified.RATaskSpecified import RATaskSpecified
-from lofar.sas.resourceassignment.rataskspecified.config import DEFAULT_NOTIFICATION_BUSNAME, RATASKSPECIFIED_NOTIFICATIONNAME
-
-DEFAULT_OTDB_BUSNAME = 'lofar.otdb.status'
+from lofar.sas.resourceassignment.rataskspecified.RATaskSpecified import main
 
 if __name__ == "__main__":
-    import sys
-    import logging
-    from optparse import OptionParser
-    from lofar.common.util import waitForInterrupt
-
-    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO)
-
-    # Check the invocation arguments
-    parser = OptionParser("%prog [options]",
-                          description="run the rataskspecified service")
-    parser.add_option("-o", "--otdb_bus", dest="otdb_busname", type="string", default=DEFAULT_OTDB_BUSNAME,
-                      help="Bus or queue OTDB operates on")
-    parser.add_option("-b", "--notification_bus", dest="notification_bus", type="string", default=DEFAULT_NOTIFICATION_BUSNAME,
-                      help="Bus or queue we publish resource requests on")
-    parser.add_option("-s", "--notification_subject", dest="notification_subject", type="string", default=RATASKSPECIFIED_NOTIFICATIONNAME,
-                      help="The subject of the event messages which this service publishes")
-    (options, args) = parser.parse_args()
-
-    with RATaskSpecified(RATASKSPECIFIED_NOTIFICATIONNAME, otdb_busname=options.otdb_busname, my_busname=options.notification_bus) as jts:
-        waitForInterrupt()
+    main()
 
-- 
GitLab