App.distro_info(): Add method

Add a method distro_info() to App, essentially providing CmdInfo's macro-expansion of platform information to other interested code.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-04-16 13:25:32 +02:00
commit ef21dc1b1e
2 changed files with 19 additions and 18 deletions

View file

@ -418,6 +418,23 @@ class App(Base):
self.__distro = ret
return self.__distro
def distro_info(self, fmt: str) -> str:
ret = fmt
for macro in re.findall("%{([A-Za-z_-]+)}", fmt):
try:
name = 'distro_' + macro.replace('-', '_')
if name == 'distro_info':
continue
val = getattr(self, name)
patt = r'%{' + macro + r'}'
if ret.find(patt) == -1:
continue
ret = ret.replace(patt, val)
except Exception as e:
log(ERR, f'Failed to expand macro "{macro}" inside "{fmt}": {str(e)}')
raise
return ret
def find_dir(self, name: str, search_subdirs: list[str]=[], search_absdirs: list[str]=[], pretty: bool=True):
return self.__find_dir(name, search_subdirs, search_absdirs, pretty)