-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintrospect
executable file
·46 lines (43 loc) · 1.46 KB
/
introspect
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
#!/usr/bin/python3
#+
# DBussy example -- make an Introspect query to a specified bus object.
# This version uses asyncio. Invoke this script as follows:
#
# introspect «bus» «bus-name» «obj-path»
#
# where «bus» is either “session” or “system”, indicating which bus
# to do the query on, “bus-name” is the name of the service on the
# bus to query, and «obj-path» is the path of the object to query.
# The response should be an XML string in the usual introspection
# format, indicating the protocol for communicating with the
# specified object.
#
# 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
if len(sys.argv) != 4 :
raise getopt.GetoptError("usage: %s session|system «bus-name» «obj-path»" % sys.argv[0])
#end if
conn = dbus.Connection.bus_get \
(
{"session" : DBUS.BUS_SESSION, "system" : DBUS.BUS_SYSTEM}[sys.argv[1].lower()],
private = False
)
conn.attach_asyncio()
message = dbus.Message.new_method_call \
(
destination = dbus.valid_bus_name(sys.argv[2]),
path = dbus.valid_path(sys.argv[3]),
iface = DBUS.INTERFACE_INTROSPECTABLE,
method = "Introspect"
)
await_reply = conn.send_await_reply(message)
reply = conn.loop.run_until_complete(await_reply)
sys.stdout.write(reply.expect_return_objects("s")[0])