TransCordingSetup : add new plugin.
authorChang.H.S <jhs@dev3>
Mon, 17 Dec 2012 10:48:54 +0000 (19:48 +0900)
committerChang.H.S <jhs@dev3>
Mon, 17 Dec 2012 11:39:00 +0000 (20:39 +0900)
configure.ac
lib/python/Plugins/SystemPlugins/Makefile.am
lib/python/Plugins/SystemPlugins/TransCordingSetup/Makefile.am [new file with mode: 0755]
lib/python/Plugins/SystemPlugins/TransCordingSetup/__init__.py [new file with mode: 0755]
lib/python/Plugins/SystemPlugins/TransCordingSetup/locale/Makefile.am [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/TransCordingSetup/locale/TransCordingSetup.pot [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/TransCordingSetup/locale/de.po [new file with mode: 0644]
lib/python/Plugins/SystemPlugins/TransCordingSetup/meta/Makefile.am [new file with mode: 0755]
lib/python/Plugins/SystemPlugins/TransCordingSetup/meta/plugin_transcordingsetup.xml [new file with mode: 0755]
lib/python/Plugins/SystemPlugins/TransCordingSetup/plugin.py [new file with mode: 0755]

index 100220c..b460135 100644 (file)
@@ -271,6 +271,9 @@ lib/python/Plugins/SystemPlugins/ZappingModeSelection/meta/Makefile
 lib/python/Plugins/SystemPlugins/DeviceManager/Makefile
 lib/python/Plugins/SystemPlugins/DeviceManager/meta/Makefile
 lib/python/Plugins/SystemPlugins/DeviceManager/locale/Makefile
 lib/python/Plugins/SystemPlugins/DeviceManager/Makefile
 lib/python/Plugins/SystemPlugins/DeviceManager/meta/Makefile
 lib/python/Plugins/SystemPlugins/DeviceManager/locale/Makefile
+lib/python/Plugins/SystemPlugins/TransCordingSetup/Makefile
+lib/python/Plugins/SystemPlugins/TransCordingSetup/meta/Makefile
+lib/python/Plugins/SystemPlugins/TransCordingSetup/locale/Makefile
 lib/python/Tools/Makefile
 lib/service/Makefile
 lib/components/Makefile
 lib/python/Tools/Makefile
 lib/service/Makefile
 lib/components/Makefile
index 32dc2ab..7f2ce31 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 \
        TempFanControl FactoryTest Fancontrol FPGAUpgrade WirelessLanSetup ManualFancontrol \
        Blindscan RemoteControlCode UI3DSetup UIPositionSetup HDMICEC LEDBrightnessSetup \
        FirmwareUpgrade CrashReport 3GModemManager WirelessAccessPoint ZappingModeSelection \
-       DeviceManager
+       DeviceManager TransCordingSetup
 
 install_PYTHON =       \
        __init__.py
 
 install_PYTHON =       \
        __init__.py
diff --git a/lib/python/Plugins/SystemPlugins/TransCordingSetup/Makefile.am b/lib/python/Plugins/SystemPlugins/TransCordingSetup/Makefile.am
new file mode 100755 (executable)
index 0000000..65217f9
--- /dev/null
@@ -0,0 +1,7 @@
+installdir = $(pkglibdir)/python/Plugins/SystemPlugins/TransCordingSetup
+
+SUBDIRS = meta locale
+
+install_PYTHON =       \
+       __init__.py \
+       plugin.py 
diff --git a/lib/python/Plugins/SystemPlugins/TransCordingSetup/__init__.py b/lib/python/Plugins/SystemPlugins/TransCordingSetup/__init__.py
new file mode 100755 (executable)
index 0000000..68c27e7
--- /dev/null
@@ -0,0 +1,22 @@
+from Components.Language import language
+from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
+import os,gettext
+
+PluginLanguageDomain = "TransCordingSetup"
+PluginLanguagePath = "SystemPlugins/TransCordingSetup/locale"
+
+def localeInit():
+       lang = language.getLanguage()[:2]
+       os.environ["LANGUAGE"] = lang
+       gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE))
+       gettext.textdomain("enigma2")
+       gettext.bindtextdomain(PluginLanguageDomain, resolveFilename(SCOPE_PLUGINS, PluginLanguagePath))
+
+def _(txt):
+       t = gettext.dgettext(PluginLanguageDomain, txt)
+       if t == txt:
+               t = gettext.gettext(txt)
+       return t
+
+localeInit()
+language.addCallback(localeInit)
diff --git a/lib/python/Plugins/SystemPlugins/TransCordingSetup/locale/Makefile.am b/lib/python/Plugins/SystemPlugins/TransCordingSetup/locale/Makefile.am
new file mode 100644 (file)
index 0000000..1093311
--- /dev/null
@@ -0,0 +1,28 @@
+PLUGIN = TransCordingSetup
+LANGS = de
+
+CATEGORY ?= "SystemPlugins"
+
+plugindir = $(libdir)/enigma2/python/Plugins/$(CATEGORY)/$(PLUGIN)
+
+LANGMO = $(LANGS:=.mo)
+LANGPO = $(LANGS:=.po)
+
+.po.mo:
+       $(MSGFMT) -o $@ $<
+
+BUILT_SOURCES = $(LANGMO)
+CLEANFILES = $(LANGMO) $(PLUGIN)-py.pot $(PLUGIN)-xml.pot $(PLUGIN).pot
+
+dist-hook: $(LANGPO)
+
+install-data-local: $(LANGMO)
+       for lang in $(LANGS); do \
+               $(mkinstalldirs) $(DESTDIR)$(plugindir)/locale/$$lang/LC_MESSAGES; \
+               $(INSTALL_DATA) $$lang.mo $(DESTDIR)$(plugindir)/locale/$$lang/LC_MESSAGES/$(PLUGIN).mo; \
+       done
+
+uninstall-local:
+       for lang in $(LANGS); do \
+               $(RM) $(DESTDIR)$(plugindir)/locale/$$lang/LC_MESSAGES/$(PLUGIN).mo; \
+       done
diff --git a/lib/python/Plugins/SystemPlugins/TransCordingSetup/locale/TransCordingSetup.pot b/lib/python/Plugins/SystemPlugins/TransCordingSetup/locale/TransCordingSetup.pot
new file mode 100644 (file)
index 0000000..5035042
--- /dev/null
@@ -0,0 +1,59 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR ORGANIZATION
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2012-12-17 18:07+KST\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: pygettext.py 1.5\n"
+
+
+#: ../plugin.py:11
+msgid "disabled"
+msgstr ""
+
+#: ../plugin.py:11
+msgid "enabled"
+msgstr ""
+
+#: ../plugin.py:129
+msgid "Cancel"
+msgstr ""
+
+#: ../plugin.py:130
+msgid "Ok"
+msgstr ""
+
+#: ../plugin.py:131
+msgid "%s"
+msgstr ""
+
+#: ../plugin.py:136
+msgid "Transcording"
+msgstr ""
+
+#: ../plugin.py:137
+msgid "Port"
+msgstr ""
+
+#: ../plugin.py:149
+msgid ""
+"SET FAILED.\n"
+"(%s)."
+msgstr ""
+
+#: ../plugin.py:152
+msgid "SET SUCCESSED."
+msgstr ""
+
+#: ../plugin.py:166
+msgid "TranscordingSetup"
+msgstr ""
+
diff --git a/lib/python/Plugins/SystemPlugins/TransCordingSetup/locale/de.po b/lib/python/Plugins/SystemPlugins/TransCordingSetup/locale/de.po
new file mode 100644 (file)
index 0000000..5035042
--- /dev/null
@@ -0,0 +1,59 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR ORGANIZATION
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2012-12-17 18:07+KST\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Generated-By: pygettext.py 1.5\n"
+
+
+#: ../plugin.py:11
+msgid "disabled"
+msgstr ""
+
+#: ../plugin.py:11
+msgid "enabled"
+msgstr ""
+
+#: ../plugin.py:129
+msgid "Cancel"
+msgstr ""
+
+#: ../plugin.py:130
+msgid "Ok"
+msgstr ""
+
+#: ../plugin.py:131
+msgid "%s"
+msgstr ""
+
+#: ../plugin.py:136
+msgid "Transcording"
+msgstr ""
+
+#: ../plugin.py:137
+msgid "Port"
+msgstr ""
+
+#: ../plugin.py:149
+msgid ""
+"SET FAILED.\n"
+"(%s)."
+msgstr ""
+
+#: ../plugin.py:152
+msgid "SET SUCCESSED."
+msgstr ""
+
+#: ../plugin.py:166
+msgid "TranscordingSetup"
+msgstr ""
+
diff --git a/lib/python/Plugins/SystemPlugins/TransCordingSetup/meta/Makefile.am b/lib/python/Plugins/SystemPlugins/TransCordingSetup/meta/Makefile.am
new file mode 100755 (executable)
index 0000000..7217e77
--- /dev/null
@@ -0,0 +1,3 @@
+installdir = $(datadir)/meta
+
+dist_install_DATA = plugin_transcordingsetup.xml
diff --git a/lib/python/Plugins/SystemPlugins/TransCordingSetup/meta/plugin_transcordingsetup.xml b/lib/python/Plugins/SystemPlugins/TransCordingSetup/meta/plugin_transcordingsetup.xml
new file mode 100755 (executable)
index 0000000..19e3627
--- /dev/null
@@ -0,0 +1,16 @@
+<default>
+         <prerequisites>
+                    <tag type="System" />
+         </prerequisites>
+          <info>
+                    <author>hschang</author>
+                    <name>TranscordingSetup</name>
+                    <packagename>enigma2-plugin-systemplugins-transcordingsetup</packagename>
+                    <shortdescription>Setup transcording of your VU+</shortdescription>
+                    <description>Setup transcording of your VU+</description>
+          </info>
+
+         <files type="package"> <!-- without version, without .ipk -->
+               <file type="package" name="enigma2-plugin-systemplugins-transcordingsetup" />
+       </files>
+</default>
diff --git a/lib/python/Plugins/SystemPlugins/TransCordingSetup/plugin.py b/lib/python/Plugins/SystemPlugins/TransCordingSetup/plugin.py
new file mode 100755 (executable)
index 0000000..821d2db
--- /dev/null
@@ -0,0 +1,229 @@
+from Screens.Screen import Screen
+from Components.ConfigList import ConfigListScreen
+from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection
+from Components.ActionMap import ActionMap
+from Screens.MessageBox import MessageBox
+from Components.Sources.StaticText import StaticText
+from Plugins.Plugin import PluginDescriptor
+from Tools.Directories import fileExists
+from enigma import eTimer
+from os import system as os_system
+from __init__ import _
+
+config.plugins.transcordingsetup = ConfigSubsection()
+config.plugins.transcordingsetup.transcording = ConfigSelection(default = "disabled", choices = [ ("enabled", _("enabled")), ("disabled", _("disabled"))] )
+config.plugins.transcordingsetup.port = ConfigSelection(default = "8002", choices = [ ("8001", "8001"), ("8002", "8002")] )
+
+error_msg ={
+       -1 : "File not exist - /proc/stb/encoder/enable.",
+       -2 : "File not exist - /etc/inetd.conf.",
+       -3 : "File open error - /proc/stb/encoder/enable.",
+       -4 : "File open error - /etc/inetd.conf.",
+       -5 : "Set encoder error.",
+       -6 : "Set port error.",
+       -7 : "Setting value is incorrect."
+}
+class TranscordingSetupInit:
+       def __init__(self):
+               self.transcording_value = config.plugins.transcordingsetup.transcording.value
+               if self.transcording_value == "disabled":
+                       self.port_value = "8002"
+               else:
+                       self.port_value = config.plugins.transcordingsetup.port.value
+               self.transcording_old = config.plugins.transcordingsetup.transcording.value
+               ret = self.setTranscording(self.transcording_value, self.port_value)
+               if ret is not None and ret < 0:
+                       print "[TranscordingSetup] setup failed!(%s, %s)"%(self.transcording_value, self.port_value)
+
+       def setTranscording(self, transcording, port):
+               if not self.getModel():
+                       print "This plugin is only supported for solo2/duo2."
+                       return -8
+               if transcording not in ["enabled","disabled"] or port not in ["8001","8002"]:
+                       print "Input arg error.."
+                       return -7
+               if not fileExists("/proc/stb/encoder/enable"):
+                       return -1
+               elif not fileExists("/etc/inetd.conf"):
+                       return -2
+               if self.setEncoder(transcording) < 0:
+                       return -5
+               res = self.setPort(port)
+               if res < 0:
+                       self.setEncoder(self.transcording_old)
+                       return res
+               else:
+                       self.inetdRestart()
+               return res
+
+       def setEncoder(self,mode = "disabled"):
+               print "<TranscordingSetup> set encoder : %s" % mode
+               mode = mode.strip(' ').strip('\n')
+               try:
+                       fd = open("/proc/stb/encoder/enable",'r')
+                       self.transcording_old = fd.read()
+                       fd.close()
+                       fd = open("/proc/stb/encoder/enable",'w')
+                       fd.write(mode)
+                       fd.close()
+                       print "-->",mode
+                       fd = open("/proc/stb/encoder/enable",'r')
+                       encoder_enable = fd.read().strip(' ').strip('\n')
+                       fd.close()
+                       print "<--",encoder_enable
+                       if encoder_enable == mode:
+                               return 0
+                       else:
+                               print "can not setting.."
+                               return -1
+               except:
+                       print "setEncoder exception error"
+                       return -1
+
+       def setPort(self, port = "8001"):
+               print "<TranscordingSetup> set port : %s" % port
+               try:
+                       fp = file('/etc/inetd.conf', 'r')
+                       datas = fp.readlines()
+                       fp.close()
+               except:
+                       print "file open error, inetd.conf!"
+                       return -4
+               try:
+                       newdatas=""
+                       s_port = ""
+                       if port == "8001":
+                               s_port = "8002"
+                       else:
+                               s_port = "8001"
+                       for line in datas:
+                               if line.find("transtreamproxy") != -1:
+                                       p=line.replace('\t',' ').find(' ')
+                                       line = port+line[p:]
+                               elif line.find("streamproxy") != -1:
+                                       p=line.replace('\t',' ').find(' ')
+                                       line = s_port+line[p:]
+                               newdatas+=line
+
+                       if newdatas.find("transtreamproxy") == -1:
+                               newdatas+=port+'\t'+'stream'+'\t'+'tcp'+'\t'+'nowait'+'\t'+'root'+'\t'+'/usr/bin/transtreamproxy'+'\t'+'transtreamproxy\n'
+                       fd = file("/etc/inetd.conf",'w')
+                       fd.write(newdatas)
+                       fd.close()
+               except:
+                       return -6
+               return 0
+
+       def inetdRestart(self):
+               if fileExists("/etc/init.d/inetd"):
+                       os_system("/etc/init.d/inetd restart")
+
+       def getModel(self):
+               if fileExists("/proc/stb/info/vumodel"):
+                       vumodel = open("/proc/stb/info/vumodel")
+                       info=vumodel.read().strip()
+                       vumodel.close()
+                       if info in ["solo2", "duo2"]:
+                               return True
+                       else:
+                               return False
+               else:
+                       return False
+
+class TranscordingSetup(Screen,ConfigListScreen, TranscordingSetupInit):
+       skin =  """
+               <screen position="center,center" size="560,270" title="Transcording Setup" >
+                       <ePixmap pixmap="skin_default/buttons/red.png" position="110,10" size="140,40" alphatest="on" />
+                       <ePixmap pixmap="skin_default/buttons/green.png" position="310,10" size="140,40" alphatest="on" />
+                       <widget source="key_red" render="Label" position="110,10" 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="310,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
+                       <widget name="config" zPosition="2" position="5,70" size="550,70" scrollbarMode="showOnDemand" transparent="1" />
+                       <widget source="text" render="Label" position="20,140" size="520,130" font="Regular;18" halign="center" valign="center" />
+               </screen>
+               """
+
+       def __init__(self,session):
+               Screen.__init__(self,session)
+               self.session = session
+               self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
+               {
+                       "ok": self.keySave,
+                       "cancel": self.keyCancel,
+                       "red": self.keyCancel,
+                       "green": self.keySave,
+               }, -2)
+               self.list = []
+               ConfigListScreen.__init__(self, self.list,session = self.session)
+               TEXT = "Tanscoding can be started when there is no corresponding channel recordings."
+               TEXT += "\nWhen transcoding, both PIP and analog video outputs are disabled."
+               self["key_red"] = StaticText(_("Cancel"))
+               self["key_green"] = StaticText(_("Ok"))
+               self["text"] = StaticText(_("%s")%TEXT)
+               self.createSetup()
+               self.onLayoutFinish.append(self.checkModel)
+               self.checkModelTimer = eTimer()
+               self.checkModelTimer.callback.append(self.invalidmodel)
+
+       def checkModel(self):
+               if not self.getModel():
+                       self.checkModelTimer.start(1000,True)
+
+       def invalidmodel(self):
+                       self.session.openWithCallback(self.close, MessageBox, _("This Plugin is available on SOLO2/DUO2"), MessageBox.TYPE_ERROR)
+
+       def createSetup(self):
+               self.list = []
+               self.transcording = getConfigListEntry(_("Transcording"), config.plugins.transcordingsetup.transcording)
+               self.port = getConfigListEntry(_("Port"), config.plugins.transcordingsetup.port)
+               self.list.append( self.transcording )
+               if config.plugins.transcordingsetup.transcording.value == "enabled":
+                       self.list.append( self.port )
+               self["config"].list = self.list
+               self["config"].l.setList(self.list)
+
+       def keySave(self):
+               transcording = config.plugins.transcordingsetup.transcording.value
+               port = config.plugins.transcordingsetup.port.value
+               print "<ZappingModeSelection> Transcording %s(port : %s)"%(transcording, port)
+               ret = self.setupTranscording(transcording, port)
+               if ret is not None and ret <0 :
+                       self.resetConfig()
+                       global error_msg
+                       self.session.openWithCallback(self.close, MessageBox, _("Failed, Encoder %s\n(%s).")%(transcording, error_msg[ret]), MessageBox.TYPE_ERROR)
+               else:
+                       self.saveAll()
+                       if transcording == "enabled" and port == "8001" :
+                               text = "PC Streaming is replaced with mobile streaming."
+                               self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.\n%s")%(transcording,text), MessageBox.TYPE_INFO)
+                       else:
+                               self.session.openWithCallback(self.close, MessageBox, _("OK. Encoder %s.")%transcording, MessageBox.TYPE_INFO)
+                       self.close()
+
+       def resetConfig(self):
+               for x in self["config"].list:
+                       x[1].cancel()
+
+       def setupTranscording(self, transcording = None, port = None):
+               if transcording == "disabled":
+                       config.plugins.transcordingsetup.port.value = "8002"
+                       port = "8002"
+               return self.setTranscording(transcording, port)
+
+       def keyLeft(self):
+               ConfigListScreen.keyLeft(self)
+               if self["config"].getCurrent() == self.transcording:
+                       self.createSetup()
+
+       def keyRight(self):
+               ConfigListScreen.keyRight(self)
+               if self["config"].getCurrent() == self.transcording:
+                       self.createSetup()
+
+def main(session, **kwargs):
+       session.open(TranscordingSetup)
+
+def Plugins(**kwargs):
+       return [PluginDescriptor(name=_("TranscordingSetup"), description="Transcording Setup", where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=main)]
+
+transcordingsetupinit = TranscordingSetupInit()
+