-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-managed-objects
More file actions
executable file
·61 lines (56 loc) · 1.65 KB
/
get-managed-objects
File metadata and controls
executable file
·61 lines (56 loc) · 1.65 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
#!/usr/bin/python3
#+
# DBussy example -- obtain all managed objects from a bus peer. Invoke
# this script as follows:
#
# get-managed-objects session|system «bus_name»
#
# Copyright 2018 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, \
DBUSX
#+
# Mainline
#-
if len(sys.argv) != 3 :
raise getopt.GetoptError("usage: %s session|system «bus-name»" % sys.argv[0])
#end if
which_bus, destination = 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 = "/",
iface = DBUSX.INTERFACE_OBJECT_MANAGER,
method = "GetManagedObjects"
)
reply = conn.loop.run_until_complete(conn.send_await_reply(request))
objs = reply.expect_return_objects("a{oa{sa{sv}}}")[0]
if len(objs) != 0 :
for pathname in sorted(objs.keys()) :
sys.stdout.write("* %s:\n" % pathname)
entry = objs[pathname]
for interface in sorted(entry.keys()) :
sys.stdout.write(" - %s:\n" % interface)
props = entry[interface]
for propname in sorted(props.keys()) :
proptype, propvalue = props[propname]
sys.stdout.write(" %s(%s) = %s\n" % (propname, proptype, repr(propvalue)))
#end for
#end for
#end for
else :
sys.stdout.write("(nothing)\n")
#end if