Fix: Decode run_cmd() result

Since commit 02697af5, ExecContext.run() returns bytes for stdout and
stderr and fixes that in calling code. The thing it did not fix was
the code calling run_cmd(), which also made return bytes. This commit
catches up on that.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-03-23 13:13:55 +01:00
commit 21e67291b5
6 changed files with 12 additions and 14 deletions

View file

@ -4,7 +4,7 @@ import os, re, sys, subprocess, datetime, time
from argparse import Namespace, ArgumentParser
from functools import lru_cache
from ...lib.util import run_cmd, get_profile_env
from ...lib.util import get_profile_env
from ...lib.log import *
from ..Cmd import Cmd
from ..CmdProjects import CmdProjects
@ -115,7 +115,7 @@ class CmdBuild(Cmd): # export
env = await get_profile_env(keep=keep)
try:
stdout, stderr, status = await run_cmd(
await self.app.exec_context.run(
make_cmd,
wd=wd,
throw=True,

View file

@ -5,7 +5,6 @@ from argparse import Namespace, ArgumentParser
from urllib.parse import urlparse
from ...lib.log import *
from ...lib.util import run_cmd
from ..Cmd import Cmd
from ..CmdProjects import CmdProjects
@ -35,7 +34,7 @@ class CmdGetAuthInfo(Cmd): # export
if not os.path.isdir(jw_pkg_dir + '/.git'):
log(DEBUG, f'jw-pkg directory is not a Git repo: {jw_pkg_dir}')
return
remotes, stderr, status = await run_cmd(['git', '-C', jw_pkg_dir, 'remote', '-v'])
remotes, stderr, status = (await self.app.exec_context.run(['git', '-C', jw_pkg_dir, 'remote', '-v'])).decode()
result: dict[str, str] = {}
for line in remotes.splitlines():
name, url, typ = re.split(r'\s+', line)

View file

@ -2,7 +2,6 @@
import os, sys, subprocess, asyncio
from ..util import run_cmd
from ..ExecContext import ExecContext as Base
from ..ExecContext import Result

View file

@ -30,14 +30,14 @@ async def run_dpkg(args: list[str], sudo: bool=False, ec: ExecContext=None): # e
cmd.extend(args)
if sudo:
return await run_sudo(cmd, ec=ec)
return await run_cmd(cmd, ec=ec)
return (await run_cmd(cmd, ec=ec)).decode()
async def run_dpkg_query(args: list[str], sudo: bool=False, ec: ExecContext=None): # export
cmd = ['/usr/bin/dpkg-query']
cmd.extend(args)
if sudo:
return await run_sudo(cmd)
return await run_cmd(cmd, ec=ec)
return (await run_cmd(cmd, ec=ec)).decode()
async def query_packages(names: Iterable[str] = [], ec: ExecContext=None) -> Iterable[Package]: # export
fmt_str = '|'.join([(f'${{{tag}}}' if tag else '') for tag in meta_map().values()]) + r'\n'

View file

@ -38,8 +38,8 @@ async def query_packages(names: Iterable[str] = [], ec: ExecContext=None) -> Ite
if not names:
opts.append('-a')
specs, stderr, status = await run_rpm([*opts, *names], throw=True, sudo=False, ec=ec)
return Package.parse_specs_str(specs)
return Package.parse_specs_str(specs.decode())
async def list_files(pkg: str, ec: ExecContext=None) -> list[str]: # export
file_list_str, stderr, status = await run_rpm(['-ql', pkg], throw=True, sudo=False, ec=ec)
return file_list_str.splitlines()
stdout, stderr, status = await run_rpm(['-ql', pkg], throw=True, sudo=False, ec=ec)
return stdout.decode().splitlines()

View file

@ -32,7 +32,7 @@ def pretty_cmd(cmd: list[str], wd=None):
return ret
# See ExecContext.run() for what this function does
async def run_cmd(*args, ec: ExecContext|None=None, verbose: bool|None=None, **kwargs) -> tuple[str|bytes|None, str|bytes|None]:
async def run_cmd(*args, ec: ExecContext|None=None, verbose: bool|None=None, **kwargs) -> Result:
if verbose is None:
verbose = False if ec is None else ec.verbose_default
if ec is None:
@ -47,7 +47,7 @@ async def run_curl(args: list[str], parse_json: bool=True, wd=None, throw=None,
if not verbose:
cmd.append('-s')
cmd.extend(args)
ret, stderr, status = await run_cmd(cmd, wd=wd, throw=throw, verbose=verbose, cmd_input=cmd_input, ec=ec)
ret, stderr, status = await run_cmd(cmd, wd=wd, throw=throw, verbose=verbose, cmd_input=cmd_input, ec=ec).decode()
if parse_json:
try:
ret = json.loads(ret)
@ -82,7 +82,7 @@ async def run_askpass(askpass_env: list[str], key: AskpassKey, host: str|None=No
continue # Can't get user name from SSH_ASKPASS
case AskpassKey.Password:
exe_arg += 'Password'
ret, stderr, status = await run_cmd([exe, exe_arg], throw=False, ec=ec)
ret, stderr, status = await run_cmd([exe, exe_arg], throw=False, ec=ec).decode()
if ret is not None:
return ret
return None
@ -141,7 +141,7 @@ async def get_profile_env(throw: bool=True, keep: Iterable[str]|bool=False, ec:
cmd = ['/usr/bin/env', '-i', '/bin/bash', '-lc', 'env -0']
result = await run_cmd(cmd, throw=throw, verbose=True, env=env, ec=ec)
ret: dict[str, str] = {}
for entry in result.stdout.split(b"\0"):
for entry in result.stdout.rstrip(b"\0").split(b"\0"):
if not entry:
continue
key, val = entry.split(b"=", 1)