|
Packit |
130fc8 |
#!/usr/bin/env python
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
"""Usage: python list-system-services.py [--session|--system]
|
|
Packit |
130fc8 |
List services on the system bus (default) or the session bus."""
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
# Copyright (C) 2004-2006 Red Hat Inc. <http://www.redhat.com/>
|
|
Packit |
130fc8 |
# Copyright (C) 2005-2007 Collabora Ltd. <http://www.collabora.co.uk/>
|
|
Packit |
130fc8 |
#
|
|
Packit |
130fc8 |
# Permission is hereby granted, free of charge, to any person
|
|
Packit |
130fc8 |
# obtaining a copy of this software and associated documentation
|
|
Packit |
130fc8 |
# files (the "Software"), to deal in the Software without
|
|
Packit |
130fc8 |
# restriction, including without limitation the rights to use, copy,
|
|
Packit |
130fc8 |
# modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
Packit |
130fc8 |
# of the Software, and to permit persons to whom the Software is
|
|
Packit |
130fc8 |
# furnished to do so, subject to the following conditions:
|
|
Packit |
130fc8 |
#
|
|
Packit |
130fc8 |
# The above copyright notice and this permission notice shall be
|
|
Packit |
130fc8 |
# included in all copies or substantial portions of the Software.
|
|
Packit |
130fc8 |
#
|
|
Packit |
130fc8 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
Packit |
130fc8 |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
Packit |
130fc8 |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
Packit |
130fc8 |
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
Packit |
130fc8 |
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
Packit |
130fc8 |
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
Packit |
130fc8 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
Packit |
130fc8 |
# DEALINGS IN THE SOFTWARE.
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
import sys
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
import dbus
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
def main(argv):
|
|
Packit |
130fc8 |
factory = dbus.SystemBus
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
if len(argv) > 2:
|
|
Packit |
130fc8 |
sys.exit(__doc__)
|
|
Packit |
130fc8 |
elif len(argv) == 2:
|
|
Packit |
130fc8 |
if argv[1] == '--session':
|
|
Packit |
130fc8 |
factory = dbus.SessionBus
|
|
Packit |
130fc8 |
elif argv[1] != '--system':
|
|
Packit |
130fc8 |
sys.exit(__doc__)
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
# Get a connection to the system or session bus as appropriate
|
|
Packit |
130fc8 |
# We're only using blocking calls, so don't actually need a main loop here
|
|
Packit |
130fc8 |
bus = factory()
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
# This could be done by calling bus.list_names(), but here's
|
|
Packit |
130fc8 |
# more or less what that means:
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
# Get a reference to the desktop bus' standard object, denoted
|
|
Packit |
130fc8 |
# by the path /org/freedesktop/DBus.
|
|
Packit |
130fc8 |
dbus_object = bus.get_object('org.freedesktop.DBus',
|
|
Packit |
130fc8 |
'/org/freedesktop/DBus')
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
# The object /org/freedesktop/DBus
|
|
Packit |
130fc8 |
# implements the 'org.freedesktop.DBus' interface
|
|
Packit |
130fc8 |
dbus_iface = dbus.Interface(dbus_object, 'org.freedesktop.DBus')
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
# One of the member functions in the org.freedesktop.DBus interface
|
|
Packit |
130fc8 |
# is ListNames(), which provides a list of all the other services
|
|
Packit |
130fc8 |
# registered on this bus. Call it, and print the list.
|
|
Packit |
130fc8 |
services = dbus_iface.ListNames()
|
|
Packit |
130fc8 |
services.sort()
|
|
Packit |
130fc8 |
for service in services:
|
|
Packit |
130fc8 |
print service
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
if __name__ == '__main__':
|
|
Packit |
130fc8 |
main(sys.argv)
|