Skip to content

Commit

Permalink
Merge pull request #70 from SteelPh0enix/calldwell-uart-support
Browse files Browse the repository at this point in the history
Calldwell: UART support
  • Loading branch information
SteelPh0enix authored Oct 18, 2023
2 parents 197fa02 + 080fe69 commit 0700d2e
Show file tree
Hide file tree
Showing 6 changed files with 574 additions and 9 deletions.
13 changes: 9 additions & 4 deletions calldwell/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ readme = "README.md"
python = "^3.9"
pygdbmi = "^0.11.0.0"
paramiko = "^3.3.1"
option = "^2.1.0"

[tool.poetry.group.dev.dependencies]
black = "^23.9.1"
mypy = "^1.5.1"
pylint = "^2.17.5"
ruff = "^0.0.289"
mypy = "^1.6.0"
pylint = "^3.0.1"
ruff = "^0.0.292"
types-paramiko = "^3.3.0.0"

[tool.black]
Expand Down Expand Up @@ -64,7 +65,9 @@ select = [
"PERF", # perflint
"RUF", # ruff-specific rules
]
ignore = []
ignore = [
"TD003", # We don't want to link stuff to TODOs
]

[tool.ruff.pylint]
max-args = 6
Expand Down Expand Up @@ -101,6 +104,8 @@ logging-not-lazy,
locally-disabled,
suppressed-message,
import-error,
use-implicit-booleaness-not-comparison-to-zero,
duplicate-code,
'''


Expand Down
2 changes: 1 addition & 1 deletion calldwell/rust_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def _initialize_rtt(
if not gdb.setup_rtt(rtt_address, RTT_SECTION_SEARCHED_MEMORY_LENGTH, RTT_SECTION_ID):
logging.error(
f"Could not setup RTT for section @ {rtt_address} "
"(searched {RTT_SECTION_SEARCHED_MEMORY_LENGTH} bytes)",
f"(searched {RTT_SECTION_SEARCHED_MEMORY_LENGTH} bytes)",
)
return None

Expand Down
20 changes: 16 additions & 4 deletions calldwell/ssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(self: SSHClient, host: str, login: str, password: str, port: int =
* `password` - user password
* `port` - SSH port, default: 22
"""
self._host = host
self.client: paramiko.SSHClient = paramiko.SSHClient()
self.client.load_system_host_keys()
self.client.connect(hostname=host, port=port, username=login, password=password)
Expand All @@ -37,13 +38,19 @@ class CommandChannels:
stdout: ChannelFile
stderr: ChannelStderrFile

@property
def host(self: SSHClient) -> str:
"""Returns hostname of the client"""
return self._host

def execute(
self: SSHClient,
command: str,
timeout: float | None = None,
environment: dict[str, str] | None = None,
) -> CommandChannels:
"""Executes a command on remote, returns `stdin`, `stdout`, `stderr` wrapped in dataclass.
) -> tuple[int, CommandChannels]:
"""Executes a command on remote, returns PID of created process and `stdin`, `stdout`,
`stderr` wrapped in dataclass.
# Parameters
* `command` - command (and arguments) to be executed, in form of a single string
Expand All @@ -52,12 +59,17 @@ def execute(
* `environment` - additional environment variables for executed program.
"""

# This will start a new shell, echo it's PID, and replace it with command.
# That way, we can safely get the PID of executed process before it starts.
stdin, stdout, stderr = self.client.exec_command(
command,
f"sh -c 'echo $$; exec {command}'",
timeout=timeout,
environment=environment,
)
return self.CommandChannels(stdin, stdout, stderr)

# Consume the PID from output
pid = int(stdout.readline())
return (pid, self.CommandChannels(stdin, stdout, stderr))

def upload_file_to_remote(
self: SSHClient,
Expand Down
Loading

0 comments on commit 0700d2e

Please sign in to comment.