add WOLSetup(WakeOnLan) plugin.
authorkos <kos@dev3>
Tue, 16 Jul 2013 05:21:42 +0000 (14:21 +0900)
committerkos <kos@dev3>
Tue, 16 Jul 2013 05:21:42 +0000 (14:21 +0900)
configure.ac
lib/python/Plugins/SystemPlugins/Makefile.am
lib/python/Plugins/SystemPlugins/WOLSetup/Makefile.am [new file with mode: 0755]
lib/python/Plugins/SystemPlugins/WOLSetup/__init__.py [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/WOLSetup/meta/Makefile.am [new file with mode: 0755]
lib/python/Plugins/SystemPlugins/WOLSetup/meta/plugin_wolsetup.xml [new file with mode: 0755]
lib/python/Plugins/SystemPlugins/WOLSetup/plugin.py [new file with mode: 0644]

index 057ded7..07f5c6b 100644 (file)
@@ -274,6 +274,8 @@ lib/python/Plugins/SystemPlugins/DeviceManager/locale/Makefile
 lib/python/Plugins/SystemPlugins/TransCodingSetup/Makefile
 lib/python/Plugins/SystemPlugins/TransCodingSetup/meta/Makefile
 lib/python/Plugins/SystemPlugins/TransCodingSetup/locale/Makefile
+lib/python/Plugins/SystemPlugins/WOLSetup/Makefile
+lib/python/Plugins/SystemPlugins/WOLSetup/meta/Makefile
 lib/python/Tools/Makefile
 lib/service/Makefile
 lib/components/Makefile
index c85fc4a..32c8543 100755 (executable)
@@ -7,7 +7,7 @@ SUBDIRS = SoftwareManager FrontprocessorUpgrade PositionerSetup Satfinder \
        TempFanControl FactoryTest Fancontrol FPGAUpgrade WirelessLanSetup ManualFancontrol \
        Blindscan RemoteControlCode UI3DSetup UIPositionSetup HDMICEC LEDBrightnessSetup \
        FirmwareUpgrade CrashReport 3GModemManager WirelessAccessPoint ZappingModeSelection \
-       DeviceManager TransCodingSetup
+       DeviceManager TransCodingSetup WOLSetup
 
 install_PYTHON =       \
        __init__.py
diff --git a/lib/python/Plugins/SystemPlugins/WOLSetup/Makefile.am b/lib/python/Plugins/SystemPlugins/WOLSetup/Makefile.am
new file mode 100755 (executable)
index 0000000..5850d94
--- /dev/null
@@ -0,0 +1,5 @@
+installdir = $(pkglibdir)/python/Plugins/SystemPlugins/WOLSetup
+
+SUBDIRS = meta 
+
+install_PYTHON = __init__.py plugin.py 
diff --git a/lib/python/Plugins/SystemPlugins/WOLSetup/__init__.py b/lib/python/Plugins/SystemPlugins/WOLSetup/__init__.py
new file mode 100644 (file)
index 0000000..9ce06a8
--- /dev/null
@@ -0,0 +1 @@
+# dummy
diff --git a/lib/python/Plugins/SystemPlugins/WOLSetup/meta/Makefile.am b/lib/python/Plugins/SystemPlugins/WOLSetup/meta/Makefile.am
new file mode 100755 (executable)
index 0000000..a8f6379
--- /dev/null
@@ -0,0 +1,3 @@
+installdir = $(datadir)/meta
+
+dist_install_DATA = plugin_wolsetup.xml
diff --git a/lib/python/Plugins/SystemPlugins/WOLSetup/meta/plugin_wolsetup.xml b/lib/python/Plugins/SystemPlugins/WOLSetup/meta/plugin_wolsetup.xml
new file mode 100755 (executable)
index 0000000..c9630bc
--- /dev/null
@@ -0,0 +1,16 @@
+<default>
+         <prerequisites>
+                    <tag type="System" />
+         </prerequisites>
+          <info>
+                    <author>kos(oskwon@dev3)</author>
+                    <name>WOLSetup</name>
+                    <packagename>enigma2-plugin-systemplugins-wolsetup</packagename>
+                    <shortdescription>WakeOnLan Setup on your Vu+</shortdescription>
+                    <description>WakeOnLan Setup on your Vu+</description>
+          </info>
+
+         <files type="package"> <!-- without version, without .ipk -->
+               <file type="package" name="enigma2-plugin-systemplugins-wolsetup" />
+       </files>
+</default>
diff --git a/lib/python/Plugins/SystemPlugins/WOLSetup/plugin.py b/lib/python/Plugins/SystemPlugins/WOLSetup/plugin.py
new file mode 100644 (file)
index 0000000..9beb993
--- /dev/null
@@ -0,0 +1,186 @@
+from Plugins.Plugin import PluginDescriptor
+
+from Screens.Screen import Screen
+from Components.ActionMap import ActionMap
+from Components.Label import Label
+from Components.Sources.StaticText import StaticText
+
+from Screens.ChoiceBox import ChoiceBox
+from Screens.MessageBox import MessageBox
+from Screens.Standby import TryQuitMainloop
+
+from Components.PluginComponent import plugins
+
+from Components.ConfigList import ConfigListScreen
+from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigYesNo, ConfigSelection
+
+import os
+
+_deviseWOL = "/proc/stb/fp/wol"
+
+_flagForceEnable = False
+_flagSupportWol = _flagForceEnable and True or os.path.exists(_deviseWOL)
+
+_tryQuitTable = {"deepstandby":1, "reboot":2, "guirestart":3}
+
+_ethDevice = "eth0"
+
+config.plugins.wolconfig = ConfigSubsection()
+config.plugins.wolconfig.activate = ConfigYesNo(default = False)
+config.plugins.wolconfig.location = ConfigSelection(default = "menu", choices = [("menu", _("Show on the Standby Menu")), ("deepstandby", _("Run at the Deep Standby"))])
+
+class WOLSetup(ConfigListScreen, Screen):
+       skin =  """
+               <screen name="WOLSetup" position="center,120" size="600,390" title="WakeOnLan Setup">
+                       <ePixmap pixmap="skin_default/buttons/red.png" position="5,0" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/green.png" position="155,0" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/yellow.png" position="305,0" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/blue.png" position="455,0" size="140,40" alphatest="on" />
+
+                       <widget source="key_red" render="Label" position="5,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
+                       <widget source="key_green" render="Label" position="155,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
+                       <widget source="key_yellow" render="Label" position="305,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" foregroundColor="#ffffff" transparent="1" />
+                       <widget source="key_blue" render="Label" position="455,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" foregroundColor="#ffffff" transparent="1" />
+
+                       <widget name="config" position="5,70" size="590,280" scrollbarMode="showOnDemand" />
+                       <widget name="introduction" position="5,365" size="590,20" font="Regular;20" halign="center" />
+               </screen>
+               """
+       def __init__(self, session):
+               self.configlist = []
+               self.session = session
+               Screen.__init__(self, session)
+               ConfigListScreen.__init__(self, self.configlist)
+
+               self["actions"]  = ActionMap(["OkCancelActions", "ColorActions", "WizardActions"], {
+                       "cancel": self.OnKeyCancel,
+                       "green" : self.OnKeyGreen,
+                       "red"   : self.OnKeyRed,
+                       "blue"  : self.OnKeyBlue,
+               }, -1)
+
+               self["key_red"]    = StaticText(_("Close"))
+               self["key_green"]  = StaticText(_("Save"))
+               self["key_yellow"] = StaticText(_(" "))
+               self["key_blue"]   = StaticText(_("Default"))
+
+               self["introduction"] = Label(_(" "))
+
+               self.default = {"activate":False, "location":"menu"}
+               self.backup = {
+                       "activate":config.plugins.wolconfig.activate.value,
+                       "location":config.plugins.wolconfig.location.value,
+                       }
+
+               self.MakeConfigList()
+
+       def MakeConfigList(self):
+               self.UpdateConfigList()
+
+       def UpdateConfigList(self):
+               self.configlist = []
+               if _flagSupportWol:
+                       self.configlist.append(getConfigListEntry(_("WakeOnLan Enable"), config.plugins.wolconfig.activate))
+                       if config.plugins.wolconfig.activate.value:
+                               self.configlist.append(getConfigListEntry(_("  - Location"), config.plugins.wolconfig.location))
+
+               self["config"].list = self.configlist
+               self["config"].l.setList(self.configlist)
+
+       def Save(self):
+               config.plugins.wolconfig.activate.save()
+               config.plugins.wolconfig.location.save()
+               config.plugins.wolconfig.save()
+               config.plugins.save()
+               config.save()
+
+       def Restore(self):
+               print "[WOLSetup] Restore :", self.backup
+               config.plugins.wolconfig.activate.value = self.backup["activate"]
+               config.plugins.wolconfig.location.value = self.backup["location"]
+
+       def OnKeyGreenCB(self, answer):
+               answer = answer and answer[1]
+               if answer == "n":
+                       self.Restore()
+                       return
+               self.Save()
+               self.close()
+
+       def OnKeyGreen(self):
+               if config.plugins.wolconfig.activate.value == self.backup["activate"] and config.plugins.wolconfig.location.value == self.backup["location"]:
+                       self.close()
+                       return
+               if not config.plugins.wolconfig.activate.value:
+                       WOLSetup.ActivateWOL(False, True)
+                       self.OnKeyBlue()
+                       self.Save()
+                       self.close()
+                       return
+               message = _("If WOL is enabled, power consumption will be around 2W.\nErP Standby Power Regulation (<0.5W at standby) cannot be met.\nProceed?")
+               self.session.openWithCallback(self.OnKeyGreenCB, ChoiceBox, title=message, list=((_("Yes"), "y"), (_("No"), "n"),))
+
+       def OnKeyCancel(self):
+               self.Restore()
+               self.close()
+
+       def OnKeyRed(self):
+               self.OnKeyCancel()
+
+       def OnKeyBlue(self):
+               print "[WOLSetup] Set Default :", self.default
+               config.plugins.wolconfig.activate.value = self.default["activate"]
+               config.plugins.wolconfig.location.value = self.default["location"]
+               self.UpdateConfigList()
+
+       def keyLeft(self):
+               ConfigListScreen.keyLeft(self)
+               self.UpdateConfigList()
+
+       def keyRight(self):
+               ConfigListScreen.keyRight(self)
+               self.UpdateConfigList()
+
+       @staticmethod
+       def ActivateWOL(self=None, enable=True, writeDevice=False):
+               print "[WOLSetup] Support :", _flagSupportWol, " Enable :", enable ," WriteDevice :", writeDevice
+               if not _flagSupportWol:
+                       return
+               if writeDevice:
+                       os.system('echo "%s" > %s' % (enable and "enable" or "disble",_deviseWOL))
+               os.system("ethtool -s %s wol %s" % (_ethDevice, enable and "g" or "d"))
+
+       @staticmethod
+       def DeepStandbyNotifierCB(self=None):
+               if config.plugins.wolconfig.activate.value:
+                       if config.plugins.wolconfig.location.value == "deepstandby":
+                               print "[WOLSetup] Deep Standby with WOL."
+                               WOLSetup.ActivateWOL(writeDevice=True)
+                       else:   print "[WOLSetup] Deep Standby without WOL."
+               else:   print "[WOLSetup] Nomal Deep Standby."
+
+def SessionStartMain(session, **kwargs):
+       config.misc.DeepStandbyOn.addNotifier(WOLSetup.DeepStandbyNotifierCB, initial_call=False)
+
+def PluginMain(session, **kwargs):
+       session.open(WOLSetup)
+
+def DeepStandbyWOLMain(session, **kwargs):
+       WOLSetup.ActivateWOL(session, writeDevice=True)
+       session.open(TryQuitMainloop, _tryQuitTable["deepstandby"])
+
+def MenuSelected(selected, **kwargs):
+       if selected == "system":
+               return [(_("WakeOnLan Setup"), PluginMain, "wolconfig", 80)]
+       if selected == "shutdown" and config.plugins.wolconfig.activate.value and config.plugins.wolconfig.location.value == "menu":
+               return [(_("Deep Standby with WOL"), DeepStandbyWOLMain, "deep_standby_wol", 80)]
+       return []
+
+def Plugins(**kwargs):
+       if not _flagSupportWol: return []
+       l = []
+       l.append(PluginDescriptor(name=_("WakeOnLan Setup"), where=PluginDescriptor.WHERE_EXTENSIONSMENU, needsRestart=True, fnc=PluginMain))
+       l.append(PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART, fnc=SessionStartMain))
+       l.append(PluginDescriptor(where=PluginDescriptor.WHERE_MENU, fnc=MenuSelected))
+       return l
+