-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-props
More file actions
executable file
·64 lines (59 loc) · 2.02 KB
/
get-props
File metadata and controls
executable file
·64 lines (59 loc) · 2.02 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python3
#+
# DBussy example -- obtain all property values for an interface at an
# object path from a bus peer. Invoke this script as follows:
#
# get-props session|system «bus_name» «path» «interface»
#
# For example, you can get info about your machine hostname with the
# command
#
# get-props system org.freedesktop.hostname1 /org/freedesktop/hostname1 \
# org.freedesktop.hostname1
#
# and you can get info about your current login with the commands
#
# get-props system org.freedesktop.login1 /org/freedesktop/login1/session/self \
# org.freedesktop.login1.Session
# get-props system org.freedesktop.login1 /org/freedesktop/login1/seat/self \
# org.freedesktop.login1.Seat
# get-props system org.freedesktop.login1 /org/freedesktop/login1/user/self \
# org.freedesktop.login1.User
#
# Copyright 2017 by Lawrence D'Oliveiro <ldo@geek-central.gen.nz>. This
# script is licensed CC0
# <https://creativecommons.org/publicdomain/zero/1.0/>; do with it
# what you will.
#-
import sys
import getopt
import dbussy as dbus
from dbussy import \
DBUS
#+
# Mainline
#-
if len(sys.argv) != 5 :
raise getopt.GetoptError("usage: %s session|system «bus-name» «path» «interface»" % sys.argv[0])
#end if
which_bus, destination, object_path, interface_name = sys.argv[1:]
conn = dbus.Connection.bus_get \
(
{"session" : DBUS.BUS_SESSION, "system" : DBUS.BUS_SYSTEM}[which_bus.lower()],
private = False
)
conn.attach_asyncio()
request = dbus.Message.new_method_call \
(
destination = dbus.valid_bus_name(destination),
path = dbus.valid_path(object_path),
iface = DBUS.INTERFACE_PROPERTIES,
method = "GetAll"
)
request.append_objects("s", dbus.valid_interface(interface_name))
reply = conn.loop.run_until_complete(conn.send_await_reply(request))
values = reply.expect_return_objects("a{sv}")[0]
for propname in sorted(values.keys()) :
proptype, propvalue = values[propname]
sys.stdout.write("%s(%s) = %s\n" % (propname, proptype, repr(propvalue)))
#end for