Merge branch 'master' of code.vuplus.com:/opt/repository/openvuplus
[vuplus_openvuplus_3.0] / meta-openvuplus / recipes-vuplus / enigma2 / enigma2 / enigma2_vuplus_transcodingsetup_xinetd.patch
1 diff --git a/lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py b/lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py
2 index 09ec093..f73da01 100755
3 --- a/lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py
4 +++ b/lib/python/Plugins/SystemPlugins/TransCodingSetup/plugin.py
5 @@ -7,7 +7,7 @@ from Components.Sources.StaticText import StaticText
6  from Plugins.Plugin import PluginDescriptor
7  from Tools.Directories import fileExists
8  from enigma import eTimer
9 -from os import system as os_system
10 +from os import system as os_system, popen as os_popen
11  from __init__ import _
12  
13  config.plugins.transcodingsetup = ConfigSubsection()
14 @@ -15,13 +15,17 @@ config.plugins.transcodingsetup.transcoding = ConfigSelection(default = "disable
15  config.plugins.transcodingsetup.port = ConfigSelection(default = "8002", choices = [ ("8001", "8001"), ("8002", "8002")] )
16  
17  error_msg ={
18 -       -1 : "File not exist - /proc/stb/encoder/enable.",
19 -       -2 : "File not exist - /etc/inetd.conf.",
20 -       -3 : "File open error - /proc/stb/encoder/enable.",
21 -       -4 : "File open error - /etc/inetd.conf.",
22 -       -5 : "Set encoder error.",
23 -       -6 : "Set port error.",
24 -       -7 : "Setting value is incorrect."
25 +       -1 : "File not exist - /proc/stb/encoder/enable",
26 +       -2 : "File not exist - /etc/inetd.conf",
27 +       -3 : "File open error - /proc/stb/encoder/enable",
28 +       -4 : "File open error - /etc/inetd.conf",
29 +       -5 : "Set encoder error",
30 +       -6 : "Set port error",
31 +       -7 : "Setting value is incorrect",
32 +       -8 : "File not exist - /etc/xinetd.d/streamproxy",
33 +       -9 : "File not exist - /etc/xinetd.d/transtreamproxy",
34 +       -10 : "File open error - /etc/xinetd.d/streamproxy",
35 +       -11 : "File open error - /etc/xinetd.d/transtreamproxy",
36  }
37  class TranscodingSetupInit:
38         def __init__(self):
39 @@ -44,8 +48,6 @@ class TranscodingSetupInit:
40                         return -7
41                 if not fileExists("/proc/stb/encoder/enable"):
42                         return -1
43 -               elif not fileExists("/etc/inetd.conf"):
44 -                       return -2
45                 if self.setEncoder(transcoding) < 0:
46                         return -5
47                 res = self.setPort(port)
48 @@ -53,11 +55,11 @@ class TranscodingSetupInit:
49                         self.setEncoder(self.transcoding_old)
50                         return res
51                 else:
52 -                       self.inetdRestart()
53 +                       self.restartDaemon()
54                 return res
55  
56         def setEncoder(self,mode = "disabled"):
57 -               print "<TranscodingSetup> set encoder : %s" % mode
58 +#              print "<TranscodingSetup> set encoder : %s" % mode
59                 mode = mode.strip(' ').strip('\n')
60                 try:
61                         fd = open("/proc/stb/encoder/enable",'r')
62 @@ -78,14 +80,29 @@ class TranscodingSetupInit:
63  #                      print "setEncoder exception error"
64                         return -1
65  
66 +       def isXinetd(self):
67 +               ps_xinetd = os_popen('ps -ef | grep xinetd | grep -v grep').read()
68 +               if ps_xinetd.strip() == '':
69 +                       return False
70 +               else:
71 +                       return True
72 +
73         def setPort(self, port = "8001"):
74 -               print "<TranscodingSetup> set port : %s" % port
75 +#              print "<TranscodingSetup> set port : %s" % port
76 +               if self.isXinetd():
77 +                       res = self.setPort_xinetd(port)
78 +               else:
79 +                       res = self.setPort_inetd(port)
80 +               return res
81 +
82 +       def setPort_inetd(self, port = "8001"):
83 +               if not fileExists("/etc/inetd.conf"):
84 +                       return -2
85                 try:
86                         fp = file('/etc/inetd.conf', 'r')
87                         datas = fp.readlines()
88                         fp.close()
89                 except:
90 -#                      print "file open error, inetd.conf!"
91                         return -4
92                 try:
93                         newdatas=""
94 @@ -112,9 +129,65 @@ class TranscodingSetupInit:
95                         return -6
96                 return 0
97  
98 -       def inetdRestart(self):
99 -               if fileExists("/etc/init.d/inetd"):
100 -                       os_system("/etc/init.d/inetd restart")
101 +       def setPort_xinetd(self, port = "8001"):
102 +               if not fileExists("/etc/xinetd.d/streamproxy") :
103 +                       return -8
104 +               if  not fileExists("/etc/xinetd.d/transtreamproxy"):
105 +                       return -9
106 +
107 +               try:
108 +                       fp_s = file('/etc/xinetd.d/streamproxy')
109 +                       data_s = fp_s.readlines()
110 +                       fp_s.close()
111 +               except:
112 +                       return -10
113 +
114 +               try:
115 +                       fp_t = file('/etc/xinetd.d/transtreamproxy')
116 +                       data_t = fp_t.readlines()
117 +                       fp_t.close()
118 +               except:
119 +                       return -11
120 +# fix xinetd port
121 +               try:
122 +                       if port == "8001":
123 +                               port_s = "8002"
124 +                               port_t = "8001"
125 +                       else:
126 +                               port_s = "8001"
127 +                               port_t = "8002"
128 +
129 +                       newdata_s=""
130 +                       for line in data_s:
131 +                               if line.find("port") != -1:
132 +                                       line = "\tport = %s\n"%port_s
133 +                               newdata_s+=line
134 +
135 +                       newdata_t=""
136 +                       for line in data_t:
137 +                               if line.find("port") != -1:
138 +                                       line = "\tport = %s\n"%port_t
139 +                               newdata_t+=line
140 +
141 +                       fd = file("/etc/xinetd.d/streamproxy",'w')
142 +                       fd.write(newdata_s)
143 +                       fd.close()
144 +
145 +                       fd = file("/etc/xinetd.d/transtreamproxy",'w')
146 +                       fd.write(newdata_t)
147 +                       fd.close()
148 +
149 +               except:
150 +                       return -6
151 +               return 0
152 +
153 +       def restartDaemon(self):
154 +               if self.isXinetd():
155 +                       if fileExists("/etc/init.d/xinetd"):
156 +                               os_system("/etc/init.d/xinetd restart")
157 +               else:           
158 +                       if fileExists("/etc/init.d/inetd"):
159 +                               os_system("/etc/init.d/inetd restart")
160  
161         def getModel(self):
162                 if fileExists("/proc/stb/info/vumodel"):
163 @@ -182,12 +255,12 @@ class TranscodingSetup(Screen,ConfigListScreen, TranscodingSetupInit):
164         def keySave(self):
165                 transcoding = config.plugins.transcodingsetup.transcoding.value
166                 port = config.plugins.transcodingsetup.port.value
167 -               print "<TranscodingSetup> Transcoding %s(port : %s)"%(transcoding, port)
168 +#              print "<TranscodingSetup> Transcoding %s(port : %s)"%(transcoding, port)
169                 ret = self.setupTranscoding(transcoding, port)
170                 if ret is not None and ret <0 :
171                         self.resetConfig()
172                         global error_msg
173 -                       self.session.openWithCallback(self.close, MessageBox, _("Failed, Encoder %s\n(%s).")%(transcoding, error_msg[ret]), MessageBox.TYPE_ERROR)
174 +                       self.session.openWithCallback(self.close, MessageBox, _("Failed, Encoder %s.\n(%s)")%(transcoding, error_msg[ret]), MessageBox.TYPE_ERROR)
175                 else:
176                         self.saveAll()
177                         if transcoding == "enabled" and port == "8001" :