Move the client method-call machinery from dbus.proxies to dbus.connection._MethodCal...
[dbus-python-phuang.git] / examples / list-system-services.py
blob04745749b5d0c39c22021a4773ba5a3f1fdff98a
1 #!/usr/bin/env python
3 """Usage: python list-system-services.py [--session|--system]
4 List services on the system bus (default) or the session bus."""
6 import sys
8 import dbus
10 def main(argv):
11 factory = dbus.SystemBus
13 if len(argv) > 2:
14 sys.exit(__doc__)
15 elif len(argv) == 2:
16 if argv[1] == '--session':
17 factory = dbus.SessionBus
18 elif argv[1] != 'system':
19 sys.exit(__doc__)
21 # Get a connection to the system or session bus as appropriate
22 # We're only using blocking calls, so don't actually need a main loop here
23 bus = factory()
25 # Get a reference to the desktop bus' standard object, denoted
26 # by the path /org/freedesktop/DBus.
27 dbus_object = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
29 # The object /org/freedesktop/DBus
30 # implements the 'org.freedesktop.DBus' interface
31 dbus_iface = dbus.Interface(dbus_object, 'org.freedesktop.DBus')
33 # One of the member functions in the org.freedesktop.DBus interface
34 # is ListServices(), which provides a list of all the other services
35 # registered on this bus. Call it, and print the list.
36 services = dbus_object.ListNames()
37 services.sort()
38 for service in services:
39 print service
41 if __name__ == '__main__':
42 main(sys.argv)