mirror of
https://github.com/freedomofpress/dangerzone.git
synced 2025-04-29 10:12:38 +02:00
simplify get_resource_path logic
Simplifying the logic for obtaining resource paths by using pathlib
instead inspect.
Co-authored-by: Guthrie McAfee Armstrong <git@gmarmstrong.dev>
Based on commit bbce13d
This commit is contained in:
parent
4d9f729654
commit
c2a140807f
1 changed files with 15 additions and 19 deletions
|
@ -1,7 +1,6 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
|
||||||
import inspect
|
|
||||||
import appdirs
|
import appdirs
|
||||||
|
import pathlib
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -389,27 +388,24 @@ class GlobalCommon(object):
|
||||||
def get_resource_path(self, filename):
|
def get_resource_path(self, filename):
|
||||||
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
|
||||||
prefix = os.path.join(
|
project_root = pathlib.Path(__file__).parent.parent
|
||||||
os.path.dirname(
|
prefix = project_root.joinpath("share")
|
||||||
os.path.dirname(
|
|
||||||
os.path.abspath(inspect.getfile(inspect.currentframe()))
|
|
||||||
)
|
|
||||||
),
|
|
||||||
"share",
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
if platform.system() == "Darwin":
|
if platform.system() == "Darwin":
|
||||||
prefix = os.path.join(
|
bin_path = pathlib.Path(sys.executable) # /path/to/Dangerzone.app/Contents/MacOS/dangerzone[-cli]
|
||||||
os.path.dirname(os.path.dirname(sys.executable)), "Resources/share"
|
app_path = bin_path.parent.parent # /path/to/Dangerzone.app/Contents
|
||||||
)
|
prefix = app_path.joinpath("Resources", "share") # /path/to/Dangerzone.app/Contents/Resources/share
|
||||||
elif platform.system() == "Linux":
|
elif platform.system() == "Linux":
|
||||||
prefix = os.path.join(sys.prefix, "share", "dangerzone")
|
prefix = pathlib.Path(sys.prefix)\
|
||||||
|
.joinpath("share", "dangerzone") # /usr/share/dangerzone
|
||||||
|
elif platform.system() == "Windows":
|
||||||
|
exe_path = pathlib.Path(sys.executable) # c:\Program Files (x86)\Dangerzone\dangerzone.exe
|
||||||
|
dz_install_path = exe_path.parent # c:\Program Files (x86)\Dangerzone\
|
||||||
|
prefix = dz_install_path.joinpath("share") # c:\Program Files (x86)\Dangerzone\share
|
||||||
else:
|
else:
|
||||||
# Windows
|
raise NotImplementedError(f"Unsupported system {platform.system()}")
|
||||||
prefix = os.path.join(os.path.dirname(sys.executable), "share")
|
resource_path = prefix.joinpath(filename)
|
||||||
|
return str(resource_path)
|
||||||
resource_path = os.path.join(prefix, filename)
|
|
||||||
return resource_path
|
|
||||||
|
|
||||||
def get_subprocess_startupinfo(self):
|
def get_subprocess_startupinfo(self):
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
|
|
Loading…
Reference in a new issue