|
13 | 13 | import signal |
14 | 14 | import sys |
15 | 15 | import shlex |
| 16 | +import shutil |
16 | 17 | import json |
17 | 18 | from textwrap import indent |
18 | 19 | from socket import gethostname |
@@ -826,18 +827,32 @@ async def _console(self, place, target, timeout, *, logfile=None, loop=False, li |
826 | 827 | # check for valid resources |
827 | 828 | assert port is not None, "Port is not set" |
828 | 829 |
|
829 | | - call = ["microcom", "-s", str(resource.speed), "-t", f"{host}:{port}"] |
| 830 | + microcom_bin = shutil.which("microcom") |
830 | 831 |
|
831 | | - if listen_only: |
832 | | - call.append("--listenonly") |
| 832 | + if microcom_bin is not None: |
| 833 | + call = [microcom_bin, "-s", str(resource.speed), "-t", f"{host}:{port}"] |
| 834 | + |
| 835 | + if listen_only: |
| 836 | + call.append("--listenonly") |
| 837 | + |
| 838 | + if logfile: |
| 839 | + call.append(f"--logfile={logfile}") |
| 840 | + else: |
| 841 | + call = ["telnet", host, str(port)] |
| 842 | + |
| 843 | + logging.info("microcom not available, using telnet instead") |
| 844 | + |
| 845 | + if listen_only: |
| 846 | + logging.warning("--listenonly option not supported by telnet, ignoring") |
| 847 | + |
| 848 | + if logfile: |
| 849 | + logging.warning("--logfile option not supported by telnet, ignoring") |
833 | 850 |
|
834 | | - if logfile: |
835 | | - call.append(f"--logfile={logfile}") |
836 | 851 | print(f"connecting to {resource} calling {' '.join(call)}") |
837 | 852 | try: |
838 | 853 | p = await asyncio.create_subprocess_exec(*call) |
839 | 854 | except FileNotFoundError as e: |
840 | | - raise ServerError(f"failed to execute microcom: {e}") |
| 855 | + raise ServerError(f"failed to execute remote console command: {e}") |
841 | 856 | while p.returncode is None: |
842 | 857 | try: |
843 | 858 | await asyncio.wait_for(p.wait(), 1.0) |
|
0 commit comments