mirror of
https://gitlab.com/kupfer/kupferbootstrap.git
synced 2025-06-25 09:58:21 -04:00
utils.programs_available(): add cache
This commit is contained in:
parent
8a7f78261f
commit
27e7fe9a10
1 changed files with 8 additions and 2 deletions
10
utils.py
10
utils.py
|
@ -8,12 +8,18 @@ from typing import Optional, Union, Sequence
|
||||||
|
|
||||||
from exec.cmd import run_cmd, run_root_cmd
|
from exec.cmd import run_cmd, run_root_cmd
|
||||||
|
|
||||||
|
_programs_available = dict[str, bool]()
|
||||||
|
|
||||||
def programs_available(programs: Union[str, Sequence[str]]) -> bool:
|
|
||||||
|
def programs_available(programs: Union[str, Sequence[str]], lazy: bool = True) -> bool:
|
||||||
|
global _programs_available
|
||||||
if type(programs) is str:
|
if type(programs) is str:
|
||||||
programs = [programs]
|
programs = [programs]
|
||||||
for program in programs:
|
for program in programs:
|
||||||
if not which(program):
|
if program not in _programs_available or not lazy:
|
||||||
|
avail = bool(which(program))
|
||||||
|
_programs_available[program] = avail
|
||||||
|
if not _programs_available[program]:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue