[displaymanager] Document the internal functions for DE finding
- rename find_* to _search_* to make clear they're internal.
This commit is contained in:
parent
a3666cabe0
commit
fe33952733
@ -51,31 +51,59 @@ class DesktopEnvironment:
|
|||||||
self.executable = exec
|
self.executable = exec
|
||||||
self.desktop_file = desktop
|
self.desktop_file = desktop
|
||||||
|
|
||||||
def find_executable(self, root_mount_point, command):
|
def _search_executable(self, root_mount_point, pathname):
|
||||||
if command.startswith("/"):
|
"""
|
||||||
|
Search for @p pathname within @p root_mount_point .
|
||||||
|
If the pathname is absolute, just check there inside
|
||||||
|
the target, otherwise earch in a sort-of-sensible $PATH.
|
||||||
|
|
||||||
|
Returns the full (including @p root_mount_point) path
|
||||||
|
to that executable, or None.
|
||||||
|
"""
|
||||||
|
if pathname.startswith("/"):
|
||||||
path = [""]
|
path = [""]
|
||||||
else:
|
else:
|
||||||
path = ["/bin/", "/usr/bin/", "/sbin/", "/usr/local/bin/"]
|
path = ["/bin/", "/usr/bin/", "/sbin/", "/usr/local/bin/"]
|
||||||
|
|
||||||
for p in path:
|
for p in path:
|
||||||
absolute_path = "{!s}{!s}{!s}".format(root_mount_point, p, command)
|
absolute_path = "{!s}{!s}{!s}".format(root_mount_point, p, pathname)
|
||||||
if os.path.exists(absolute_path):
|
if os.path.exists(absolute_path):
|
||||||
return absolute_path
|
return absolute_path
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def find_tryexec(self, root_mount_point, absolute_desktop_file):
|
def _search_tryexec(self, root_mount_point, absolute_desktop_file):
|
||||||
|
"""
|
||||||
|
Check @p absolute_desktop_file for a TryExec line and, if that is
|
||||||
|
found, search for the command (executable pathname) within
|
||||||
|
@p root_mount_point. The .desktop file must live within the
|
||||||
|
target root.
|
||||||
|
|
||||||
|
Returns the full (including @p root_mount_point) for the executable
|
||||||
|
from TryExec, or None.
|
||||||
|
"""
|
||||||
assert absolute_desktop_file.startswith(root_mount_point)
|
assert absolute_desktop_file.startswith(root_mount_point)
|
||||||
with open(absolute_desktop_file, "r") as f:
|
with open(absolute_desktop_file, "r") as f:
|
||||||
for tryexec_line in [x for x in f.readlines() if x.startswith("TryExec")]:
|
for tryexec_line in [x for x in f.readlines() if x.startswith("TryExec")]:
|
||||||
try:
|
try:
|
||||||
key, value = tryexec_line.split("=")
|
key, value = tryexec_line.split("=")
|
||||||
if key.strip() == "TryExec":
|
if key.strip() == "TryExec":
|
||||||
return self.find_executable(root_mount_point, value.strip())
|
return self._search_executable(root_mount_point, value.strip())
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def find_executable(self, root_mount_point):
|
||||||
|
"""
|
||||||
|
Returns the full path of the configured executable within @p root_mount_point,
|
||||||
|
or None if it isn't found. May search in a semi-sensible $PATH.
|
||||||
|
"""
|
||||||
|
return self._search_executable(root_mount_point, self.executable)
|
||||||
|
|
||||||
def find_desktop_file(self, root_mount_point):
|
def find_desktop_file(self, root_mount_point):
|
||||||
|
"""
|
||||||
|
Returns the full path of the .desktop file within @p root_mount_point,
|
||||||
|
or None if it isn't found. Searches both X11 and Wayland sessions.
|
||||||
|
"""
|
||||||
x11_sessions = "{!s}/usr/share/xsessions/{!s}.desktop".format(root_mount_point, self.desktop_file)
|
x11_sessions = "{!s}/usr/share/xsessions/{!s}.desktop".format(root_mount_point, self.desktop_file)
|
||||||
wayland_sessions = "{!s}/usr/share/wayland-sessions/{!s}.desktop".format(root_mount_point, self.desktop_file)
|
wayland_sessions = "{!s}/usr/share/wayland-sessions/{!s}.desktop".format(root_mount_point, self.desktop_file)
|
||||||
for candidate in (x11_sessions, wayland_sessions):
|
for candidate in (x11_sessions, wayland_sessions):
|
||||||
@ -92,8 +120,9 @@ class DesktopEnvironment:
|
|||||||
if desktop_file is None:
|
if desktop_file is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return (self.find_executable(root_mount_point, self.executable) is not None or
|
return (self.find_executable(root_mount_point) is not None or
|
||||||
self.find_tryexec(root_mount_point, desktop_file) is not None)
|
self._search_tryexec(root_mount_point, desktop_file) is not None)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# This is the list of desktop environments that Calamares looks
|
# This is the list of desktop environments that Calamares looks
|
||||||
|
Loading…
Reference in New Issue
Block a user