App.distro_xxx: Move properties to Distro.xxx

Commit a19679fec reverted the first attempt to make AsyncSSH reuse one connection during an instance lifetime. That failed because a lot of distribution-specific properties were filled in a new event loop thread started by AsyncRunner, and AsyncSSH didn't like that.

This commit is the first part of the solution: Move those properties from the App class to the Distro class, and load the Distro class in an async loader. As soon as it's instantiated, it can provide all its properties without cluttering the code with async keywords.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-18 12:08:00 +02:00
commit aa7275f426
7 changed files with 241 additions and 231 deletions

View file

@ -3,20 +3,19 @@
from argparse import Namespace, ArgumentParser
from ...lib.log import *
from ...lib.Distro import Distro
from ..Cmd import Cmd
from ..CmdProjects import CmdProjects
class CmdInfo(Cmd): # export
def __init__(self, parent: CmdProjects) -> None:
super().__init__(parent, 'info', help='Print information about target platform')
super().__init__(parent, 'info', help='Retrieve information about target platform')
def add_arguments(self, parser: ArgumentParser) -> None:
super().add_arguments(parser)
macro_names = ', '.join(['%%{' + name.replace('distro_', '').replace('_', '-') + '}'
for name in dir(self.app) if name.startswith('distro_')])
parser.add_argument('--format', default='%{cascade}',
help=f'Format string, expanding macros {macro_names}')
help=f'Format string, expanding macros {", ".join(Distro.macros())}')
async def _run(self, args: Namespace) -> None:
print(self.app.distro_info(args.format))
print(self.app.distro.expand_macros(args.format))

View file

@ -15,8 +15,8 @@ class CmdInstall(Cmd): # export
parser.add_argument("names", nargs="*", help="Packages to be installed")
parser.add_argument('--only-update', default=False, action='store_true', help='Only update the listed packages, don\'t install them')
parser.add_argument('-F', '--fixed-strings', action='store_true',
help='Don\'t expand platform info macros in <names>')
help='Don\'t expand platform.expand_macros macros in <names>')
async def _run(self, args: Namespace) -> None:
names = names if args.fixed_strings else self.app.distro_info(args.names)
names = names if args.fixed_strings else self.app.distro.expand_macros(args.names)
return await self.distro.install(names, only_update=args.only_update)

View file

@ -23,12 +23,12 @@ class CmdCopy(Cmd): # export
parser.add_argument('-g', '--group', default=None, help='Destination file group')
parser.add_argument('-m', '--mode', default=None, help='Destination file mode')
parser.add_argument('-F', '--fixed-strings', action='store_true',
help='Don\'t expand platform info macros in <src> and <dst>')
help='Don\'t expand platform.expand_macros macros in <src> and <dst>')
async def _run(self, args: Namespace) -> None:
def __expand(url: str) -> str:
if args.fixed_strings:
return url
return self.app.distro_info(url)
return self.app.distro.expand_macros(url)
await copy(__expand(args.src), __expand(args.dst),
owner=args.owner, group=args.group, mode=int(args.mode, 0))

View file

@ -37,7 +37,7 @@ class BaseCmdPkgRelations(Cmd):
) -> list[str]:
if subsections is None:
subsections = self.app.os_cascade()
subsections = self.app.distro.os_cascade
subsections.append('jw')
expand_semver_revision_range = expand_semver_revision_range

View file

@ -38,7 +38,7 @@ class CmdRequiredOsPkg(Cmd): # export
for d in deps:
if self.app.is_excluded_from_build(d) is not None:
deps.remove(d)
subsecs = self.app.os_cascade()
subsecs = self.app.distro.os_cascade
log(DEBUG, "subsecs = ", subsecs)
requires: set[str] = set()
for sec in subsecs: