From a954b1b42370eb445f2cd676b2b1fe669c73a149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 20 May 2025 13:35:45 +0200 Subject: [PATCH 1/4] mypy: ignore clan_lib.nixpkgs --- pkgs/clan-cli/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clan-cli/pyproject.toml b/pkgs/clan-cli/pyproject.toml index 85ae19b24..b60ed1ea6 100644 --- a/pkgs/clan-cli/pyproject.toml +++ b/pkgs/clan-cli/pyproject.toml @@ -58,4 +58,4 @@ warn_redundant_casts = true disallow_untyped_calls = true disallow_untyped_defs = true no_implicit_optional = true -exclude = "clan_cli.nixpkgs" +exclude = "clan_lib.nixpkgs" From e2af06352850d94e3fc1648926b7dc0c1034731e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 20 May 2025 13:10:35 +0200 Subject: [PATCH 2/4] upload: stream tarball rather than read at once --- pkgs/clan-cli/clan_cli/ssh/upload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/ssh/upload.py b/pkgs/clan-cli/clan_cli/ssh/upload.py index 1e6af15a2..815634dd7 100644 --- a/pkgs/clan-cli/clan_cli/ssh/upload.py +++ b/pkgs/clan-cli/clan_cli/ssh/upload.py @@ -109,7 +109,7 @@ def upload( f"{dir_mode:o}", ], RunOpts( - input=f.read(), + input=f, log=Log.BOTH, prefix=host.command_prefix, needs_user_terminal=True, From 9c4333abcb840ed675489ebc486f3b5ad182f900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 20 May 2025 13:11:37 +0200 Subject: [PATCH 3/4] cmd/run: dont run logging code unless we have debugging enabled. --- pkgs/clan-cli/clan_lib/cmd/__init__.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pkgs/clan-cli/clan_lib/cmd/__init__.py b/pkgs/clan-cli/clan_lib/cmd/__init__.py index f0cbc3c3c..30c277745 100644 --- a/pkgs/clan-cli/clan_lib/cmd/__init__.py +++ b/pkgs/clan-cli/clan_lib/cmd/__init__.py @@ -342,18 +342,22 @@ def run( if options.requires_root_perm: cmd = cmd_with_root(cmd, options.graphical_perm) - if options.input and isinstance(options.input, bytes): - if any(not ch.isprintable() for ch in options.input.decode("ascii", "replace")): - filtered_input = "<>" + if cmdlog.isEnabledFor(logging.DEBUG): + if options.input and isinstance(options.input, bytes): + if any( + not ch.isprintable() for ch in options.input.decode("ascii", "replace") + ): + filtered_input = "<>" + else: + filtered_input = options.input.decode("ascii", "replace") + + print_trace( + f"echo '{filtered_input}' | {indent_command(cmd)}", + cmdlog, + options.prefix, + ) else: - filtered_input = options.input.decode("ascii", "replace") - print_trace( - f"echo '{filtered_input}' | {indent_command(cmd)}", - cmdlog, - options.prefix, - ) - elif cmdlog.isEnabledFor(logging.DEBUG): - print_trace(f"{indent_command(cmd)}", cmdlog, options.prefix) + print_trace(f"{indent_command(cmd)}", cmdlog, options.prefix) start = timeit.default_timer() with ExitStack() as stack: From 2f2af072e411f72bdba47f76ac748b96792dc7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 20 May 2025 13:17:41 +0200 Subject: [PATCH 4/4] upload: hide upload command by default --- pkgs/clan-cli/clan_cli/ssh/host.py | 17 ++++++++++------- pkgs/clan-cli/clan_cli/ssh/upload.py | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/ssh/host.py b/pkgs/clan-cli/clan_cli/ssh/host.py index 39acea75f..52a1d24c2 100644 --- a/pkgs/clan-cli/clan_cli/ssh/host.py +++ b/pkgs/clan-cli/clan_cli/ssh/host.py @@ -130,6 +130,7 @@ class Host: extra_env: dict[str, str] | None = None, tty: bool = False, verbose_ssh: bool = False, + quiet: bool = False, ) -> CmdOut: """ Command to run on the host via ssh @@ -166,13 +167,15 @@ class Host: export_cmd = f"export {' '.join(env_vars)}; " displayed_cmd += export_cmd displayed_cmd += " ".join(cmd) - cmdlog.info( - f"$ {displayed_cmd}", - extra={ - "command_prefix": self.command_prefix, - "color": AnsiColor.GREEN.value, - }, - ) + + if not quiet: + cmdlog.info( + f"$ {displayed_cmd}", + extra={ + "command_prefix": self.command_prefix, + "color": AnsiColor.GREEN.value, + }, + ) # Build the ssh command bash_cmd = export_cmd diff --git a/pkgs/clan-cli/clan_cli/ssh/upload.py b/pkgs/clan-cli/clan_cli/ssh/upload.py index 815634dd7..ef76d7718 100644 --- a/pkgs/clan-cli/clan_cli/ssh/upload.py +++ b/pkgs/clan-cli/clan_cli/ssh/upload.py @@ -108,7 +108,8 @@ def upload( str(remote_dest), f"{dir_mode:o}", ], - RunOpts( + quiet=True, + opts=RunOpts( input=f, log=Log.BOTH, prefix=host.command_prefix,