xboxdrv/contrib/hal_plugandplay

44 lines
1.3 KiB
Python

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import dbus
import dbus.service
if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
import dbus.glib
import gobject
import sys
import os
class DeviceManager:
def __init__(self):
self.bus = dbus.SystemBus()
self.bus.add_signal_receiver(self.device_added,
'DeviceAdded',
'org.freedesktop.Hal.Manager',
'org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
self.bus.add_signal_receiver(self.device_removed,
'DeviceRemoved',
'org.freedesktop.Hal.Manager',
'org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager')
def udi_to_device(self, udi):
return self.bus.get_object("org.freedesktop.Hal", udi)
def device_added(self, udi):
os.system("exec '/home/media/Scripts/usb_added'")
def device_removed(self, udi):
os.system("exec '/home/media/Scripts/usb_removed'")
if __name__ == '__main__':
m = DeviceManager()
mainloop = gobject.MainLoop()
try:
mainloop.run()
except KeyboardInterrupt:
mainloop.quit()
print 'Exiting...'
sys.exit(0)