add Hotplug plugin
authorFelix Domke <tmbinc@elitedvb.net>
Wed, 27 Feb 2008 03:03:59 +0000 (03:03 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Wed, 27 Feb 2008 03:03:59 +0000 (03:03 +0000)
configure.ac
lib/python/Plugins/SystemPlugins/Hotplug/LICENSE [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/Hotplug/Makefile.am [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/Hotplug/__init__.py [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/Hotplug/plugin.py [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/Makefile.am

index 506a09426f5fa8a20d3d360ab17461897173542f..f3239d214657df48db787df0fc5ef9308d7e9b8b 100644 (file)
@@ -87,6 +87,7 @@ lib/python/Plugins/SystemPlugins/Makefile
 lib/python/Plugins/SystemPlugins/SoftwareUpdate/Makefile
 lib/python/Plugins/SystemPlugins/FrontprocessorUpgrade/Makefile
 lib/python/Plugins/SystemPlugins/PositionerSetup/Makefile
 lib/python/Plugins/SystemPlugins/SoftwareUpdate/Makefile
 lib/python/Plugins/SystemPlugins/FrontprocessorUpgrade/Makefile
 lib/python/Plugins/SystemPlugins/PositionerSetup/Makefile
+lib/python/Plugins/SystemPlugins/Hotplug/Makefile
 lib/python/Plugins/SystemPlugins/ConfigurationBackup/Makefile
 lib/python/Plugins/SystemPlugins/Satfinder/Makefile
 lib/python/Plugins/SystemPlugins/SkinSelector/Makefile
 lib/python/Plugins/SystemPlugins/ConfigurationBackup/Makefile
 lib/python/Plugins/SystemPlugins/Satfinder/Makefile
 lib/python/Plugins/SystemPlugins/SkinSelector/Makefile
diff --git a/lib/python/Plugins/SystemPlugins/Hotplug/LICENSE b/lib/python/Plugins/SystemPlugins/Hotplug/LICENSE
new file mode 100644 (file)
index 0000000..9970059
--- /dev/null
@@ -0,0 +1,12 @@
+This plugin is licensed under the Creative Commons 
+Attribution-NonCommercial-ShareAlike 3.0 Unported 
+License. To view a copy of this license, visit
+http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative
+Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
+
+Alternatively, this plugin may be distributed and executed on hardware which
+is licensed by Dream Multimedia GmbH.
+
+This plugin is NOT free software. It is open source, you are allowed to
+modify it (if you keep the license), but it may not be commercially 
+distributed other than under the conditions noted above.
diff --git a/lib/python/Plugins/SystemPlugins/Hotplug/Makefile.am b/lib/python/Plugins/SystemPlugins/Hotplug/Makefile.am
new file mode 100644 (file)
index 0000000..bfb113c
--- /dev/null
@@ -0,0 +1,5 @@
+installdir = $(LIBDIR)/enigma2/python/Plugins/SystemPlugins/Hotplug
+
+install_PYTHON =       \
+       __init__.py \
+       plugin.py
diff --git a/lib/python/Plugins/SystemPlugins/Hotplug/__init__.py b/lib/python/Plugins/SystemPlugins/Hotplug/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/lib/python/Plugins/SystemPlugins/Hotplug/plugin.py b/lib/python/Plugins/SystemPlugins/Hotplug/plugin.py
new file mode 100644 (file)
index 0000000..882668f
--- /dev/null
@@ -0,0 +1,54 @@
+from Plugins.Plugin import PluginDescriptor
+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"
+       }
+
+class Hotplug(Protocol):
+       def getUserfriendlyDeviceName(self, phys):
+               return DEVICEDB.get(phys, "USB Storage")
+
+       def connectionMade(self):
+               self.received = ""
+
+       def dataReceived(self, data):
+               self.received += data
+
+       def connectionLost(self, reason):
+               data = self.received.split('\0')[:-1]
+
+               print "hotplug:", data
+
+               if len(data) < 4:
+                       return
+
+               (action, device, physdev, driver) = data[:4]
+
+               dev = device.split('/')[-1]
+
+               if action == "add":
+                       print "Medium found in", self.getUserfriendlyDeviceName(dev)
+                       harddiskmanager.addHotplugPartition(dev, self.getUserfriendlyDeviceName(dev))
+               elif action == "remove":
+                       harddiskmanager.removeHotplugPartition(dev)
+
+def autostart(reason, **kwargs):
+       if reason == 0:
+               print "starting hotplug handler"
+               factory = Factory()
+               factory.protocol = Hotplug
+
+               try:
+                       import os
+                       os.remove("/tmp/hotplug.socket")
+               except OSError:
+                       pass
+
+               reactor.listenUNIX("/tmp/hotplug.socket", factory)
+
+def Plugins(**kwargs):
+       return PluginDescriptor(name = "Hotplug", description = "listens to hotplug events", where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart)
index 56cb651e969b6a5e898ddd01fc5604279f03a8d7..a82601f652d3384e9819107fd948dfb23c675652 100644 (file)
@@ -1 +1 @@
-SUBDIRS = SoftwareUpdate FrontprocessorUpgrade PositionerSetup ConfigurationBackup Satfinder SkinSelector SatelliteEquipmentControl Videomode VideoTune
+SUBDIRS = SoftwareUpdate FrontprocessorUpgrade PositionerSetup ConfigurationBackup Satfinder SkinSelector SatelliteEquipmentControl Videomode VideoTune Hotplug