Skip to content

Commit

Permalink
[tools] Fix telnetlib for Python 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
andryblack authored and salkinium committed Dec 15, 2024
1 parent 8fa0594 commit 05c81d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions repo.lb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ import platform
from pathlib import Path
from git import Repo
from os.path import normpath
from importlib.metadata import version

def StrictVersion(v):
return tuple(map(int, (v.split("."))))

# Check for miminum required lbuild version
import lbuild
min_lbuild_version = "1.21.6"
if StrictVersion(getattr(lbuild, "__version__", "0.1.0")) < StrictVersion(min_lbuild_version):
print("modm requires at least lbuild v{}, please upgrade!\n"
" pip3 install -U lbuild".format(min_lbuild_version))
if StrictVersion(version("lbuild")) < StrictVersion(min_lbuild_version):
print(f"modm requires at least lbuild v{min_lbuild_version}, please upgrade!\n"
" pip3 install -U lbuild")
exit(1)

min_modm_version = "0.2.1"
if StrictVersion(version("modm")) < StrictVersion(min_modm_version):
print(f"modm requires at least modm v{min_modm_version}, please upgrade!\n"
" pip3 install -U modm")
exit(1)

# Check for submodule existance and their version
Expand Down
7 changes: 5 additions & 2 deletions tools/modm_tools/jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import time
import signal
import platform
import telnetlib
import subprocess

from . import gdb
Expand Down Expand Up @@ -99,10 +98,14 @@ def itm(device, baudrate=None):


def rtt(backend, channel=0):
try:
import telnetlib as telnetlib3
except ImportError:
import telnetlib3
# Start JLinkGDBServer in the background
with backend.scope():
time.sleep(0.5)
with telnetlib.Telnet("localhost", 19021) as tn:
with telnetlib3.Telnet("localhost", 19021) as tn:
try:
tn.interact()
except KeyboardInterrupt:
Expand Down
7 changes: 5 additions & 2 deletions tools/modm_tools/openocd.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import signal
import tempfile
import platform
import telnetlib
import subprocess

from . import utils
Expand Down Expand Up @@ -126,11 +125,15 @@ def itm(backend, fcpu, baudrate=None):
pass

def rtt(backend, channel=0):
try:
import telnetlib as telnetlib3
except ImportError:
import telnetlib3
backend.commands.append("modm_rtt")
# Start OpenOCD in the background
with backend.scope():
time.sleep(0.5)
with telnetlib.Telnet("localhost", 9090+channel) as tn:
with telnetlib3.Telnet("localhost", 9090+channel) as tn:
try:
tn.interact()
except KeyboardInterrupt:
Expand Down

0 comments on commit 05c81d4

Please sign in to comment.