File: cinnamon-subprocess-wrapper

package info (click to toggle)
cinnamon 6.4.13-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,304 kB
  • sloc: javascript: 54,298; ansic: 51,499; python: 21,971; xml: 2,803; sh: 96; makefile: 27; perl: 13
file content (37 lines) | stat: -rwxr-xr-x 1,157 bytes parent folder | download | duplicates (3)
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))