X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/226cd38475ed94cb9f412d9d16e249a85fa40b67..defadb893d6897935165b63a9de09b95f43dfcc1:/lib/python/Plugins/SystemPlugins/Hotplug/plugin.py diff --git a/lib/python/Plugins/SystemPlugins/Hotplug/plugin.py b/lib/python/Plugins/SystemPlugins/Hotplug/plugin.py index 882668f7..b19007c9 100644 --- a/lib/python/Plugins/SystemPlugins/Hotplug/plugin.py +++ b/lib/python/Plugins/SystemPlugins/Hotplug/plugin.py @@ -3,15 +3,9 @@ from twisted.internet.protocol import Protocol, Factory from twisted.internet import reactor from Components.Harddisk import harddiskmanager -DEVICEDB = \ - { "/devices/pci0000:00/0000:00:14.2/usb1/1-1/1-1:1.0/host0/target0:0:0/0:0:0:0": "CF Slot", - "/devices/pci0000:00/0000:00:14.2/usb1/1-1/1-1:1.0/host0/target1:0:0/0:0:0:0": "SD Slot" - } +hotplugNotifier = [ ] class Hotplug(Protocol): - def getUserfriendlyDeviceName(self, phys): - return DEVICEDB.get(phys, "USB Storage") - def connectionMade(self): self.received = "" @@ -21,20 +15,38 @@ class Hotplug(Protocol): def connectionLost(self, reason): data = self.received.split('\0')[:-1] - print "hotplug:", data + v = {} + + for x in data: + i = x.find('=') + var, val = x[:i], x[i+1:] + v[var] = val - if len(data) < 4: - return + print "hotplug:", v - (action, device, physdev, driver) = data[:4] + action = v.get("ACTION") + device = v.get("DEVPATH") + physdevpath = v.get("PHYSDEVPATH") + media_state = v.get("X_E2_MEDIA_STATUS") dev = device.split('/')[-1] - if action == "add": - print "Medium found in", self.getUserfriendlyDeviceName(dev) - harddiskmanager.addHotplugPartition(dev, self.getUserfriendlyDeviceName(dev)) - elif action == "remove": + if action is not None and action == "add": + harddiskmanager.addHotplugPartition(dev, physdevpath) + elif action is not None and action == "remove": harddiskmanager.removeHotplugPartition(dev) + elif media_state is not None: + if media_state == '1': + harddiskmanager.removeHotplugPartition(dev) + harddiskmanager.addHotplugPartition(dev, physdevpath) + elif media_state == '0': + harddiskmanager.removeHotplugPartition(dev) + + for callback in hotplugNotifier: + try: + callback(dev, action or media_state) + except AttributeError: + hotplugNotifier.remove(callback) def autostart(reason, **kwargs): if reason == 0: