1 from Plugins.Plugin import PluginDescriptor
2 from twisted.internet.protocol import Protocol, Factory
3 from twisted.internet import reactor
4 from Components.Harddisk import harddiskmanager
7 { "/devices/pci0000:00/0000:00:14.2/usb1/1-1/1-1:1.0/host0/target0:0:0/0:0:0:0": "CF Slot",
8 "/devices/pci0000:00/0000:00:14.2/usb1/1-1/1-1:1.0/host0/target1:0:0/0:0:0:0": "SD Slot"
13 class Hotplug(Protocol):
14 def getUserfriendlyDeviceName(self, phys):
15 return DEVICEDB.get(phys, "USB Storage")
17 def connectionMade(self):
20 def dataReceived(self, data):
23 def connectionLost(self, reason):
24 data = self.received.split('\0')[:-1]
30 var, val = x[:i], x[i+1:]
35 action = v.get("ACTION")
36 device = v.get("DEVPATH")
37 physdevpath = v.get("PHYSDEVPATH")
38 media_state = v.get("X_E2_MEDIA_STATUS")
40 dev = device.split('/')[-1]
42 if action is not None and action == "add":
43 print "Medium found in", self.getUserfriendlyDeviceName(dev)
44 harddiskmanager.addHotplugPartition(dev, self.getUserfriendlyDeviceName(physdevpath))
45 elif action is not None and action == "remove":
46 harddiskmanager.removeHotplugPartition(dev)
47 elif media_state is not None:
48 if media_state == '1':
49 harddiskmanager.removeHotplugPartition(dev)
50 harddiskmanager.addHotplugPartition(dev, self.getUserfriendlyDeviceName(physdevpath))
51 elif media_state == '0':
52 harddiskmanager.removeHotplugPartition(dev)
54 for callback in hotplugNotifier:
56 callback(dev, action or media_state)
57 except AttributeError:
58 hotplugNotifier.remove(callback)
60 def autostart(reason, **kwargs):
62 print "starting hotplug handler"
64 factory.protocol = Hotplug
68 os.remove("/tmp/hotplug.socket")
72 reactor.listenUNIX("/tmp/hotplug.socket", factory)
74 def Plugins(**kwargs):
75 return PluginDescriptor(name = "Hotplug", description = "listens to hotplug events", where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart)