mintmenu/usr/lib/linuxmint/mintMenu/plugins/execute.py
gm10 3c6e384a1d Assorted cleanup, fixes and performance improvements (#206)
* initial cleanup with some debug messaging

* further cleanup, mostly coding style

* - more cleanup, and speed-up
- more fixes, including many icon and encoding related issues
- replace some icons and remove compile.py
- prepare for python3 port as much as possible

* remove some more unneeded files, few left-over cleanups

* move some external scripts to python3 already

* Fix and clean up add_search_suggestions and add_apt_filter_results logic

* more cleanup, thx Codacity

* fix issue with a path

* add a killall to the test script, fix a method declaration

* fix custom colour setting

* keybinding: re-add GdkX11

* re-add mint-common dep

* Use os.path.expanduser("~") instead of os.environ

* revert re-add GdkX11, but import Gtk first
2019-02-11 13:54:20 +00:00

43 lines
1006 B
Python
Executable File

#!/usr/bin/python2
import os
from gi.repository import Gio
def RemoveArgs(Execline):
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, 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
cmd = RemoveArgs(cmd)
try:
os.chdir(cwd)
os.system(cmd + " &")
return True
except Exception as e:
print(e)
return False