source: ipk/source.sh4/swapepg_crossepg/var/swap/extensions/CrossEPG/crossepg_setup.py@ 12495

Last change on this file since 12495 was 12090, checked in by madie, 14 years ago

[ipk] update crossepg

File size: 12.2 KB
Line 
1from enigma import getDesktop
2
3from Screens.Screen import Screen
4from Screens.MessageBox import MessageBox
5
6from Components.config import KEY_LEFT, KEY_RIGHT, KEY_HOME, KEY_END, KEY_0, ConfigYesNo, ConfigSelection, ConfigClock, config, configfile
7from Components.ConfigList import ConfigList
8from Components.Button import Button
9from Components.Label import Label
10from Components.Harddisk import harddiskmanager
11from Components.PluginComponent import plugins
12from Components.ActionMap import NumberActionMap
13
14from Tools.Directories import resolveFilename, SCOPE_PLUGINS
15
16from Plugins.Plugin import PluginDescriptor
17
18from crossepglib import *
19from crossepg_locale import _
20from crossepg_auto import crossepg_auto
21
22from time import *
23
24import os
25
26class CrossEPG_Setup(Screen):
27 def __init__(self, session):
28 if (getDesktop(0).size().width() < 800):
29 skin = "%s/skins/setup_sd.xml" % (os.path.dirname(sys.modules[__name__].__file__))
30 else:
31 skin = "%s/skins/setup_hd.xml" % (os.path.dirname(sys.modules[__name__].__file__))
32 f = open(skin, "r")
33 self.skin = f.read()
34 f.close()
35 Screen.__init__(self, session)
36
37 patchtype = getEPGPatchType()
38 if patchtype == 0 or patchtype == 1 or patchtype == 3:
39 self.fastpatch = True
40 else:
41 self.fastpatch = False
42
43 self.session = session
44
45 self.config = CrossEPG_Config()
46 self.config.load()
47
48 self.lamedbs = self.config.getAllLamedbs()
49
50 self.lamedbs_desc = []
51 self.mountpoint = []
52 self.mountdescription = []
53 self.automatictype = []
54
55 self.show_extension = self.config.show_extension
56 self.show_plugin = self.config.show_plugin
57 self.show_force_reload_as_plugin = self.config.show_force_reload_as_plugin
58
59 # make devices entries
60 if self.config.isQBOXHD():
61 self.mountdescription.append(_("Internal flash"))
62 self.mountpoint.append("/var/crossepg/data")
63
64 for partition in harddiskmanager.getMountedPartitions():
65 if (partition.mountpoint != '/') and (partition.mountpoint != '') and self.isMountedInRW(partition.mountpoint):
66 self.mountpoint.append(partition.mountpoint + "/crossepg")
67
68 if partition.description != '':
69 self.mountdescription.append(partition.description)
70 else:
71 self.mountdescription.append(partition.mountpoint)
72
73 if not self.config.isQBOXHD(): # for other decoders we add internal flash as last entry (it's unsuggested)
74 self.mountdescription.append(_("Internal flash (unsuggested)"))
75 self.mountpoint.append(self.config.home_directory + "/data")
76
77 # make lamedb entries
78 for lamedb in self.lamedbs:
79 if lamedb == "lamedb":
80 self.lamedbs_desc.append(_("main lamedb"))
81 else:
82 self.lamedbs_desc.append(lamedb.replace("lamedb.", "").replace(".", " "))
83
84 # make automatic type entries
85 self.automatictype.append(_("disabled"))
86 self.automatictype.append(_("once a day"))
87 self.automatictype.append(_("every hour (only in standby)"))
88
89 self.list = []
90 self["config"] = ConfigList(self.list, session = self.session)
91 self["config"].onSelectionChanged.append(self.setInfo)
92 self["information"] = Label("")
93 self["key_red"] = Button(_("Back"))
94 self["key_green"] = Button()
95 self["key_yellow"] = Button()
96 self["key_blue"] = Button("")
97 self["config_actions"] = NumberActionMap(["SetupActions", "InputAsciiActions", "KeyboardInputActions", "ColorActions"],
98 {
99 "red": self.quit,
100 "cancel": self.quit,
101 "left": self.keyLeft,
102 "right": self.keyRight,
103 "home": self.keyHome,
104 "end": self.keyEnd,
105 "1": self.keyNumberGlobal,
106 "2": self.keyNumberGlobal,
107 "3": self.keyNumberGlobal,
108 "4": self.keyNumberGlobal,
109 "5": self.keyNumberGlobal,
110 "6": self.keyNumberGlobal,
111 "7": self.keyNumberGlobal,
112 "8": self.keyNumberGlobal,
113 "9": self.keyNumberGlobal,
114 "0": self.keyNumberGlobal
115 }, -1) # to prevent left/right overriding the listbox
116
117 self.makeList()
118
119 def isMountedInRW(self, path):
120 testfile = path + "/tmp-rw-test"
121 os.system("touch " + testfile)
122 if os.path.exists(testfile):
123 os.system("rm -f " + testfile)
124 return True
125 return False
126
127 def showWarning(self):
128 self.session.open(MessageBox, _("PLEASE READ!\nNo disk found. An hard drive or an usb pen is HARDLY SUGGESTED. If you still want use your internal flash pay attention to:\n(1) If you don't have enough free space your box may completely block and you need to flash it again\n(2) Many write operations on your internal flash may damage your flash memory"), type = MessageBox.TYPE_ERROR)
129
130 def keyLeft(self):
131 self["config"].handleKey(KEY_LEFT)
132 self.update()
133 #self.setInfo()
134
135 def keyRight(self):
136 self["config"].handleKey(KEY_RIGHT)
137 self.update()
138 #self.setInfo()
139
140 def keyHome(self):
141 self["config"].handleKey(KEY_HOME)
142 self.update()
143 #self.setInfo()
144
145 def keyEnd(self):
146 self["config"].handleKey(KEY_END)
147 self.update()
148 #self.setInfo()
149
150 def keyNumberGlobal(self, number):
151 self["config"].handleKey(KEY_0 + number)
152 self.update()
153 #self.setInfo()
154
155 def makeList(self):
156 self.list = []
157
158 device_default = None
159 i = 0
160 for mountpoint in self.mountpoint:
161 if mountpoint == self.config.db_root:
162 device_default = self.mountdescription[i]
163 i += 1
164
165 # default device is really important... if miss a default we force it on first entry and update now the main config
166 if device_default == None:
167 self.config.db_root = self.mountpoint[0]
168 device_default = self.mountdescription[0]
169
170 lamedb_default = _("main lamedb")
171 if self.config.lamedb != "lamedb":
172 lamedb_default = self.config.lamedb.replace("lamedb.", "").replace(".", " ")
173
174 scheduled_default = None
175 if self.config.download_standby_enabled:
176 scheduled_default = _("every hour (only in standby)")
177 elif self.config.download_daily_enabled:
178 scheduled_default = _("once a day")
179 else:
180 scheduled_default = _("disabled")
181
182 self.list.append((_("Storage device"), ConfigSelection(self.mountdescription, device_default)))
183 if len(self.lamedbs_desc) > 1:
184 self.list.append((_("Preferred lamedb"), ConfigSelection(self.lamedbs_desc, lamedb_default)))
185
186 self.list.append((_("Enable csv import"), ConfigYesNo(self.config.csv_import_enabled > 0)))
187 self.list.append((_("Force epg reload on boot"), ConfigYesNo(self.config.force_load_on_boot > 0)))
188 self.list.append((_("Download on tune"), ConfigYesNo(self.config.download_tune_enabled > 0)))
189 self.list.append((_("Scheduled download"), ConfigSelection(self.automatictype, scheduled_default)))
190
191 if self.config.download_daily_enabled:
192 ttime = localtime()
193 ltime = (ttime[0], ttime[1], ttime[2], self.config.download_daily_hours, self.config.download_daily_minutes, ttime[5], ttime[6], ttime[7], ttime[8])
194 self.list.append((_("Scheduled download at"), ConfigClock(mktime(ltime))))
195
196 if not self.fastpatch:
197 self.list.append((_("Reboot after a scheduled download"), ConfigYesNo(self.config.download_daily_reboot > 0)))
198 self.list.append((_("Reboot after a manual download"), ConfigYesNo(self.config.download_manual_reboot > 0)))
199 self.list.append((_("Show as plugin"), ConfigYesNo(self.config.show_plugin > 0)))
200 self.list.append((_("Show as extension"), ConfigYesNo(self.config.show_extension > 0)))
201 self.list.append((_("Show 'Force reload' as plugin"), ConfigYesNo(self.config.show_force_reload_as_plugin > 0)))
202
203 self["config"].setList(self.list)
204 self.setInfo()
205
206 def update(self):
207 redraw = False
208 self.config.db_root = self.mountpoint[self.list[0][1].getIndex()]
209
210 i = 1
211 if len(self.lamedbs_desc) > 1:
212 self.config.lamedb = self.lamedbs[self.list[i][1].getIndex()]
213 i += 1
214
215 self.config.csv_import_enabled = int(self.list[i][1].getValue())
216 self.config.force_load_on_boot = int(self.list[i+1][1].getValue())
217 self.config.download_tune_enabled = int(self.list[i+2][1].getValue())
218
219 dailycache = self.config.download_daily_enabled
220 standbycache = self.config.download_standby_enabled
221 if self.list[i+3][1].getIndex() == 0:
222 self.config.download_daily_enabled = 0
223 self.config.download_standby_enabled = 0
224 elif self.list[i+3][1].getIndex() == 1:
225 self.config.download_daily_enabled = 1
226 self.config.download_standby_enabled = 0
227 else:
228 self.config.download_daily_enabled = 0
229 self.config.download_standby_enabled = 1
230
231 if dailycache != self.config.download_daily_enabled or standbycache != self.config.download_standby_enabled:
232 redraw = True
233
234 i += 4
235 if dailycache:
236 self.config.download_daily_hours = self.list[i][1].getValue()[0]
237 self.config.download_daily_minutes = self.list[i][1].getValue()[1]
238 i += 1
239
240 if not self.fastpatch:
241 self.config.download_daily_reboot = int(self.list[i][1].getValue())
242 self.config.download_manual_reboot = int(self.list[i+1][1].getValue())
243 i += 2
244
245 self.config.show_plugin = int(self.list[i][1].getValue())
246 self.config.show_extension = int(self.list[i+1][1].getValue())
247 self.config.show_force_reload_as_plugin = int(self.list[i+2][1].getValue())
248
249 if redraw:
250 self.makeList()
251
252 def setInfo(self):
253 index = self["config"].getCurrentIndex()
254 if len(self.lamedbs_desc) <= 1 and index > 0:
255 index += 1
256 if self.config.download_daily_enabled == 0 and index > 5:
257 index += 1
258 if self.fastpatch and index > 6:
259 index += 2
260
261 if index == 0:
262 self["information"].setText(_("Drive where you save data.\nThe drive MUST be mounted in rw. If you can't see your device here probably is mounted as read only or autofs handle it only in read only mode. In case of mount it manually and try again"))
263 elif index == 1:
264 self["information"].setText(_("Lamedb used for epg.dat conversion.\nThis option doesn't work with crossepg patch v2"))
265 elif index == 2:
266 self["information"].setText(_("Import *.csv and *.bin from %s/import or %s/import\n(*.bin are binaries with a csv as stdout)") % (self.config.db_root, self.config.home_directory))
267 elif index == 3:
268 self["information"].setText(_("Reload epg at every boot.\nNormally it's not necessary but recover epg after an enigma2 crash"))
269 elif index == 4:
270 self["information"].setText(_("Only for opentv providers.\nIf you zap on channel used from a provider it download the epg in background"))
271 elif index == 5:
272 if self.config.download_standby_enabled:
273 self["information"].setText(_("When the decoder is in standby opentv providers will be automatically downloaded every hour.\nXMLTV providers will be always downloaded only once a day"))
274 elif self.config.download_daily_enabled:
275 self["information"].setText(_("Download epg once a day"))
276 else:
277 self["information"].setText(_("Scheduled download disabled"))
278 elif index == 6:
279 self["information"].setText(_("Time for scheduled daily download"))
280 elif index == 7:
281 self["information"].setText(_("Automatically reboot the decoder after a scheduled download"))
282 elif index == 8:
283 self["information"].setText(_("Automatically reboot the decoder after a manual download"))
284 elif index == 9:
285 self["information"].setText(_("Show crossepg in plugin menu"))
286 elif index == 10:
287 self["information"].setText(_("Show crossepg in extensions menu"))
288
289 def quit(self):
290 self.config.last_full_download_timestamp = 0
291 self.config.last_partial_download_timestamp = 0
292 self.config.configured = 1
293 self.config.save()
294 try:
295 if self.config.db_root[-8:] == "crossepg":
296 config.misc.epgcache_filename.setValue(self.config.db_root[:-9] + "/epg.dat")
297 else:
298 config.misc.epgcache_filename.setValue(self.config.db_root + "/epg.dat")
299 config.misc.epgcache_filename.callNotifiersOnSaveAndCancel = True
300 config.misc.epgcache_filename.save()
301 configfile.save()
302 except Exception, e:
303 print "custom epgcache filename not supported by current enigma2 version"
304
305 if getEPGPatchType() == -1:
306 # exec crossepg_prepare_pre_start for unpatched images
307 os.system(self.config.home_directory + "/crossepg_prepare_pre_start.sh")
308
309 if self.show_extension != self.config.show_extension or self.show_plugin != self.config.show_plugin:
310 for plugin in plugins.getPlugins(PluginDescriptor.WHERE_PLUGINMENU):
311 if plugin.name == "CrossEPG Downloader":
312 plugins.removePlugin(plugin)
313
314 for plugin in plugins.getPlugins(PluginDescriptor.WHERE_EXTENSIONSMENU):
315 if plugin.name == "CrossEPG Downloader":
316 plugins.removePlugin(plugin)
317
318 plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
319
320 crossepg_auto.forcePoll()
321
322 if self.config.db_root == self.config.home_directory + "/data" and not self.config.isQBOXHD():
323 self.showWarning()
324
325 self.close()
326
Note: See TracBrowser for help on using the repository browser.