diff --git a/LCS/PyCommon/lcu_utils.py b/LCS/PyCommon/lcu_utils.py index e4e3abe0c7373142f9c9cf1ce1c30a51b25a9c37..97916ce208fc9799cc0e2459a2844fb9fc0fbee4 100644 --- a/LCS/PyCommon/lcu_utils.py +++ b/LCS/PyCommon/lcu_utils.py @@ -88,6 +88,30 @@ def execute_in_parallel_over_station_group(cmd, station_group='today', timeout=3 stations = get_current_stations(station_group=station_group, as_host_names=True) return execute_in_parallel_over_stations(cmd=cmd, stations=stations, timeout=timeout, max_parallel=max_parallel) +def translate_user_station_string_into_station_list(user_station_string: str): + ''' + try to deal with user input like 'cs001,cs001' or 'today' or ... etc + No guarantees! just best effort! + :param user_station_string: a string like 'cs001,cs001' or 'today' or ... etc + :return: a list of station names + ''' + if isinstance(user_station_string, bytes): + user_station_string = user_station_string.decode('utf-8') + + if not isinstance(user_station_string, str): + raise ValueError("cannot parse user_station_string") + + if ',' in user_station_string: + return user_station_string.split(',') + + # maybe 'stations' is a group. Do lookup. + current_stations = get_current_stations(user_station_string, as_host_names=False) + if current_stations: + return current_stations + + # just treat the stations string as list of stations and hope for the best + return [user_station_string] + def get_current_stations(station_group='today', as_host_names=True): ''' Wrapper function around the amazing lcurun and stations.txt operators system. diff --git a/MAC/TBB/lib/tbb_freeze.py b/MAC/TBB/lib/tbb_freeze.py index 815426bac1c2391fb7937176631f11dd8fa2722a..e9edd9be0bd07e793d55e066bd55366eea075626 100755 --- a/MAC/TBB/lib/tbb_freeze.py +++ b/MAC/TBB/lib/tbb_freeze.py @@ -14,7 +14,7 @@ logger = logging.getLogger(__name__) from lofar.mac.tbb.tbb_config import lcurun_command, tbb_command from lofar.mac.tbb.tbb_util import split_stations_by_boardnumber -from lofar.common.lcu_utils import execute_in_parallel_over_stations +from lofar.common.lcu_utils import execute_in_parallel_over_stations, translate_user_station_string_into_station_list from lofar.common.subprocess_utils import wrap_composite_command def freeze_tbb(stations, dm, timesec, timensec): @@ -26,8 +26,7 @@ def freeze_tbb(stations, dm, timesec, timensec): :return: """ - if isinstance(stations, str): - stations = stations.split(',') + stations = translate_user_station_string_into_station_list(stations) logger.info('Freezing TBB boards for stations: %s', ', '.join(stations)) @@ -91,6 +90,7 @@ def parse_args(): if args.dm is None: logger.error("No dm provided") + parser.print_help() exit(1) return args diff --git a/MAC/TBB/lib/tbb_load_firmware.py b/MAC/TBB/lib/tbb_load_firmware.py index 65e9e2ba355b6427266117a12cba90b6426e613f..29cdfe224e6dac7c58b20215e248fd9d6ed2dc4f 100755 --- a/MAC/TBB/lib/tbb_load_firmware.py +++ b/MAC/TBB/lib/tbb_load_firmware.py @@ -11,7 +11,7 @@ import time import subprocess import logging from lofar.mac.tbb.tbb_config import supported_modes, lcurun_command, tbb_command - +from lofar.common.lcu_utils import translate_user_station_string_into_station_list def load_tbb_firmware(stations, mode): logging.info('Loading TBB firmware for mode \"%s\"' % (mode)) @@ -26,6 +26,8 @@ def load_tbb_firmware(stations, mode): else: slot = 1 + stations = translate_user_station_string_into_station_list(stations) + logging.info("It is assumed that the firmware for mode \"%s\" is in slot %d!" % (mode, slot)) relay = lcurun_command + [stations] diff --git a/MAC/TBB/lib/tbb_release_recording.py b/MAC/TBB/lib/tbb_release_recording.py index 7763247134e088cef6e2c8f17e179056ec160660..8e7435259a1c81a25ed4e20024e43e5077998d40 100755 --- a/MAC/TBB/lib/tbb_release_recording.py +++ b/MAC/TBB/lib/tbb_release_recording.py @@ -11,10 +11,12 @@ import time import subprocess import logging from lofar.mac.tbb.tbb_config import lcurun_command, tbb_command +from lofar.common.lcu_utils import translate_user_station_string_into_station_list def release_tbb(stations): logging.info('Releasing TBB recording') + stations = translate_user_station_string_into_station_list(stations) relay = lcurun_command + [stations] cmd = relay + [tbb_command, '--free'] diff --git a/MAC/TBB/lib/tbb_restart_recording.py b/MAC/TBB/lib/tbb_restart_recording.py index 9f1b869b245ce75358d5f19a296e5daf102ecd88..4dd5f2e2b8bac2a4835a6fcdb3d180fdb5c50420 100755 --- a/MAC/TBB/lib/tbb_restart_recording.py +++ b/MAC/TBB/lib/tbb_restart_recording.py @@ -12,11 +12,14 @@ import time import subprocess import logging from lofar.mac.tbb.tbb_config import supported_modes, lcurun_command, tbb_command +from lofar.common.lcu_utils import translate_user_station_string_into_station_list def restart_tbb_recording(stations): logging.info("Restarting TBB recording") + stations = translate_user_station_string_into_station_list(stations) + relay = lcurun_command + [stations] cmd = relay + [tbb_command, "--record"] logging.info("Executing %s" % " ".join(cmd)) diff --git a/MAC/TBB/lib/tbb_set_storage.py b/MAC/TBB/lib/tbb_set_storage.py index 85f90740b5483c2c815a1eea47fdabfe58901fae..60f620661feba61b07f84f5f0c845900f1e1e55c 100755 --- a/MAC/TBB/lib/tbb_set_storage.py +++ b/MAC/TBB/lib/tbb_set_storage.py @@ -11,11 +11,14 @@ import time import subprocess import logging from lofar.mac.tbb.tbb_config import lcurun_command, tbb_command +from lofar.common.lcu_utils import translate_user_station_string_into_station_list def set_tbb_storage(map): logging.info('Setting TBB storage nodes') for stations, node in map.items(): + stations = translate_user_station_string_into_station_list(stations) + relay = lcurun_command + [stations] cmds = [ @@ -53,6 +56,7 @@ def create_mapping(stations, nodes): :param nodes: list of nodes :return: dict mapping stations to nodes, e.g. {station1: node1, station2: node2} """ + stations = translate_user_station_string_into_station_list(stations) # zip truncates to shortest list, so make sure there are enough nodes, then map each station to a node logging.info("Mapping stations %s on %s nodes " % (stations, nodes)) diff --git a/MAC/TBB/lib/tbb_start_recording.py b/MAC/TBB/lib/tbb_start_recording.py index 118edde5098ba82e23ae41fc7228f771654e7a3b..61877a912ffb9b7f13bfd7eea65412529bd1831a 100755 --- a/MAC/TBB/lib/tbb_start_recording.py +++ b/MAC/TBB/lib/tbb_start_recording.py @@ -11,6 +11,7 @@ import time import subprocess import logging from lofar.mac.tbb.tbb_config import supported_modes, lcurun_command, tbb_command, rsp_command +from lofar.common.lcu_utils import translate_user_station_string_into_station_list def start_tbb(stations, mode, subbands): @@ -31,6 +32,8 @@ def start_tbb(stations, mode, subbands): [tbb_command, '--record'] ] + stations = translate_user_station_string_into_station_list(stations) + relay = lcurun_command + [stations] for cmd in cmds: diff --git a/MAC/TBB/lib/tbb_upload_to_cep.py b/MAC/TBB/lib/tbb_upload_to_cep.py index dace5fd8360d315abb5fd65498a292fb42b39c32..dd8fb859e4411d37bf13f7e986db381b3c9f4f9f 100755 --- a/MAC/TBB/lib/tbb_upload_to_cep.py +++ b/MAC/TBB/lib/tbb_upload_to_cep.py @@ -13,6 +13,7 @@ import logging from lofar.mac.tbb.tbb_config import * from lofar.mac.tbb.tbb_util import split_stations_by_boardnumber, expand_list, calculate_adjusted_start_time, wrap_remote_composite_command from lofar.common.lcu_utils import execute_in_parallel_over_stations +from lofar.common.lcu_utils import translate_user_station_string_into_station_list def upload_tbb_data(stations, dm, start_time, duration, sub_bands, wait_time, boards): """ @@ -27,6 +28,8 @@ def upload_tbb_data(stations, dm, start_time, duration, sub_bands, wait_time, bo """ logging.info("Uploadind TBB data...") + stations = translate_user_station_string_into_station_list(stations) + # determine number of tbb boards per station: stationlists = split_stations_by_boardnumber(stations)