diff --git a/modules/archive/lib.py b/modules/archive/lib.py index 088d622d..11f08eff 100644 --- a/modules/archive/lib.py +++ b/modules/archive/lib.py @@ -150,7 +150,7 @@ SINGLE_FILE_PATH = which('single-file', '/usr/bin/single-file', # rpi ubuntu '/usr/local/bin/single-file', # debian warn=True) -CHROMIUM = which('chromium-browser', +CHROMIUM = which('chromium-browser', 'chromium', '/usr/bin/chromium-browser', # rpi ubuntu '/usr/bin/chromium', # debian warn=True diff --git a/wrolpi/cmd.py b/wrolpi/cmd.py index 18fb42d3..bbc002cf 100644 --- a/wrolpi/cmd.py +++ b/wrolpi/cmd.py @@ -13,21 +13,22 @@ def is_executable(path: Path) -> bool: return path.is_file() and os.access(path, os.X_OK) -def which(name: str, *possible_paths: str, warn: bool = False) -> Path: +def which(*possible_paths: str, warn: bool = False) -> Path: """ Find an executable in the system $PATH. If the executable cannot be found in $PATH, then return the first executable found in possible_paths. Returns None if no executable can be found. """ - path = shutil.which(name) - if path: - return Path(path).absolute() - possible_paths = map(Path, possible_paths) for path in possible_paths: if is_executable(path): + # `path` was an absolute file which is executable. return path.absolute() + path = shutil.which(path) + if path and (path := Path(path).absolute()) and is_executable(path): + # `path` was a name or relative path. + return path if warn and not PYTEST and not DOCKERIZED: - logger.warning(f'Cannot find executable {name}') + logger.warning(f'Cannot find executable {possible_paths[0]}') diff --git a/wrolpi/test/test_cmd.py b/wrolpi/test/test_cmd.py index 43613ab0..5a47dd0c 100644 --- a/wrolpi/test/test_cmd.py +++ b/wrolpi/test/test_cmd.py @@ -2,6 +2,7 @@ import os from pathlib import Path from wrolpi import cmd +from wrolpi.test.common import skip_circleci def test_which(test_directory): @@ -20,3 +21,9 @@ def test_which(test_directory): assert cmd.which('asdf', str(foo)) is None os.chmod(foo, 0o777) assert cmd.which('asdf', str(foo)) == foo + + +@skip_circleci +def test_which_chromium(): + # Multiple names can be tried. + assert cmd.which('chromium-browser', 'chromium') == Path('/usr/bin/chromium')