diff --git a/extras/dump_iphone_video.py b/extras/dump_iphone_video.py index 127e0019..69d02825 100644 --- a/extras/dump_iphone_video.py +++ b/extras/dump_iphone_video.py @@ -1,4 +1,5 @@ import neurobooth_os.iout.iphone as iphone +from neurobooth_os.iout.lsl_streamer import get_device_assignment import neurobooth_os.config as cfg import re import os @@ -26,8 +27,8 @@ def neurobooth_dump(args: argparse.Namespace) -> None: args Command line arguments. """ - session_root = cfg.neurobooth_config.server_by_name(args.server).local_data_dir logger = logging.getLogger(APP_LOG_NAME) + session_root = cfg.neurobooth_config.current_server().local_data_dir logger.debug(f'Session Root: {session_root}') # Connect to the iPhone @@ -146,12 +147,6 @@ def parse_arguments() -> argparse.Namespace: type=int, help='Specify a timeout (in seconds) for each file retrieval. Default is 10 min. No timeout if <= 0.' ) - parser.add_argument( - '--server', - default='acquisition', - type=str, - help='Specify the server to run on so the proper value of local_data_dir is used. Default is "acquisition".' - ) args = parser.parse_args() if args.delete_zero_byte: @@ -171,6 +166,13 @@ def main(): logger = make_db_logger() iphone.DISABLE_LSL = True + # Check if we should be running the dump on this machine. + server_name = cfg.get_server_name_from_env() + if get_device_assignment('IPhone_dev_1') != server_name: + logger.debug(f'IPhone not assigned to {server_name}.') + return + + # Run and time the dump. args = parse_arguments() t0 = datetime.datetime.now() logger.info('Running Dump') diff --git a/neurobooth_os/__init__.py b/neurobooth_os/__init__.py index e7500121..c8a96b34 100644 --- a/neurobooth_os/__init__.py +++ b/neurobooth_os/__init__.py @@ -1,3 +1,3 @@ """Neurobooth OS""" -__version__ = "0.0.29.1" +__version__ = "0.0.30" diff --git a/neurobooth_os/iout/iphone.py b/neurobooth_os/iout/iphone.py index 392746c3..f4345947 100644 --- a/neurobooth_os/iout/iphone.py +++ b/neurobooth_os/iout/iphone.py @@ -191,8 +191,9 @@ def __init__(self, name, sess_id="", mock=False, device_args: DeviceArgs = None, self.iphone_sessionID = sess_id self.name = name self.mock = mock - self.device_id = device_args.device_id - self.sensor_ids = device_args.sensor_ids + if not DISABLE_LSL: # Device and sensor IDs are only needed if streaming data to LSL. + self.device_id = device_args.device_id + self.sensor_ids = device_args.sensor_ids self.enable_timeout_exceptions = enable_timeout_exceptions self.streaming = False self.streamName = "IPhoneFrameIndex" diff --git a/neurobooth_os/iout/lsl_streamer.py b/neurobooth_os/iout/lsl_streamer.py index 02d27a78..715af92f 100644 --- a/neurobooth_os/iout/lsl_streamer.py +++ b/neurobooth_os/iout/lsl_streamer.py @@ -105,6 +105,23 @@ def start_yeti_stream(_, device_args): ] +class DeviceNotFoundException(Exception): + """Exception raised when a given device ID cannot be found.""" + pass + + +def get_device_assignment(device_id: str) -> str: + """ + Return the server a device is assigned to. Raises a DeviceNotFoundException if the device is not found. + :param device_id: The ID of the device. + :return: The full name of the assigned server. + """ + for server_name, device_list in SERVER_ASSIGNMENTS.items(): + if device_id in device_list: + return server_name + raise DeviceNotFoundException(f'{device_id} is not assigned to any server.') + + # -------------------------------------------------------------------------------- # Handle the device life cycle # -------------------------------------------------------------------------------- diff --git a/neurobooth_os/server_acq.bat b/neurobooth_os/server_acq.bat index e63e105d..82ed2d13 100644 --- a/neurobooth_os/server_acq.bat +++ b/neurobooth_os/server_acq.bat @@ -1,3 +1,2 @@ call %NB_CONDA_INSTALL%\Scripts\activate.bat %NB_CONDA_ENV% start /W ipython --pdb %NB_INSTALL%\neurobooth_os\server_acq.py -start /W ipython %NB_INSTALL%\neurobooth_os\transfer_data.py acquisition diff --git a/neurobooth_os/server_ctr.bat b/neurobooth_os/server_ctr.bat index 5e6dfe4c..16da8573 100644 --- a/neurobooth_os/server_ctr.bat +++ b/neurobooth_os/server_ctr.bat @@ -1,3 +1,2 @@ call %NB_CONDA_INSTALL%\Scripts\activate.bat %NB_CONDA_ENV% start /W ipython --pdb %NB_INSTALL%\neurobooth_os\gui.py -start /W ipython %NB_INSTALL%\neurobooth_os\transfer_data.py control diff --git a/neurobooth_os/server_stm.bat b/neurobooth_os/server_stm.bat index 91c831f8..ecbd282d 100644 --- a/neurobooth_os/server_stm.bat +++ b/neurobooth_os/server_stm.bat @@ -1,3 +1,2 @@ call %NB_CONDA_INSTALL%\Scripts\activate.bat %NB_CONDA_ENV% start /W ipython --pdb %NB_INSTALL%\neurobooth_os\server_stm.py -start /W ipython %NB_INSTALL%\neurobooth_os\transfer_data.py presentation diff --git a/neurobooth_os/transfer_data.bat b/neurobooth_os/transfer_data.bat new file mode 100755 index 00000000..923566ad --- /dev/null +++ b/neurobooth_os/transfer_data.bat @@ -0,0 +1,3 @@ +call %NB_CONDA_INSTALL%\Scripts\activate.bat %NB_CONDA_ENV% +start /W ipython %NB_INSTALL%\extras\dump_iphone_video.py +start /W ipython %NB_INSTALL%\neurobooth_os\transfer_data.py diff --git a/neurobooth_os/transfer_data.py b/neurobooth_os/transfer_data.py index 6eb135db..68f45e10 100644 --- a/neurobooth_os/transfer_data.py +++ b/neurobooth_os/transfer_data.py @@ -7,7 +7,6 @@ import argparse from neurobooth_os import config -from neurobooth_os.util.constants import NODE_NAMES from neurobooth_os.log_manager import make_db_logger @@ -18,7 +17,7 @@ def log_output(pipe): def main(args: argparse.Namespace): destination = config.neurobooth_config.remote_data_dir - source = config.neurobooth_config.server_by_name(args.source_node_name).local_data_dir + source = config.neurobooth_config.current_server().local_data_dir try: # Move data to remote @@ -39,17 +38,10 @@ def main(args: argparse.Namespace): def parse_arguments() -> argparse.Namespace: - parser = argparse.ArgumentParser( prog='transfer_data', description='Transfer data copies data from local folders into remote storage.', ) - - parser.add_argument( - 'source_node_name', # positional argument - choices=NODE_NAMES, - help=f'You must provide the name of the node to transfer data from, which must be one of {NODE_NAMES}' - ) args = parser.parse_args() return args