Cannot get Mount/Unmount notifications.

Matthew Yacobucci myacobucci at jabber.com
Tue May 29 08:35:24 PDT 2007


Hello all,

I'm new to dbus and hal and am trying to get some notifications from Volumes
at mount and umount.

Unfortunately I am having trouble getting these notifications,
but a generic catchall that I found in an example.  Currently I'm using
dbus-1.0.2, hal-0.5.7.1, and dbus-python 0.80.2.

In the main() function I'm simply looping through all devices and then doing a
check for 'block' capability and then 'is_volume'.  Once that is determined I am
getting the ProxyObject for the device and trying to connect_to_signal for the "VolumeMount",
"VolumeUnmount", and "VolumeUnmountForced" conditions.  The handler I
have setup never gets called back though.  The only signal I see get hit
is the "catchall_signal_handler" for the "PropertyModified" signal.

What I am doing is running this script and then mounting and unmounting
a volume on my local machine (mostly just mounting /dev/sda1).  Any suggestions or
advice would be greatly appreciated?

Thanks,
M Yacobucci

-------------------- python script --------------------
#!/usr/bin/env python2
import dbus
from dbus.mainloop.glib import DBusGMainLoop
import gobject

def catchall_signal_handler(*args, **kwargs):
    print ("Caught signal (in catchall handler) " + \
            kwargs['dbus_interface'] + "." + kwargs['member'])

    for arg in args:
        print "        " + str(arg)

    if len(args) > 1:
        print
        for i in args[1]:
            print i

    print "kwargs: ", kwargs

# XXX why don't these work?
def catchall_mount_signals_handler(*args, **kwargs):
    print "Caught mount signal " + device

def volume_mounted(device, mount):
    print "Caught mount signal"

    print "Volume %s mounted to %s" % (device, mount)

def volume_unmounted(device, mount):
    print "Caught unmount signal"

    print "Volume %s unmounted from %s" % (device, mount)

def volume_forced(device, mount):
    print "Caught forced unmount signal"

    print "Volume %s force unmounted from %s" % (device, mount)

def main():
    DBusGMainLoop(set_as_default=True)

    bus = dbus.Bus(dbus.Bus.TYPE_SYSTEM)

    hal_obj = bus.get_object('org.freedesktop.Hal', \
            '/org/freedesktop/Hal/Manager')
    manager = dbus.Interface(hal_obj, 'org.freedesktop.Hal.Manager')

    udis = manager.GetAllDevices()
    for udi in udis:
        dev_obj = bus.get_object('org.freedesktop.Hal', udi)
        dev = dbus.Interface(dev_obj, 'org.freedesktop.Hal.Device')

        if dev.QueryCapability('block'):
            print udi
            if dev.GetProperty('block.is_volume'):
                print "System device: %s" %
(dev.GetProperty('block.device'))

                if dev.QueryCapability('volume'):
                    if dev.GetProperty('volume.is_mounted'):
                        print "Mounted volume"
                    else:
                        print "Not mounted"

                    print dev.GetProperty('volume.mount_point')
                    print dev.GetProperty('volume.fstype')
                    print dev.GetProperty('volume.size')

                    dev_obj.connect_to_signal('VolumeMount', volume_mounted)
                    dev_obj.connect_to_signal('VolumeUnmount',
volume_unmounted)
                    dev_obj.connect_to_signal('VolumeUnmountForced',
                            volume_forced)
            else:
                if dev.QueryCapability('storage'):
                    print dev.GetProperty('storage.bus')
                    print dev.GetProperty('storage.drive_type')

    bus.add_signal_receiver(catchall_signal_handler, \
            interface_keyword='dbus_interface', member_keyword='member')

    bus.add_signal_receiver(catchall_mount_signals_handler, \
            dbus_interface = "org.freedesktop.Hal.Device.Volume", \
            signal_name = "VolumeMount")

    loop = gobject.MainLoop()
    loop.run()

    return 0;

if __name__ == "__main__":
    main()




More information about the hal mailing list