-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_bus_names_blocking
More file actions
executable file
·83 lines (80 loc) · 2.41 KB
/
list_bus_names_blocking
File metadata and controls
executable file
·83 lines (80 loc) · 2.41 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/python3
#+
# DBussy example -- ask the D-Bus daemon for a list of all registered names
# on a bus. Invoke this script as follows:
#
# list_bus_names_blocking [--activatable] [--owners] [--unique] session|system
#
# where --activatable specifies you want a list of activatable (as opposed
# to active) names, --owners shows the unique bus names owning the names,
# and --unique means you want the unique names (beginning with a colon
# and assigned by the D-Bus daemon) as opposed to the requested names.
# The single argument is the bus for which to list the names.
#
# 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
activatable = False
show_owners = False
unique = False
opts, args = getopt.getopt \
(
sys.argv[1:],
"",
["activatable", "owners", "unique"]
)
for keyword, value in opts :
if keyword == "--activatable" :
activatable = True
elif keyword == "--owners" :
show_owners = True
elif keyword == "--unique" :
unique = True
#end if
#end for
if len(args) != 1 :
raise getopt.GetoptError("usage: %s session|system" % sys.argv[0])
#end if
conn = dbus.Connection.bus_get \
(
{"session" : DBUS.BUS_SESSION, "system" : DBUS.BUS_SYSTEM}[args[0].lower()],
private = False
)
reply = conn.send_with_reply_and_block \
(
dbus.Message.new_method_call
(
destination = DBUS.SERVICE_DBUS,
path = DBUS.PATH_DBUS,
iface = DBUS.INTERFACE_DBUS,
method = ("ListNames", "ListActivatableNames")[activatable]
)
)
for name in sorted(reply.expect_objects("as")[0]) :
if name.startswith(":") == unique :
if show_owners :
reply = conn.send_with_reply_and_block \
(
dbus.Message.new_method_call
(
destination = DBUS.SERVICE_DBUS,
path = DBUS.PATH_DBUS,
iface = DBUS.INTERFACE_DBUS,
method = "GetNameOwner"
)
.append_objects("s", name)
)
owner, = reply.all_objects
sys.stdout.write("%s -> %s\n" % (name, owner))
else :
sys.stdout.write(name + "\n")
#end if
#end if
#end for