summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/Changelog1
-rwxr-xr-xportato.py46
-rw-r--r--portato/constants.py3
-rw-r--r--portato/helper.py19
-rw-r--r--portato/su.py57
5 files changed, 105 insertions, 21 deletions
diff --git a/doc/Changelog b/doc/Changelog
index b88a949..dd0a3d6 100644
--- a/doc/Changelog
+++ b/doc/Changelog
@@ -1,5 +1,6 @@
next:
- allow lines w/o keyword in package.keywords
+- added support for ktsuss as su-frontend
0.12.1:
- bugfixes
diff --git a/portato.py b/portato.py
index 800698a..bdf3ddb 100755
--- a/portato.py
+++ b/portato.py
@@ -20,8 +20,9 @@ import atexit
from optparse import OptionParser, SUPPRESS_HELP
from portato import get_listener, log, start
-from portato.helper import debug, info
-from portato.constants import VERSION, SU_COMMAND
+from portato.su import detect_su_command
+from portato.helper import debug, info, error
+from portato.constants import VERSION
def main ():
start() # the first thing to do :)
@@ -74,23 +75,32 @@ def main ():
lt.setDaemon(False)
lt.start()
- # set DBUS_SESSION_BUS_ADDRESS to "" to make dbus work as root ;)
- env = os.environ.copy()
- env.update(DBUS_SESSION_BUS_ADDRESS="")
- cmd = SU_COMMAND.split()
-
- sp = subprocess.Popen(cmd+["%s --no-fork --shm %ld %ld %ld" % (sys.argv[0], mem.key, sig.key, rw.key)], env = env)
-
- # wait for process to finish
try:
- sp.wait()
- debug("Subprocess finished")
- except KeyboardInterrupt:
- debug("Got KeyboardInterrupt.")
-
- if lt.isAlive():
- debug("Listener is still running. Close it.")
- get_listener().close()
+ # set DBUS_SESSION_BUS_ADDRESS to "" to make dbus work as root ;)
+ env = os.environ.copy()
+ env.update(DBUS_SESSION_BUS_ADDRESS="")
+
+ su = detect_su_command()
+ if su:
+ debug("Using '%s' as su command.", su.bin)
+ cmd = su.cmd("%s --no-fork --shm %ld %ld %ld" % (sys.argv[0], mem.key, sig.key, rw.key))
+
+ sp = subprocess.Popen(cmd, env = env)
+
+ # wait for process to finish
+ try:
+ sp.wait()
+ debug("Subprocess finished")
+ except KeyboardInterrupt:
+ debug("Got KeyboardInterrupt.")
+
+ else:
+ error(_("No valid su command detected. Aborting."))
+
+ finally:
+ if lt.isAlive():
+ debug("Listener is still running. Close it.")
+ get_listener().close()
if __name__ == "__main__":
main()
diff --git a/portato/constants.py b/portato/constants.py
index f188897..7d2a9d6 100644
--- a/portato/constants.py
+++ b/portato/constants.py
@@ -20,8 +20,6 @@ These should be set during the installation.
@type VERSION: string
@var HOME: shortcut to $HOME
@type HOME: string
-@var SU_COMMAND: command to execute to "su"
-@type SU_COMMAND: string
@var CONFIG_DIR: The configuration directory.
@type CONFIG_DIR: string
@@ -58,7 +56,6 @@ APP_ICON = pjoin(ICON_DIR, "portato-icon.png")
APP = "portato"
VERSION = "9999"
HOME = os.environ["HOME"]
-SU_COMMAND = "gksu -D 'Portato'"
# config
CONFIG_DIR = "etc/"
diff --git a/portato/helper.py b/portato/helper.py
index d3fc70b..5b275d6 100644
--- a/portato/helper.py
+++ b/portato/helper.py
@@ -151,3 +151,22 @@ def unique_array(s):
if x not in u:
u.append(x)
return u
+
+def detect_desktop_environment():
+ # stolen from wicd :)
+
+ desktop_environment = 'generic'
+ if os.environ.get('KDE_FULL_SESSION') == 'true':
+ desktop_environment = 'kde'
+ elif os.environ.get('GNOME_DESKTOP_SESSION_ID'):
+ desktop_environment = 'gnome'
+ #else: # no need for this part as of now
+ # try:
+ # info = commands.getoutput('xprop -root _DT_SAVE_MODE')
+ # if ' = "xfce4"' in info:
+ # desktop_environment = 'xfce'
+ # except (OSError, RuntimeError):
+ # pass
+
+ return desktop_environment
+
diff --git a/portato/su.py b/portato/su.py
new file mode 100644
index 0000000..b87c75b
--- /dev/null
+++ b/portato/su.py
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+#
+# File: portato/su.py
+# This file is part of the Portato-Project, a graphical portage-frontend.
+#
+# Copyright (C) 2006-2009 René 'Necoro' Neumann
+# This is free software. You may redistribute copies of it under the terms of
+# the GNU General Public License version 2.
+# There is NO WARRANTY, to the extent permitted by law.
+#
+# Written by René 'Necoro' Neumann <necoro@necoro.net>
+
+from __future__ import with_statement, absolute_import
+
+import os
+
+from .constants import APP_ICON
+from .helper import detect_desktop_environment
+
+class SUCommand (object):
+ def __init__ (self, bin, args):
+ self.bin = bin
+ self.args = args
+
+ def cmd (self, cmd):
+ return [self.bin] + self.args + [cmd]
+
+ def check (self):
+ for p in os.environ['PATH'].split(":"):
+ jp = os.path.join(p, self.bin)
+ if os.access(jp, os.F_OK):
+ return True
+
+ return False
+
+class SplitSUCommand (SUCommand):
+ def cmd (self, cmd):
+ return [self.bin] + self.args + cmd.split()
+
+gtksu = SUCommand("gksu", ["-D", "Portato"])
+kdesu = SUCommand("kdesu", ["-t", "-d", "-i", APP_ICON, "-c"])
+ktsuss = SplitSUCommand("ktsuss", ["-m", "Portato"])
+
+def detect_su_command ():
+ desktop_env = detect_desktop_environment()
+ if desktop_env == "kde":
+ sus = [kdesu, ktsuss, gtksu]
+ elif desktop_env == "gnome":
+ sus = [gtksu, ktsuss, kdesu]
+ else:
+ sus = [ktsuss, gtksu, kdesu]
+
+ for s in sus:
+ if s.check():
+ return s
+
+ return None