2015-06-26 01:36:36 +01:00
|
|
|
#!/usr/bin/python2
|
2014-03-28 15:44:13 +00:00
|
|
|
|
2009-07-27 11:45:34 +01:00
|
|
|
import os
|
2019-01-21 15:50:58 +00:00
|
|
|
from gi.repository import Gio
|
2009-07-27 11:45:34 +01:00
|
|
|
|
|
|
|
def RemoveArgs(Execline):
|
2019-01-21 15:50:58 +00:00
|
|
|
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
|
2009-07-27 11:45:34 +01:00
|
|
|
|
|
|
|
# Actually execute the command
|
2019-01-21 15:50:58 +00:00
|
|
|
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)
|
2016-05-21 17:11:36 +01:00
|
|
|
if (os.path.exists(tmpCwd)):
|
|
|
|
cwd = tmpCwd
|
|
|
|
|
|
|
|
cmd = RemoveArgs(cmd)
|
|
|
|
|
|
|
|
try:
|
2019-01-21 15:50:58 +00:00
|
|
|
os.chdir(cwd)
|
|
|
|
os.system(cmd + " &")
|
2016-05-21 17:11:36 +01:00
|
|
|
return True
|
2019-01-21 15:50:58 +00:00
|
|
|
except Exception as err:
|
|
|
|
print err
|
2016-05-21 17:11:36 +01:00
|
|
|
return False
|