auto start mediascanner on hotplug change (new device plugged or medium
[enigma2.git] / lib / python / Plugins / SystemPlugins / Hotplug / plugin.py
index 882668f74c6dcd9e84925f07abba4d6665763836..469b1dd0a948af1b5da4ba4c4ab474e937a15979 100644 (file)
@@ -21,20 +21,33 @@ class Hotplug(Protocol):
        def connectionLost(self, reason):
                data = self.received.split('\0')[:-1]
 
        def connectionLost(self, reason):
                data = self.received.split('\0')[:-1]
 
-               print "hotplug:", data
+               v = {}
 
 
-               if len(data) < 4:
-                       return
+               for x in data:
+                       i = x.find('=')
+                       var, val = x[:i], x[i+1:]
+                       v[var] = val
 
 
-               (action, device, physdev, driver) = data[:4]
+               print "hotplug:", v
+
+               action = v.get("ACTION")
+               device = v.get("DEVPATH")
+               physdevpath = v.get("PHYSDEVPATH")
+               media_state = v.get("X_E2_MEDIA_STATUS")
 
                dev = device.split('/')[-1]
 
 
                dev = device.split('/')[-1]
 
-               if action == "add":
+               if action is not None and action == "add":
                        print "Medium found in", self.getUserfriendlyDeviceName(dev)
                        print "Medium found in", self.getUserfriendlyDeviceName(dev)
-                       harddiskmanager.addHotplugPartition(dev, self.getUserfriendlyDeviceName(dev))
-               elif action == "remove":
+                       harddiskmanager.addHotplugPartition(dev, self.getUserfriendlyDeviceName(physdevpath))
+               elif action is not None and action == "remove":
                        harddiskmanager.removeHotplugPartition(dev)
                        harddiskmanager.removeHotplugPartition(dev)
+               elif media_state is not None:
+                       if media_state == '1':
+                               harddiskmanager.removeHotplugPartition(dev)
+                               harddiskmanager.addHotplugPartition(dev, self.getUserfriendlyDeviceName(physdevpath))
+                       elif media_state == '0':
+                               harddiskmanager.removeHotplugPartition(dev)
 
 def autostart(reason, **kwargs):
        if reason == 0:
 
 def autostart(reason, **kwargs):
        if reason == 0: