Skip to content
Snippets Groups Projects
Commit e86c278c authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

SW-818: handle user input for station groups

parent c0d06439
No related branches found
No related tags found
2 merge requests!62Lofar release 4 0 into master,!61SW-818: Resolve SW-818
......@@ -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.
......
......@@ -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
......
......@@ -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]
......
......@@ -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']
......
......@@ -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))
......
......@@ -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))
......
......@@ -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:
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment