mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 09:13:37 +02:00
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:
parent
fd35fa0871
commit
21e67291b5
6 changed files with 12 additions and 14 deletions
|
|
@ -4,7 +4,7 @@ import os, re, sys, subprocess, datetime, time
|
||||||
from argparse import Namespace, ArgumentParser
|
from argparse import Namespace, ArgumentParser
|
||||||
from functools import lru_cache
|
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 ...lib.log import *
|
||||||
from ..Cmd import Cmd
|
from ..Cmd import Cmd
|
||||||
from ..CmdProjects import CmdProjects
|
from ..CmdProjects import CmdProjects
|
||||||
|
|
@ -115,7 +115,7 @@ class CmdBuild(Cmd): # export
|
||||||
env = await get_profile_env(keep=keep)
|
env = await get_profile_env(keep=keep)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stdout, stderr, status = await run_cmd(
|
await self.app.exec_context.run(
|
||||||
make_cmd,
|
make_cmd,
|
||||||
wd=wd,
|
wd=wd,
|
||||||
throw=True,
|
throw=True,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ from argparse import Namespace, ArgumentParser
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from ...lib.log import *
|
from ...lib.log import *
|
||||||
from ...lib.util import run_cmd
|
|
||||||
from ..Cmd import Cmd
|
from ..Cmd import Cmd
|
||||||
from ..CmdProjects import CmdProjects
|
from ..CmdProjects import CmdProjects
|
||||||
|
|
||||||
|
|
@ -35,7 +34,7 @@ class CmdGetAuthInfo(Cmd): # export
|
||||||
if not os.path.isdir(jw_pkg_dir + '/.git'):
|
if not os.path.isdir(jw_pkg_dir + '/.git'):
|
||||||
log(DEBUG, f'jw-pkg directory is not a Git repo: {jw_pkg_dir}')
|
log(DEBUG, f'jw-pkg directory is not a Git repo: {jw_pkg_dir}')
|
||||||
return
|
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] = {}
|
result: dict[str, str] = {}
|
||||||
for line in remotes.splitlines():
|
for line in remotes.splitlines():
|
||||||
name, url, typ = re.split(r'\s+', line)
|
name, url, typ = re.split(r'\s+', line)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
import os, sys, subprocess, asyncio
|
import os, sys, subprocess, asyncio
|
||||||
|
|
||||||
from ..util import run_cmd
|
|
||||||
from ..ExecContext import ExecContext as Base
|
from ..ExecContext import ExecContext as Base
|
||||||
from ..ExecContext import Result
|
from ..ExecContext import Result
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,14 +30,14 @@ async def run_dpkg(args: list[str], sudo: bool=False, ec: ExecContext=None): # e
|
||||||
cmd.extend(args)
|
cmd.extend(args)
|
||||||
if sudo:
|
if sudo:
|
||||||
return await run_sudo(cmd, ec=ec)
|
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
|
async def run_dpkg_query(args: list[str], sudo: bool=False, ec: ExecContext=None): # export
|
||||||
cmd = ['/usr/bin/dpkg-query']
|
cmd = ['/usr/bin/dpkg-query']
|
||||||
cmd.extend(args)
|
cmd.extend(args)
|
||||||
if sudo:
|
if sudo:
|
||||||
return await run_sudo(cmd)
|
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
|
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'
|
fmt_str = '|'.join([(f'${{{tag}}}' if tag else '') for tag in meta_map().values()]) + r'\n'
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,8 @@ async def query_packages(names: Iterable[str] = [], ec: ExecContext=None) -> Ite
|
||||||
if not names:
|
if not names:
|
||||||
opts.append('-a')
|
opts.append('-a')
|
||||||
specs, stderr, status = await run_rpm([*opts, *names], throw=True, sudo=False, ec=ec)
|
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
|
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)
|
stdout, stderr, status = await run_rpm(['-ql', pkg], throw=True, sudo=False, ec=ec)
|
||||||
return file_list_str.splitlines()
|
return stdout.decode().splitlines()
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ def pretty_cmd(cmd: list[str], wd=None):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
# See ExecContext.run() for what this function does
|
# 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:
|
if verbose is None:
|
||||||
verbose = False if ec is None else ec.verbose_default
|
verbose = False if ec is None else ec.verbose_default
|
||||||
if ec is None:
|
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:
|
if not verbose:
|
||||||
cmd.append('-s')
|
cmd.append('-s')
|
||||||
cmd.extend(args)
|
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:
|
if parse_json:
|
||||||
try:
|
try:
|
||||||
ret = json.loads(ret)
|
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
|
continue # Can't get user name from SSH_ASKPASS
|
||||||
case AskpassKey.Password:
|
case AskpassKey.Password:
|
||||||
exe_arg += '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:
|
if ret is not None:
|
||||||
return ret
|
return ret
|
||||||
return None
|
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']
|
cmd = ['/usr/bin/env', '-i', '/bin/bash', '-lc', 'env -0']
|
||||||
result = await run_cmd(cmd, throw=throw, verbose=True, env=env, ec=ec)
|
result = await run_cmd(cmd, throw=throw, verbose=True, env=env, ec=ec)
|
||||||
ret: dict[str, str] = {}
|
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:
|
if not entry:
|
||||||
continue
|
continue
|
||||||
key, val = entry.split(b"=", 1)
|
key, val = entry.split(b"=", 1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue