1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#!/usr/bin/python3
""" Runs a command and then passes the output to Cinnamon via DBus asynchronously
Usage: cinnamon-subprocess-wrapper ls ~/
"""
import subprocess
import sys
from setproctitle import setproctitle
from gi.repository import GLib, Gio
if __name__ == "__main__":
setproctitle("cinnamon-subprocess-wrapper")
process_id = int(sys.argv[1])
try:
result = subprocess.check_output(sys.argv[2:])
success = True
except Exception:
result = b''
success = False
try:
connection = Gio.bus_get_sync(Gio.BusType.SESSION, None)
connection.call_sync("org.Cinnamon",
"/org/Cinnamon",
"org.Cinnamon",
"PushSubprocessResult",
GLib.Variant("(isb)", (process_id, result.decode(errors="replace"), success)),
None,
Gio.DBusCallFlags.NONE,
2000,
None)
except GLib.Error as e:
print("Could not send response (ID: %d): %s" % (process_id, e.message))
|