From 20a98cd287b4ae908a080b99cd89089f1ec48653 Mon Sep 17 00:00:00 2001 From: Andrew <37226388+mrandybu@users.noreply.github.com> Date: Mon, 21 Jan 2019 18:50:58 +0300 Subject: [PATCH] Fix broke running with "xdg-su" in exec field (#200) --- .../linuxmint/mintMenu/plugins/easybuttons.py | 2 +- usr/lib/linuxmint/mintMenu/plugins/execute.py | 57 +++++++++---------- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/usr/lib/linuxmint/mintMenu/plugins/easybuttons.py b/usr/lib/linuxmint/mintMenu/plugins/easybuttons.py index 84d5aa6..a998c17 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/easybuttons.py +++ b/usr/lib/linuxmint/mintMenu/plugins/easybuttons.py @@ -377,7 +377,7 @@ class ApplicationLauncher( easyButton ): cmd = "mate-terminal -e \"" + self.appExec + "\"" Execute(cmd, self.appPath) else: - Execute(self.appExec, self.appPath) + Execute(None, desktopFile=self.desktopFile) def uninstall (self, *args ): Execute("mint-remove-application " + self.desktopFile) diff --git a/usr/lib/linuxmint/mintMenu/plugins/execute.py b/usr/lib/linuxmint/mintMenu/plugins/execute.py index 4e058de..e021dfb 100755 --- a/usr/lib/linuxmint/mintMenu/plugins/execute.py +++ b/usr/lib/linuxmint/mintMenu/plugins/execute.py @@ -1,46 +1,41 @@ #!/usr/bin/python2 import os +from gi.repository import Gio def RemoveArgs(Execline): - NewExecline = [] - Specials=["\"%c\"", "%f","%F","%u","%U","%d","%D","%n","%N","%i","%c","%k","%v","%m","%M", "-caption", "/bin/sh", "sh", "-c", "STARTED_FROM_MENU=yes"] - for elem in Execline: - elem = elem.replace("'","") - elem = elem.replace("\"", "") - if elem not in Specials: - print elem - NewExecline.append(elem) - return NewExecline + if isinstance(Execline, list): + Execline = ' '.join(Execline) + + Specials = ["%f", "%F", "%u", "%U", "%d", "%D", "%n", "%N", "%i", "%c", "%k", "%v", "%m", "%M", + "STARTED_FROM_MENU=yes"] + for spec in Specials: + if spec in Execline: + Execline = Execline.replace(spec, "") + + return Execline # Actually execute the command -def Execute( cmd , commandCwd=None): - if not commandCwd: - cwd = os.path.expanduser( "~" ); - else: - tmpCwd = os.path.expanduser( commandCwd ); +def Execute(cmd , commandCwd=None, desktopFile=None): + if desktopFile: + launcher = Gio.DesktopAppInfo.new_from_filename(desktopFile) + retval = launcher.launch_uris() + + return retval + + cwd = os.path.expanduser("~") + + if commandCwd: + tmpCwd = os.path.expanduser(commandCwd) if (os.path.exists(tmpCwd)): cwd = tmpCwd - if isinstance( cmd, str ) or isinstance( cmd, unicode): - if (cmd.find("ubiquity") >= 0) or (cmd.find("/home/") >= 0) or (cmd.find("su-to-root") >= 0) or (cmd.find("xdg-su") >= 0) or (cmd.find("\"") >= 0): - print "running manually..." - try: - os.chdir(cwd) - os.system(cmd + " &") - return True - except Exception, detail: - print detail - return False - cmd = cmd.split() cmd = RemoveArgs(cmd) try: - os.chdir( cwd ) - string = ' '.join(cmd) - string = string + " &" - os.system(string) + os.chdir(cwd) + os.system(cmd + " &") return True - except Exception, detail: - print detail + except Exception as err: + print err return False