Get a signal when a device is mounted

Simon Wagner wagner.sim88 at web.de
Fri Sep 12 04:58:39 PDT 2008


Hello,
i am writing a program that takes care of all the removable devices that are connected to the computer. It will become a panel applet that should allow easy mounting/umounting like in windows the "save remove" function in the taskbar.
The program is written in Python.
As a start I took the code from https://dfwpython.org/repo/Projects/DBUS/dtest.py.
I have now a HalManager and a hall device class that can recognize, when a device is (physically) added or removed from the computer.
However I have no working code that will notify me, when a volume is mounted or unmounted.

According to http://people.redhat.com/davidz/hal-spec/hal-spec.html#device-properties-volume I would have to listen for the Condition VolumeMount/VolumeUnmount.
My Problem is now: How can I listen for such conditions. At this point I have this code to listen for conditions:

Code Snippet:

class HalDevice(object):

	INTERFACE = 'org.freedesktop.Hal.Device'

	def __init__(self, udi):
		bus      = dbus.SystemBus()
		self.dev_obj  = bus.get_object(HalManager.SERVICE, udi)
        	self.dev = dbus.Interface(self.dev_obj, HalDevice.INTERFACE)
        	self.udi = udi

		self.dev.connect_to_signal('PropertyModified', self.property_modified)
		self.dev.connect_to_signal('Condition', self.condition_occurred)

		self.properties = self.HalDevicePropertiesMapping(self)
		self.capabilities = self.HalDeviceCapabilitiesSet(self)

	def condition_occurred(self, condition, *args, **kwargs):
		"""
		Notification handler that receives information about the occurrence of
		a non-property event.

		Normally this is used to signal events that aren't or can't be
		expressed in properties, e.g. 'ProcessorOverheating' etc.

	"""
		print "condition_occurred for "  + self.udi
		print "condition = " + str(key)
		print "args = " + str(args)
		print "kwargs = " + str(kwargs)
		pass

However, if i mount a volume, the function condition_occured is never called. Furthermore, if i monitor the system bus, i also can't see any VolumeMount/VolumeUnmount messages.
Can you tell me what I have to do, to get a notification when a volume is mounted or unmounted?
If wanted I can send the full code

Thanks!
S.W.
______________________________________________________________
"Hostage" mit Bruce Willis kostenlos anschauen!
Exklusiv für alle WEB.DE Nutzer. http://www.blockbuster.web.de



More information about the hal mailing list