diff --git a/pym/desktop/desktop.py b/pym/desktop/desktop.py index ebf69ad..600a9c0 100644 --- a/pym/desktop/desktop.py +++ b/pym/desktop/desktop.py @@ -261,6 +261,37 @@ class Desktop(MethodsInterface): return False def userLogout(self, urLogin): + if self.clVars.GetBool('cl_desktop_elogind_set'): + return self.userLogoutByElogind(urLogin) + else: + return self.userLogoutBySession(urLogin) + + def getElogindSessionId(self, urLogin): + loginctl = getProgPath("/bin/loginctl") + p = process(loginctl, "--no-legend") + try: + for line in p: + cols = [x.strip() for x in line.split()] + if len(cols) >= 3: + sessionid, uid, username = cols[:3] + if username == urLogin: + return sessionid + finally: + p.close() + return None + + def terminateUserSession(self, session_id): + loginctl = getProgPath("/bin/loginctl") + p = process(loginctl, "terminate-session", session_id) + return p.success() + + def userLogoutByElogind(self, urLogin): + elogin_session_id = self.getElogindSessionId(urLogin) + if not elogin_session_id: + raise DesktopError(_("Unable to detect user session id")) + return self.terminateUserSession(elogin_session_id) + + def userLogoutBySession(self, urLogin): """ Выполнить logout пользователя через dbus """ diff --git a/pym/desktop/variables/desktop.py b/pym/desktop/variables/desktop.py index 86f7a36..0628c14 100644 --- a/pym/desktop/variables/desktop.py +++ b/pym/desktop/variables/desktop.py @@ -32,6 +32,7 @@ from itertools import * import glob from calculate.lib.cl_template import templateFunction from calculate.lib.cl_ini_parser import iniParser +from calculate.lib.utils.portage import isPkgInstalled import hashlib from calculate.lib.cl_lang import setLocalTranslate @@ -474,3 +475,18 @@ class VariableClDesktopFastloginPath(ReadonlyVariable): Путь до каталога в котором указаны пользователи быстрого входа в сеанс """ value = "/var/lib/calculate/calculate-desktop/fastlogin" + + +class VariableClDesktopElogindSet(ReadonlyVariable): + """ + В системе используется elogind + """ + type = Variable.Types.Boolean + elogind = "sys-auth/elogind" + consolekit = "sys-auth/consolekit" + + def get(self): + if isPkgInstalled(self.elogind) and \ + not isPkgInstalled(self.consolekit): + return Variable.On + return Variable.Off