Skip to content

Commit

Permalink
Move serial error message text into function rather than as a global
Browse files Browse the repository at this point in the history
  • Loading branch information
Larbino1 authored Jun 4, 2024
1 parent adec320 commit 99dbbae
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions sksurgerynditracker/nditracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
from sksurgerynditracker.serial_utils.com_ports import \
fix_com_port_greater_than_9

SERIAL_CONNECTION_ERRMSG = """
Please check the following:\n
\t1) Is an NDI device connected to your computer?\n
\t2) Is the NDI device switched on?\n
\t3) Do you have sufficient privilege to connect to
the device? (e.g. on Linux are you part of the "dialout"
group?)'
"""

@contextlib.contextmanager
def _open_logging(verbose):
"""
Expand Down Expand Up @@ -55,6 +46,15 @@ def _get_serial_port_name(configuration):
:raises: IOError if port not found or port probe fails
"""

serial_connection_errmsg = """
Please check the following:\n
\t1) Is an NDI device connected to your computer?\n
\t2) Is the NDI device switched on?\n
\t3) Do you have sufficient privilege to connect to
the device? (e.g. on Linux are you part of the "dialout"
group?)'
"""

with _open_logging(configuration.get('verbose', False)) as fileout:
serial_port = configuration.get("serial port", None)
ports_to_probe = configuration.get("ports to probe", 20)
Expand All @@ -78,7 +78,7 @@ def _get_serial_port_name(configuration):
# If we did not break from the for loop:
raise IOError('Could not find any NDI device in '
f'{ports_to_probe} serial port candidates checked. '
+ SERIAL_CONNECTION_ERRMSG)
+ serial_connection_errmsg)

else:
if isinstance(serial_port, int):
Expand All @@ -90,7 +90,7 @@ def _get_serial_port_name(configuration):
else:
raise IOError(f'Could not connect to serial port {serial_port} '
f'as there are only {len(serial_ports)} ports available.'
+ SERIAL_CONNECTION_ERRMSG)
+ serial_connection_errmsg)

if isinstance(serial_port, str):
name = serial_port
Expand All @@ -100,7 +100,7 @@ def _get_serial_port_name(configuration):

if result != ndicapy.NDI_OKAY:
raise IOError(f'Could not connect to an NDI device on the chosen port, {serial_port}.'
+ SERIAL_CONNECTION_ERRMSG)
+ serial_connection_errmsg)
return name


Expand Down

0 comments on commit 99dbbae

Please sign in to comment.