Skip to content

Commit 02ae57a

Browse files
committed
Fix conflict and updated logger
1 parent 2c84cec commit 02ae57a

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

conan/internal/runner/output.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
from conan.api.output import Color, ConanOutput
22

33
class RunnerOutput(ConanOutput):
4-
def __init__(self, hostname: str):
4+
def __init__(self, runner_info: str):
55
super().__init__()
66
self.set_warnings_as_errors(True) # Make log errors blocker
7-
self._prefix = f"{hostname} | "
7+
self._prefix = f"{runner_info} | "
88

99
def _write_message(self, msg, fg=None, bg=None, newline=True):
10-
super()._write_message(self._prefix, Color.BLACK, Color.BRIGHT_YELLOW, newline=False)
11-
super()._write_message(msg, fg, bg, newline)
10+
for line in msg.splitlines():
11+
super()._write_message(self._prefix, Color.BLACK, Color.BRIGHT_YELLOW, newline=False)
12+
super()._write_message(line, fg, bg, newline)
1213

1314
@property
1415
def padding(self):
1516
return len(self._prefix) + 1
1617

18+

conan/internal/runner/ssh.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import tempfile
55

66
from conan.api.conan_api import ConanAPI
7-
from conan.api.output import Color
7+
from conan.api.output import Color, ConanOutput
88
from conan.errors import ConanException
99

1010
import os
@@ -38,9 +38,11 @@ def __init__(
3838
hostname = self._create_ssh_connection()
3939
except Exception as e:
4040
raise ConanException(f"Error creating SSH connection: {e}")
41-
self.logger = RunnerOutput(hostname)
41+
self.logger = ConanOutput()
42+
self.logger.set_warnings_as_errors(True)
43+
self.runner_logger = RunnerOutput(hostname)
4244
self.logger.status(f"Connected to {hostname}", fg=Color.BRIGHT_MAGENTA)
43-
self.remote_conn = RemoteConnection(self.client, self.logger)
45+
self.remote_conn = RemoteConnection(self.client, self.runner_logger)
4446

4547
def run(self):
4648
self._ensure_runner_environment()
@@ -136,7 +138,7 @@ def _ensure_runner_environment(self):
136138
self.logger.error(f"Unable to create remote venv: {result.stderr}")
137139
self._install_conan_remotely(python_command, requested_conan_version)
138140
else:
139-
version = self.remote_conn.run_command(f"{conan_cmd} --version").stdout
141+
version = self.remote_conn.run_command(f"{conan_cmd} --version", verbose=True).stdout
140142
remote_conan_version = Version(version[version.rfind(" ")+1:])
141143
if requested_conan_version == "dev" and remote_conan_version.bump(1) == str(conan_version).replace("-dev", ""):
142144
pass
@@ -172,8 +174,7 @@ def _create_remote_conan_wrapper(self, remote_conan_home: str, remote_folder: st
172174
conan_wrapper_contents = f"""{env_lines}\n{conan_cmd} $@\n"""
173175

174176
self.remote_conan = self.remote_conn.create_remote_script(conan_wrapper_contents, remote_folder + "/conan", self.is_remote_windows)
175-
conan_config_home = self.remote_conn.run_command(f"{self.remote_conan} config home").stdout
176-
self.logger.verbose(f"Remote conan config home returned: {conan_config_home}")
177+
self.remote_conn.run_command(f"{self.remote_conan} config home", verbose=True)
177178
if not self.remote_conn.run_command(f"{self.remote_conan} profile detect --force"):
178179
self.logger.error("Error creating default profile in remote machine")
179180

@@ -319,11 +320,15 @@ def __init__(self, success, stdout, stderr):
319320
self.stdout = stdout
320321
self.stderr = stderr
321322

322-
def run_command(self, command: str) -> RunResult:
323+
def run_command(self, command: str, verbose: bool = False) -> RunResult:
323324
_, stdout, stderr = self.client.exec_command(command)
324-
return RemoteConnection.RunResult(stdout.channel.recv_exit_status() == 0,
325-
stdout.read().decode().strip(),
326-
stderr.read().decode().strip())
325+
log = self.logger.status if verbose else self.logger.verbose
326+
log(f'$ {command}', fg=Color.BLUE)
327+
result = RemoteConnection.RunResult(stdout.channel.recv_exit_status() == 0,
328+
stdout.read().decode().strip(),
329+
stderr.read().decode().strip())
330+
log(f"{result.stdout}")
331+
return result
327332

328333
def run_interactive_command(self, command: str, is_remote_windows: bool) -> bool:
329334
''' Run a command in an SSH session.
@@ -366,6 +371,5 @@ def replace_cursor_match(match):
366371
# sys.stdout.buffer.write(line)
367372
# sys.stdout.buffer.flush()
368373
line = remove_cursor_movements(line.replace(b'\r', b'').decode(errors='ignore').strip())
369-
for l in line.splitlines():
370-
self.logger.status(l)
374+
self.logger.status(line)
371375
return stdout.channel.recv_exit_status() == 0

0 commit comments

Comments
 (0)