DBus-Python - Getting Started

David Collins dcolli22 at csc.com.au
Sun Aug 12 18:56:02 PDT 2007


DBus,

I am trying to get started with DBus python, but am struggling to find
simple up-to-date examples of working Python code.  I am using Python 2.5.1
(r251:54863, May  2 2007, 16:56:35) and dbus 1.0.2-1ubuntu4 on the current
version of Ubuntu (7.04 Feisty).

Can anyone point me to a good learning resource for using Dbus in Python ?

I think that using D-bus within Python will be a really nice system once I
understand the basics.

The working code below shows about how far I have got, so far. :)

Regards,
David Collins
-------------------------------------------------

#!/usr/bin/python

import dbus

# *** SYSTEM bus ***
sysbus = dbus.SystemBus()

obj = sysbus.get_object('org.freedesktop.DBus',
                        '/org/freedesktop/DBus')
print obj.Introspect()        # 'ListNames' is in list
print 'System Interfaces ..'
print '---------------------------------------'
for name in obj.ListNames():
  print name
print '---------------------------------------'
for name in obj.ListActivatableNames():
  print name
print '---------------------------------------'

# *** SESSION bus ***
sessbus = dbus.SessionBus()
obj = sessbus.get_object('org.freedesktop.DBus',
                         '/org/freedesktop/DBus')
# print obj.Introspect()
print 'Session Interfaces ..'
print '---------------------------------------'
for name in obj.ListNames():
  print name
print '---------------------------------------'
for name in obj.ListActivatableNames():
  print name
print '---------------------------------------'

mgr = sysbus.get_object('org.freedesktop.Hal',
                  '/org/freedesktop/Hal/Manager')
print mgr.Introspect()  # 'GetAllDevices' is in list
for dev in mgr.GetAllDevices():
  print str(dev)

computer = sysbus.get_object('org.freedesktop.Hal', \
                  '/org/freedesktop/Hal/devices/computer')
print computer.Introspect()   # 'GetAllProperties' is in list
properties = computer.GetAllProperties()
for item in properties.iteritems():
  print item



More information about the dbus mailing list