cmds.secrets.lib.DistroContext: One SSH session per compile #183
1 changed files with 24 additions and 18 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue