clan: add run_no_stdout
function suppressing stdout
#1472
@ -140,3 +140,23 @@ def run(
|
|||||||
raise ClanCmdError(cmd_out)
|
raise ClanCmdError(cmd_out)
|
||||||
|
|
||||||
return cmd_out
|
return cmd_out
|
||||||
|
|
||||||
|
|
||||||
|
def run_no_stdout(
|
||||||
|
cmd: list[str],
|
||||||
|
*,
|
||||||
|
env: dict[str, str] | None = None,
|
||||||
|
cwd: Path = Path.cwd(),
|
||||||
|
log: Log = Log.STDERR,
|
||||||
|
check: bool = True,
|
||||||
|
error_msg: str | None = None,
|
||||||
|
) -> CmdOut:
|
||||||
|
"""
|
||||||
|
Like run, but automatically suppresses stdout, if not in DEBUG log level.
|
||||||
|
If in DEBUG log level the stdout of commands will be shown.
|
||||||
|
"""
|
||||||
|
if logging.getLogger(__name__.split(".")[0]).isEnabledFor(logging.DEBUG):
|
||||||
|
return run(cmd, env=env, log=log, check=check, error_msg=error_msg)
|
||||||
|
else:
|
||||||
|
log = Log.NONE
|
||||||
|
return run(cmd, env=env, log=log, check=check, error_msg=error_msg)
|
||||||
|
@ -6,7 +6,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
from clan_cli.api import API
|
from clan_cli.api import API
|
||||||
|
|
||||||
from ..cmd import Log, run
|
from ..cmd import run_no_stdout
|
||||||
from ..nix import nix_config, nix_eval
|
from ..nix import nix_config, nix_eval
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -34,10 +34,7 @@ def list_machines(flake_url: str | Path, debug: bool) -> dict[str, MachineInfo]:
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
if not debug:
|
proc = run_no_stdout(cmd)
|
||||||
proc = run(cmd, log=Log.NONE)
|
|
||||||
else:
|
|
||||||
proc = run(cmd)
|
|
||||||
|
|
||||||
res = proc.stdout.strip()
|
res = proc.stdout.strip()
|
||||||
machines_dict = json.loads(res)
|
machines_dict = json.loads(res)
|
||||||
|
@ -10,7 +10,7 @@ from clan_cli.clan_uri import ClanURI, MachineData
|
|||||||
from clan_cli.dirs import vm_state_dir
|
from clan_cli.dirs import vm_state_dir
|
||||||
from clan_cli.qemu.qmp import QEMUMonitorProtocol
|
from clan_cli.qemu.qmp import QEMUMonitorProtocol
|
||||||
|
|
||||||
from ..cmd import run
|
from ..cmd import run_no_stdout
|
||||||
from ..errors import ClanError
|
from ..errors import ClanError
|
||||||
from ..nix import nix_build, nix_config, nix_eval, nix_metadata
|
from ..nix import nix_build, nix_config, nix_eval, nix_metadata
|
||||||
from ..ssh import Host, parse_deployment_address
|
from ..ssh import Host, parse_deployment_address
|
||||||
@ -197,7 +197,7 @@ class Machine:
|
|||||||
config_json.flush()
|
config_json.flush()
|
||||||
|
|
||||||
file_info = json.loads(
|
file_info = json.loads(
|
||||||
run(
|
run_no_stdout(
|
||||||
nix_eval(
|
nix_eval(
|
||||||
[
|
[
|
||||||
"--impure",
|
"--impure",
|
||||||
@ -247,10 +247,10 @@ class Machine:
|
|||||||
]
|
]
|
||||||
|
|
||||||
if method == "eval":
|
if method == "eval":
|
||||||
output = run(nix_eval(args)).stdout.strip()
|
output = run_no_stdout(nix_eval(args)).stdout.strip()
|
||||||
return output
|
return output
|
||||||
elif method == "build":
|
elif method == "build":
|
||||||
outpath = run(nix_build(args)).stdout.strip()
|
outpath = run_no_stdout(nix_build(args)).stdout.strip()
|
||||||
return Path(outpath)
|
return Path(outpath)
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Unknown method {method}")
|
raise ValueError(f"Unknown method {method}")
|
||||||
|
Loading…
Reference in New Issue
Block a user