[PR jw/#183] cmds.secrets.lib.DistroContext: One SSH session per compile
All checks were successful
CI / Packaging - Kali Linux (push) Successful in 4m54s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 5m47s
CI / Packaging test (push) Successful in 0s

Merge pull request "cmds.secrets.lib.DistroContext: One SSH session per compile"

Upstream-repo: ssh://git@code.janware.com/janware/jw-pkg
Source-branch: jan/feature/20261120-cmds-secrets-lib-distrocontext-one-ssh-session-per-compile
Target-branch: master
Reviewed-on: #183
This commit is contained in:
Jan Lindemann 2026-11-20 23:12:06 +01:00 • committed by janware Code
commit 2aaed09356
Signed by: Code Bot
GPG key ID: 66A5D2B295EE1224

View file

@ -33,11 +33,12 @@ class DistroContext(FilesContext):
self.__distro = distro
async def match_files(self, pkg_names: Collection[str], pattern: str) -> list[str]:
# -- One query for the whole name list: the distro backends
# accept a list and issue a single file-listing command
ret: list[str] = []
for pkg_name in pkg_names:
for path in await self.__distro.pkg_paths(pkg_name):
if re.match(pattern, path):
ret.append(path)
for path in await self.__distro.pkg_paths(list(pkg_names)):
if re.match(pattern, path):
ret.append(path)
return ret
async def list_template_files(self, pkg_names: Collection[str]) -> list[str]:
@ -89,20 +90,25 @@ class DistroContext(FilesContext):
ret: list[str] = []
failed: list[str] = []
missing = 0
targets = await self.list_compilation_targets(pkg_names)
for target in targets:
try:
ok = await self.compile_template_file(target, default_attrs)
except Exception as e:
if not keep_going:
raise
log(ERR, f'{target}: {e}')
failed.append(target)
continue
if ok:
ret.append(target)
else:
missing += 1
# -- Keep the exec context and the store open across the whole
# compile, so the run() calls in the per-target operations
# bump the reference counter instead of opening and closing
# the connection for every remote command.
async with self.ctx, self.store:
targets = await self.list_compilation_targets(pkg_names)
for target in targets:
try:
ok = await self.compile_template_file(target, default_attrs)
except Exception as e:
if not keep_going:
raise
log(ERR, f'{target}: {e}')
failed.append(target)
continue
if ok:
ret.append(target)
else:
missing += 1
if missing > 0:
from ....lib.util import pretty_cmd