|
|
@ -33,20 +33,23 @@ logged = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _try_standard_locations():
|
|
|
|
def _try_standard_locations():
|
|
|
|
"""Look for the data dir where it typically can be found."""
|
|
|
|
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
|
|
|
candidates = [
|
|
|
|
# ensure at least /usr/local/share/ and /usr/share/ are tried
|
|
|
|
"/usr/share/input-remapper",
|
|
|
|
xdg_data_dirs = set(
|
|
|
|
"/usr/local/share/input-remapper",
|
|
|
|
os.environ.get("XDG_DATA_DIRS", "").split(":")
|
|
|
|
os.path.join(site.USER_BASE, "share/input-remapper"),
|
|
|
|
+ [
|
|
|
|
]
|
|
|
|
"/usr/local/share/",
|
|
|
|
|
|
|
|
"/usr/share/",
|
|
|
|
# try any of the options
|
|
|
|
os.path.join(site.USER_BASE, "share/"),
|
|
|
|
for candidate in candidates:
|
|
|
|
]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for xdg_data_dir in xdg_data_dirs:
|
|
|
|
|
|
|
|
candidate = os.path.join(xdg_data_dir, "input-remapper")
|
|
|
|
if os.path.exists(candidate):
|
|
|
|
if os.path.exists(candidate):
|
|
|
|
data = candidate
|
|
|
|
return candidate
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return data
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _try_python_package_location():
|
|
|
|
def _try_python_package_location():
|
|
|
@ -55,8 +58,8 @@ def _try_python_package_location():
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
source = pkg_resources.require("input-remapper")[0].location
|
|
|
|
source = pkg_resources.require("input-remapper")[0].location
|
|
|
|
# failed in some ubuntu installations
|
|
|
|
# failed in some ubuntu installations
|
|
|
|
except pkg_resources.DistributionNotFound:
|
|
|
|
except Exception:
|
|
|
|
logger.debug("DistributionNotFound")
|
|
|
|
logger.debug("failed to figure out package location")
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
data = None
|
|
|
|
data = None
|
|
|
@ -73,6 +76,21 @@ def _try_python_package_location():
|
|
|
|
return data
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _try_env_data_dir():
|
|
|
|
|
|
|
|
"""Check if input-remappers data can be found at DATA_DIR."""
|
|
|
|
|
|
|
|
data_dir = os.environ.get("DATA_DIR", None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if data_dir is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.exists(data_dir):
|
|
|
|
|
|
|
|
return data_dir
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
logger.error(f'"{ data_dir }" does not exist')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_data_path(filename=""):
|
|
|
|
def get_data_path(filename=""):
|
|
|
|
"""Depending on the installation prefix, return the data dir.
|
|
|
|
"""Depending on the installation prefix, return the data dir.
|
|
|
|
|
|
|
|
|
|
|
@ -86,7 +104,11 @@ def get_data_path(filename=""):
|
|
|
|
# prefix path for data
|
|
|
|
# prefix path for data
|
|
|
|
# https://docs.python.org/3/distutils/setupscript.html?highlight=package_data#installing-additional-files # noqa pylint: disable=line-too-long
|
|
|
|
# https://docs.python.org/3/distutils/setupscript.html?highlight=package_data#installing-additional-files # noqa pylint: disable=line-too-long
|
|
|
|
|
|
|
|
|
|
|
|
data = _try_python_package_location() or _try_standard_locations()
|
|
|
|
data = (
|
|
|
|
|
|
|
|
_try_env_data_dir()
|
|
|
|
|
|
|
|
or _try_python_package_location()
|
|
|
|
|
|
|
|
or _try_standard_locations()
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if data is None:
|
|
|
|
if data is None:
|
|
|
|
logger.error("Could not find the application data")
|
|
|
|
logger.error("Could not find the application data")
|
|
|
|