mintmenu/usr/lib/linuxmint/mintMenu/plugins/execute.py
James Lu d004409af9 Coerse shebangs to #!/usr/bin/python2
Arch Linux's default "python" install points to Python 3, and mintmenu is certainly not compatible with it!

Closes #134.
2015-06-25 17:44:30 -07:00

48 lines
1.2 KiB
Python
Executable File

#!/usr/bin/python2
import os
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
# Actually execute the command
def Execute( cmd , commandCwd=None):
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("\"") >= 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)
return True
except Exception, detail:
print detail
return False