jw.pkg.*.run_xxx(): Return exit status

Most run_xxx() return stdout and stderr. There's no way, really, for
the caller to get hold of the exit code of the spawned executable. It
can pass throw=true, catch, and assume a non-zero exit status. But
that's not semantically clean, since the spawned function can well be
a test function which is expected to return a non-zero status code,
and the caller might be interested in what code that was, exactly.

The clearest way to solve this is to return the exit code as well.
This commit does that.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-03-03 08:34:27 +01:00
commit 565946643b
6 changed files with 25 additions and 25 deletions

View file

@ -24,7 +24,7 @@ async def all_installed_packages() -> Iterable[Package]: # export
opts.append('--queryformat')
tag_str = '|'.join([f'%{{{tag}}}' for tag in query_tags]) + r'\n'
opts.append(tag_str)
package_list_str, stderr = await run_rpm(['-qa', *opts], sudo=False)
package_list_str, stderr, status = await run_rpm(['-qa', *opts], sudo=False)
for package_str in package_list_str.splitlines():
tags = package_str.split('|')
ret.append(Package(name=tags[0], vendor=tags[1], packager=tags[2], url=tags[3]))
@ -32,5 +32,5 @@ async def all_installed_packages() -> Iterable[Package]: # export
async def list_files(pkg: str) -> list[str]: # export
opts: list[str] = []
file_list_str, stderr = await run_rpm(['-ql', pkg, *opts], sudo=False)
file_list_str, stderr, status = await run_rpm(['-ql', pkg, *opts], sudo=False)
return file_list_str.splitlines()

View file

@ -115,7 +115,7 @@ class CmdBuild(Cmd): # export
env = await get_profile_env(keep=keep)
try:
stdout, stderr = await run_cmd(
stdout, stderr, status = await run_cmd(
make_cmd,
wd=wd,
throw=True,

View file

@ -35,7 +35,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 = await run_cmd(['git', '-C', jw_pkg_dir, 'remote', '-v'])
remotes, stderr, status = await run_cmd(['git', '-C', jw_pkg_dir, 'remote', '-v'])
result: dict[str, str] = {}
for line in remotes.splitlines():
name, url, typ = re.split(r'\s+', line)

View file

@ -55,7 +55,7 @@ class CmdListRepos(Cmd): # export
cmd_input = (f'-u {username}:{password}').encode('utf-8')
curl_args.extend(['-K-'])
curl_args.append(f'https://api.github.com/users/{args.from_owner}/repos')
repos = await run_curl(curl_args, cmd_input=cmd_input)
repos, stderr, status = await run_curl(curl_args, cmd_input=cmd_input)
for repo in repos:
print(repo['name'])
return
@ -71,7 +71,7 @@ class CmdListRepos(Cmd): # export
api_url = f'{args.base_url}/api/v1/{entities_dir}/{args.from_owner}/repos'
try:
tried.append(api_url)
repos = await run_curl(curl_args + [api_url], cmd_input=cmd_input)
repos, stderr, status = await run_curl(curl_args + [api_url], cmd_input=cmd_input)
for repo in repos:
print(repo['name'])
break