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"
11 class Hotplug(Protocol):
12 def getUserfriendlyDeviceName(self, phys):
13 return DEVICEDB.get(phys, "USB Storage")
15 def connectionMade(self):
18 def dataReceived(self, data):
21 def connectionLost(self, reason):
22 data = self.received.split('\0')[:-1]
28 var, val = x[:i], x[i+1:]
33 action = v.get("ACTION")
34 device = v.get("DEVPATH")
35 physdevpath = v.get("PHYSDEVPATH")
36 media_state = v.get("X_E2_MEDIA_STATUS")
38 dev = device.split('/')[-1]
40 if action is not None and action == "add":
41 print "Medium found in", self.getUserfriendlyDeviceName(dev)
42 harddiskmanager.addHotplugPartition(dev, self.getUserfriendlyDeviceName(physdevpath))
43 elif action is not None and action == "remove":
44 harddiskmanager.removeHotplugPartition(dev)
45 elif media_state is not None:
46 if media_state == '1':
47 harddiskmanager.removeHotplugPartition(dev)
48 harddiskmanager.addHotplugPartition(dev, self.getUserfriendlyDeviceName(physdevpath))
49 elif media_state == '0':
50 harddiskmanager.removeHotplugPartition(dev)
52 def autostart(reason, **kwargs):
54 print "starting hotplug handler"
56 factory.protocol = Hotplug
60 os.remove("/tmp/hotplug.socket")
64 reactor.listenUNIX("/tmp/hotplug.socket", factory)
66 def Plugins(**kwargs):
67 return PluginDescriptor(name = "Hotplug", description = "listens to hotplug events", where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart)