diff --git a/comicapi/utils.py b/comicapi/utils.py index f50053c..5c5fe96 100644 --- a/comicapi/utils.py +++ b/comicapi/utils.py @@ -226,7 +226,7 @@ def get_recursive_filelist(pathlist: list[str]) -> list[str]: def add_to_path(dirname: str) -> None: - if dirname: + if dirname and os.path.isdir(dirname): dirname = os.path.abspath(dirname) paths = [os.path.normpath(x) for x in split(os.environ["PATH"], os.pathsep)] diff --git a/comictaggerlib/ctsettings/commandline.py b/comictaggerlib/ctsettings/commandline.py index f958544..2800f91 100644 --- a/comictaggerlib/ctsettings/commandline.py +++ b/comictaggerlib/ctsettings/commandline.py @@ -19,6 +19,8 @@ import argparse import logging import os import platform +import shlex +import subprocess import settngs @@ -308,12 +310,18 @@ def validate_commandline_settings(config: settngs.Config[ct_ns], parser: settngs if not utils.which("rar"): if platform.system() == "Windows": # look in some likely places for Windows machines - if os.path.exists(r"C:\Program Files\WinRAR\Rar.exe"): - utils.add_to_path(r"C:\Program Files\WinRAR") - elif os.path.exists(r"C:\Program Files (x86)\WinRAR\Rar.exe"): - utils.add_to_path(r"C:\Program Files (x86)\WinRAR") + utils.add_to_path(r"C:\Program Files\WinRAR") + utils.add_to_path(r"C:\Program Files (x86)\WinRAR") else: - if os.path.exists("/opt/homebrew/bin"): - utils.add_to_path("/opt/homebrew/bin") + if platform.system() == "Darwin": + result = subprocess.run(("/usr/libexec/path_helper", "-s"), capture_output=True) + for path in reversed( + shlex.split(result.stdout.decode("utf-8", errors="ignore"))[0] + .partition("=")[2] + .rstrip(";") + .split(os.pathsep) + ): + utils.add_to_path(path) + utils.add_to_path("/opt/homebrew/bin") return config diff --git a/comictaggerlib/settingswindow.py b/comictaggerlib/settingswindow.py index 6bb5219..a5d5df7 100644 --- a/comictaggerlib/settingswindow.py +++ b/comictaggerlib/settingswindow.py @@ -60,7 +60,7 @@ macRarHelp = """ you will need the rar tool. The easiest way to get this is to install homebrew. -
Once homebrew is installed, run: brew install caskroom/cask/rar