Fix broke running with "xdg-su" in exec field (#200)

This commit is contained in:
Andrew 2019-01-21 18:50:58 +03:00 committed by Clement Lefebvre
parent df1460d7c5
commit 20a98cd287
2 changed files with 27 additions and 32 deletions

View File

@ -377,7 +377,7 @@ class ApplicationLauncher( easyButton ):
cmd = "mate-terminal -e \"" + self.appExec + "\"" cmd = "mate-terminal -e \"" + self.appExec + "\""
Execute(cmd, self.appPath) Execute(cmd, self.appPath)
else: else:
Execute(self.appExec, self.appPath) Execute(None, desktopFile=self.desktopFile)
def uninstall (self, *args ): def uninstall (self, *args ):
Execute("mint-remove-application " + self.desktopFile) Execute("mint-remove-application " + self.desktopFile)

View File

@ -1,46 +1,41 @@
#!/usr/bin/python2 #!/usr/bin/python2
import os import os
from gi.repository import Gio
def RemoveArgs(Execline): def RemoveArgs(Execline):
NewExecline = [] if isinstance(Execline, list):
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"] Execline = ' '.join(Execline)
for elem in Execline:
elem = elem.replace("'","") Specials = ["%f", "%F", "%u", "%U", "%d", "%D", "%n", "%N", "%i", "%c", "%k", "%v", "%m", "%M",
elem = elem.replace("\"", "") "STARTED_FROM_MENU=yes"]
if elem not in Specials: for spec in Specials:
print elem if spec in Execline:
NewExecline.append(elem) Execline = Execline.replace(spec, "")
return NewExecline
return Execline
# Actually execute the command # Actually execute the command
def Execute( cmd , commandCwd=None): def Execute(cmd , commandCwd=None, desktopFile=None):
if not commandCwd: if desktopFile:
cwd = os.path.expanduser( "~" ); launcher = Gio.DesktopAppInfo.new_from_filename(desktopFile)
else: retval = launcher.launch_uris()
tmpCwd = os.path.expanduser( commandCwd );
return retval
cwd = os.path.expanduser("~")
if commandCwd:
tmpCwd = os.path.expanduser(commandCwd)
if (os.path.exists(tmpCwd)): if (os.path.exists(tmpCwd)):
cwd = 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) cmd = RemoveArgs(cmd)
try: try:
os.chdir( cwd ) os.chdir(cwd)
string = ' '.join(cmd) os.system(cmd + " &")
string = string + " &"
os.system(string)
return True return True
except Exception, detail: except Exception as err:
print detail print err
return False return False