refactor: use pathlib / separator rather than .joinpath

Mainly to help readability
This commit is contained in:
Alexis Métaireau 2024-05-22 15:27:52 +02:00
parent eba30f3c17
commit 55850bfe2f
No known key found for this signature in database
GPG key ID: C65C7A89A8FFC56E

View file

@ -27,21 +27,21 @@ def get_resource_path(filename: str) -> str:
if getattr(sys, "dangerzone_dev", False): if getattr(sys, "dangerzone_dev", False):
# Look for resources directory relative to python file # Look for resources directory relative to python file
project_root = pathlib.Path(__file__).parent.parent project_root = pathlib.Path(__file__).parent.parent
prefix = project_root.joinpath("share") prefix = project_root / "share"
else: else:
if platform.system() == "Darwin": if platform.system() == "Darwin":
bin_path = pathlib.Path(sys.executable) bin_path = pathlib.Path(sys.executable)
app_path = bin_path.parent.parent app_path = bin_path.parent.parent
prefix = app_path.joinpath("Resources", "share") prefix = app_path / "Resources" / "share"
elif platform.system() == "Linux": elif platform.system() == "Linux":
prefix = pathlib.Path(sys.prefix).joinpath("share", "dangerzone") prefix = pathlib.Path(sys.prefix) / "share" / "dangerzone"
elif platform.system() == "Windows": elif platform.system() == "Windows":
exe_path = pathlib.Path(sys.executable) exe_path = pathlib.Path(sys.executable)
dz_install_path = exe_path.parent dz_install_path = exe_path.parent
prefix = dz_install_path.joinpath("share") prefix = dz_install_path / "share"
else: else:
raise NotImplementedError(f"Unsupported system {platform.system()}") raise NotImplementedError(f"Unsupported system {platform.system()}")
resource_path = prefix.joinpath(filename) resource_path = prefix / filename
return str(resource_path) return str(resource_path)