File: client.py

package info (click to toggle)
dasbus 1.7-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 880 kB
  • sloc: python: 7,550; makefile: 101; sh: 4
file content (37 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download | duplicates (2)
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
#
# Inhibit the system suspend and hibernation.
#
import os
from dasbus.connection import SystemMessageBus
from dasbus.unix import GLibClientUnix

if __name__ == "__main__":
    # Create a representation of a system bus connection.
    bus = SystemMessageBus()

    # Create a proxy of the /org/freedesktop/login1 object
    # provided by the org.freedesktop.login1 service with
    # an enabled support for Unix file descriptors.
    proxy = bus.get_proxy(
        "org.freedesktop.login1",
        "/org/freedesktop/login1",
        client=GLibClientUnix
    )

    # Inhibit sleep by this example.
    print("Inhibit sleep by my-example.")
    fd = proxy.Inhibit(
        "sleep",
        "my-example",
        "Running an example",
        "block"
    )

    # List active inhibitors.
    print("Active inhibitors:")
    for inhibitor in sorted(proxy.ListInhibitors()):
        print("\t".join(map(str, inhibitor)))

    # Release the inhibition lock.
    print("Release the inhibition lock.")
    os.close(fd)