mintmenu/usr/lib/linuxmint/mintMenu/plugins/execute.py

48 lines
1.4 KiB
Python
Raw Normal View History

#!/usr/bin/python2
2014-03-28 15:44:13 +00:00
2009-07-27 11:45:34 +01:00
import os
def RemoveArgs(Execline):
2016-05-21 17:11:36 +01:00
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
2009-07-27 11:45:34 +01:00
# Actually execute the command
def Execute( cmd , commandCwd=None):
2016-05-21 17:11:36 +01:00
if not commandCwd:
cwd = os.path.expanduser( "~" );
else:
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):
2016-05-21 17:11:36 +01:00
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)
return True
except Exception, detail:
print detail
return False