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:
parent
d1df9f0ac7
commit
ef21dc1b1e
2 changed files with 19 additions and 18 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue