update ru.po
[openblackhole/openblackhole-enigma2.git] / mytest.py
1 import sys, os
2 if os.path.isfile("/usr/lib/enigma2/python/enigma.zip"):
3         sys.path.append("/usr/lib/enigma2/python/enigma.zip")
4
5 from Tools.Profile import profile, profile_final
6 profile("PYTHON_START")
7
8 import Tools.RedirectOutput
9 import enigma
10 import eConsoleImpl
11 import eBaseImpl
12 enigma.eTimer = eBaseImpl.eTimer
13 enigma.eSocketNotifier = eBaseImpl.eSocketNotifier
14 enigma.eConsoleAppContainer = eConsoleImpl.eConsoleAppContainer
15
16 from traceback import print_exc
17 profile("SimpleSummary")
18 from Screens import InfoBar
19 from Screens.SimpleSummary import SimpleSummary
20
21 from sys import stdout, exc_info
22
23 profile("Bouquets")
24 from Components.config import config, configfile, ConfigText, ConfigYesNo, ConfigInteger, NoSave
25 config.misc.load_unlinked_userbouquets = ConfigYesNo(default=True)
26 def setLoadUnlinkedUserbouquets(configElement):
27         enigma.eDVBDB.getInstance().setLoadUnlinkedUserbouquets(configElement.value)
28 config.misc.load_unlinked_userbouquets.addNotifier(setLoadUnlinkedUserbouquets)
29 enigma.eDVBDB.getInstance().reloadBouquets()
30
31 profile("ParentalControl")
32 import Components.ParentalControl
33 Components.ParentalControl.InitParentalControl()
34
35 profile("LOAD:Navigation")
36 from Navigation import Navigation
37
38 profile("LOAD:skin")
39 from skin import readSkin
40
41 profile("LOAD:Tools")
42 from Tools.Directories import InitFallbackFiles, resolveFilename, SCOPE_PLUGINS, SCOPE_CURRENT_SKIN
43 InitFallbackFiles()
44
45 profile("config.misc")
46 config.misc.radiopic = ConfigText(default = resolveFilename(SCOPE_CURRENT_SKIN, "radio.mvi"))
47 config.misc.blackradiopic = ConfigText(default = resolveFilename(SCOPE_CURRENT_SKIN, "black.mvi"))
48 config.misc.useTransponderTime = ConfigYesNo(default=True)
49 config.misc.startCounter = ConfigInteger(default=0) # number of e2 starts...
50 config.misc.standbyCounter = NoSave(ConfigInteger(default=0)) # number of standby
51 config.misc.DeepStandby = NoSave(ConfigYesNo(default=False)) # detect deepstandby
52 config.misc.RestartUI = ConfigYesNo(default=False) # detect user interface restart
53 config.misc.prev_wakeup_time = ConfigInteger(default=0)
54 #config.misc.prev_wakeup_time_type is only valid when wakeup_time is not 0
55 config.misc.prev_wakeup_time_type = ConfigInteger(default=0)
56 # 0 = RecordTimer, 1 = ZapTimer, 2 = Plugins, 3 = WakeupTimer
57 config.misc.epgcache_filename = ConfigText(default = "/hdd/epg.dat")
58
59 def setEPGCachePath(configElement):
60         enigma.eEPGCache.getInstance().setCacheFile(configElement.value)
61
62 #demo code for use of standby enter leave callbacks
63 #def leaveStandby():
64 #       print "!!!!!!!!!!!!!!!!!leave standby"
65
66 #def standbyCountChanged(configElement):
67 #       print "!!!!!!!!!!!!!!!!!enter standby num", configElement.value
68 #       from Screens.Standby import inStandby
69 #       inStandby.onClose.append(leaveStandby)
70
71 #config.misc.standbyCounter.addNotifier(standbyCountChanged, initial_call = False)
72 ####################################################
73
74 def useTransponderTimeChanged(configElement):
75         enigma.eDVBLocalTimeHandler.getInstance().setUseDVBTime(configElement.value)
76 config.misc.useTransponderTime.addNotifier(useTransponderTimeChanged)
77
78 profile("Twisted")
79 try:
80         import twisted.python.runtime
81
82         import e2reactor
83         e2reactor.install()
84
85         from twisted.internet import reactor
86
87         def runReactor():
88                 reactor.run(installSignalHandlers=False)
89 except ImportError:
90         print "twisted not available"
91         def runReactor():
92                 enigma.runMainloop()
93
94 profile("LOAD:Plugin")
95
96 # initialize autorun plugins and plugin menu entries
97 from Components.PluginComponent import plugins
98
99 profile("LOAD:Wizard")
100 from Screens.Wizard import wizardManager
101 from Screens.StartWizard import *
102 import Screens.Rc
103 from Tools.BoundFunction import boundFunction
104 from Plugins.Plugin import PluginDescriptor
105
106 profile("misc")
107 had = dict()
108
109 def dump(dir, p = ""):
110         if isinstance(dir, dict):
111                 for (entry, val) in dir.items():
112                         dump(val, p + "(dict)/" + entry)
113         if hasattr(dir, "__dict__"):
114                 for name, value in dir.__dict__.items():
115                         if not had.has_key(str(value)):
116                                 had[str(value)] = 1
117                                 dump(value, p + "/" + str(name))
118                         else:
119                                 print p + "/" + str(name) + ":" + str(dir.__class__) + "(cycle)"
120         else:
121                 print p + ":" + str(dir)
122
123 # + ":" + str(dir.__class__)
124
125 # display
126
127 profile("LOAD:ScreenGlobals")
128 from Screens.Globals import Globals
129 from Screens.SessionGlobals import SessionGlobals
130 from Screens.Screen import Screen
131
132 profile("Screen")
133 Screen.global_screen = Globals()
134
135 # Session.open:
136 # * push current active dialog ('current_dialog') onto stack
137 # * call execEnd for this dialog
138 #   * clear in_exec flag
139 #   * hide screen
140 # * instantiate new dialog into 'current_dialog'
141 #   * create screens, components
142 #   * read, apply skin
143 #   * create GUI for screen
144 # * call execBegin for new dialog
145 #   * set in_exec
146 #   * show gui screen
147 #   * call components' / screen's onExecBegin
148 # ... screen is active, until it calls 'close'...
149 # Session.close:
150 # * assert in_exec
151 # * save return value
152 # * start deferred close handler ('onClose')
153 # * execEnd
154 #   * clear in_exec
155 #   * hide screen
156 # .. a moment later:
157 # Session.doClose:
158 # * destroy screen
159
160 class Session:
161         def __init__(self, desktop = None, summary_desktop = None, navigation = None):
162                 self.desktop = desktop
163                 self.summary_desktop = summary_desktop
164                 self.nav = navigation
165                 self.delay_timer = enigma.eTimer()
166                 self.delay_timer.callback.append(self.processDelay)
167
168                 self.current_dialog = None
169
170                 self.dialog_stack = [ ]
171                 self.summary_stack = [ ]
172                 self.summary = None
173
174                 self.in_exec = False
175
176                 self.screen = SessionGlobals(self)
177
178                 for p in plugins.getPlugins(PluginDescriptor.WHERE_SESSIONSTART):
179                         try:
180                                 p(reason=0, session=self)
181                         except:
182                                 print "Plugin raised exception at WHERE_SESSIONSTART"
183                                 import traceback
184                                 traceback.print_exc()
185
186         def processDelay(self):
187                 callback = self.current_dialog.callback
188
189                 retval = self.current_dialog.returnValue
190
191                 if self.current_dialog.isTmp:
192                         self.current_dialog.doClose()
193 #                       dump(self.current_dialog)
194                         del self.current_dialog
195                 else:
196                         del self.current_dialog.callback
197
198                 self.popCurrent()
199                 if callback is not None:
200                         callback(*retval)
201
202         def execBegin(self, first=True, do_show = True):
203                 assert not self.in_exec
204                 self.in_exec = True
205                 c = self.current_dialog
206
207                 # when this is an execbegin after a execend of a "higher" dialog,
208                 # popSummary already did the right thing.
209                 if first:
210                         self.instantiateSummaryDialog(c)
211
212                 c.saveKeyboardMode()
213                 c.execBegin()
214
215                 # when execBegin opened a new dialog, don't bother showing the old one.
216                 if c == self.current_dialog and do_show:
217                         c.show()
218
219         def execEnd(self, last=True):
220                 assert self.in_exec
221                 self.in_exec = False
222
223                 self.current_dialog.execEnd()
224                 self.current_dialog.restoreKeyboardMode()
225                 self.current_dialog.hide()
226
227                 if last and self.summary is not None:
228                         self.current_dialog.removeSummary(self.summary)
229                         self.popSummary()
230
231         def instantiateDialog(self, screen, *arguments, **kwargs):
232                 return self.doInstantiateDialog(screen, arguments, kwargs, self.desktop)
233
234         def deleteDialog(self, screen):
235                 screen.hide()
236                 screen.doClose()
237
238         def instantiateSummaryDialog(self, screen, **kwargs):
239                 if self.summary_desktop is not None:
240                         self.pushSummary()
241                         summary = screen.createSummary() or SimpleSummary
242                         arguments = (screen,)
243                         self.summary = self.doInstantiateDialog(summary, arguments, kwargs, self.summary_desktop)
244                         self.summary.show()
245                         screen.addSummary(self.summary)
246
247         def doInstantiateDialog(self, screen, arguments, kwargs, desktop):
248                 # create dialog
249                 dlg = screen(self, *arguments, **kwargs)
250                 if dlg is None:
251                         return
252                 # read skin data
253                 readSkin(dlg, None, dlg.skinName, desktop)
254                 # create GUI view of this dialog
255                 dlg.setDesktop(desktop)
256                 dlg.applySkin()
257                 return dlg
258
259         def pushCurrent(self):
260                 if self.current_dialog is not None:
261                         self.dialog_stack.append((self.current_dialog, self.current_dialog.shown))
262                         self.execEnd(last=False)
263
264         def popCurrent(self):
265                 if self.dialog_stack:
266                         (self.current_dialog, do_show) = self.dialog_stack.pop()
267                         self.execBegin(first=False, do_show=do_show)
268                 else:
269                         self.current_dialog = None
270
271         def execDialog(self, dialog):
272                 self.pushCurrent()
273                 self.current_dialog = dialog
274                 self.current_dialog.isTmp = False
275                 self.current_dialog.callback = None # would cause re-entrancy problems.
276                 self.execBegin()
277
278         def openWithCallback(self, callback, screen, *arguments, **kwargs):
279                 dlg = self.open(screen, *arguments, **kwargs)
280                 dlg.callback = callback
281                 return dlg
282
283         def open(self, screen, *arguments, **kwargs):
284                 if self.dialog_stack and not self.in_exec:
285                         raise RuntimeError("modal open are allowed only from a screen which is modal!")
286                         # ...unless it's the very first screen.
287
288                 self.pushCurrent()
289                 dlg = self.current_dialog = self.instantiateDialog(screen, *arguments, **kwargs)
290                 dlg.isTmp = True
291                 dlg.callback = None
292                 self.execBegin()
293                 return dlg
294
295         def close(self, screen, *retval):
296                 if not self.in_exec:
297                         print "close after exec!"
298                         return
299
300                 # be sure that the close is for the right dialog!
301                 # if it's not, you probably closed after another dialog
302                 # was opened. this can happen if you open a dialog
303                 # onExecBegin, and forget to do this only once.
304                 # after close of the top dialog, the underlying will
305                 # gain focus again (for a short time), thus triggering
306                 # the onExec, which opens the dialog again, closing the loop.
307                 assert screen == self.current_dialog
308
309                 self.current_dialog.returnValue = retval
310                 self.delay_timer.start(0, 1)
311                 self.execEnd()
312
313         def pushSummary(self):
314                 if self.summary is not None:
315                         self.summary.hide()
316                         self.summary_stack.append(self.summary)
317                         self.summary = None
318
319         def popSummary(self):
320                 if self.summary:
321                         self.summary.doClose()
322                 self.summary = self.summary_stack and self.summary_stack.pop()
323                 if self.summary:
324                         self.summary.show()
325
326 profile("Standby,PowerKey")
327 import Screens.Standby
328 from Screens.Menu import MainMenu, mdom
329 from GlobalActions import globalActionMap
330
331 class PowerKey:
332         """ PowerKey stuff - handles the powerkey press and powerkey release actions"""
333
334         def __init__(self, session):
335                 self.session = session
336                 globalActionMap.actions["power_down"]=self.powerdown
337                 globalActionMap.actions["power_up"]=self.powerup
338                 globalActionMap.actions["power_long"]=self.powerlong
339                 globalActionMap.actions["deepstandby"]=self.shutdown # frontpanel long power button press
340                 globalActionMap.actions["discrete_off"]=self.standby
341                 self.standbyblocked = 1
342
343         def MenuClosed(self, *val):
344                 self.session.infobar = None
345
346         def shutdown(self):
347                 print "PowerOff - Now!"
348                 if not Screens.Standby.inTryQuitMainloop and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
349                         self.session.open(Screens.Standby.TryQuitMainloop, 1)
350
351         def powerlong(self):
352                 if Screens.Standby.inTryQuitMainloop or (self.session.current_dialog and not self.session.current_dialog.ALLOW_SUSPEND):
353                         return
354                 self.doAction(action = config.usage.on_long_powerpress.value)
355
356         def doAction(self, action):
357                 self.standbyblocked = 1
358                 if action == "shutdown":
359                         self.shutdown()
360                 elif action == "show_menu":
361                         print "Show shutdown Menu"
362                         root = mdom.getroot()
363                         for x in root.findall("menu"):
364                                 y = x.find("id")
365                                 if y is not None:
366                                         id = y.get("val")
367                                         if id and id == "shutdown":
368                                                 self.session.infobar = self
369                                                 menu_screen = self.session.openWithCallback(self.MenuClosed, MainMenu, x)
370                                                 menu_screen.setTitle(_("Standby / restart"))
371                                                 return
372                 elif action == "standby":
373                         self.standby()
374
375         def powerdown(self):
376                 self.standbyblocked = 0
377
378         def powerup(self):
379                 if self.standbyblocked == 0:
380                         self.doAction(action = config.usage.on_short_powerpress.value)
381
382         def standby(self):
383                 if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND and self.session.in_exec:
384                         self.session.open(Screens.Standby.Standby)
385
386 profile("Scart")
387 from Screens.Scart import Scart
388
389 class AutoScartControl:
390         def __init__(self, session):
391                 self.force = False
392                 self.current_vcr_sb = enigma.eAVSwitch.getInstance().getVCRSlowBlanking()
393                 if self.current_vcr_sb and config.av.vcrswitch.value:
394                         self.scartDialog = session.instantiateDialog(Scart, True)
395                 else:
396                         self.scartDialog = session.instantiateDialog(Scart, False)
397                 config.av.vcrswitch.addNotifier(self.recheckVCRSb)
398                 enigma.eAVSwitch.getInstance().vcr_sb_notifier.get().append(self.VCRSbChanged)
399
400         def recheckVCRSb(self, configElement):
401                 self.VCRSbChanged(self.current_vcr_sb)
402
403         def VCRSbChanged(self, value):
404                 #print "vcr sb changed to", value
405                 self.current_vcr_sb = value
406                 if config.av.vcrswitch.value or value > 2:
407                         if value:
408                                 self.scartDialog.showMessageBox()
409                         else:
410                                 self.scartDialog.switchToTV()
411
412 profile("Load:CI")
413 from enigma import eDVBCIInterfaces
414 from Screens.Ci import CiHandler
415
416 profile("Load:VolumeControl")
417 from Components.VolumeControl import VolumeControl
418
419 def runScreenTest():
420         config.misc.startCounter.value += 1
421         config.misc.startCounter.save()
422
423         profile("readPluginList")
424         plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
425
426         profile("Init:Session")
427         nav = Navigation()
428         session = Session(desktop = enigma.getDesktop(0), summary_desktop = enigma.getDesktop(1), navigation = nav)
429
430         CiHandler.setSession(session)
431
432         screensToRun = [ p.__call__ for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD) ]
433
434         profile("wizards")
435         screensToRun += wizardManager.getWizards()
436
437         screensToRun.append((100, InfoBar.InfoBar))
438
439         screensToRun.sort()
440
441         enigma.ePythonConfigQuery.setQueryFunc(configfile.getResolvedKey)
442
443 #       eDVBCIInterfaces.getInstance().setDescrambleRules(0 # Slot Number
444 #               ,(      ["1:0:1:24:4:85:C00000:0:0:0:"], #service_list
445 #                       ["PREMIERE"], #provider_list,
446 #                       [] #caid_list
447 #               ));
448
449         def runNextScreen(session, screensToRun, *result):
450                 if result:
451                         enigma.quitMainloop(*result)
452                         return
453
454                 screen = screensToRun[0][1]
455                 args = screensToRun[0][2:]
456
457                 if screensToRun:
458                         session.openWithCallback(boundFunction(runNextScreen, session, screensToRun[1:]), screen, *args)
459                 else:
460                         session.open(screen, *args)
461
462         config.misc.epgcache_filename.addNotifier(setEPGCachePath)
463
464         runNextScreen(session, screensToRun)
465
466         profile("Init:VolumeControl")
467         vol = VolumeControl(session)
468         profile("Init:PowerKey")
469         power = PowerKey(session)
470
471         # we need session.scart to access it from within menu.xml
472         session.scart = AutoScartControl(session)
473
474         profile("Init:Trashcan")
475         import Tools.Trashcan
476         Tools.Trashcan.init(session)
477
478         profile("RunReactor")
479         profile_final()
480         runReactor()
481
482         profile("wakeup")
483         from time import time, strftime, localtime
484         from Tools.StbHardware import setFPWakeuptime, getFPWakeuptime, setRTCtime
485         from Screens.SleepTimerEdit import isNextWakeupTime
486         #get currentTime
487         nowTime = time()
488         wakeupList = [
489                 x for x in ((session.nav.RecordTimer.getNextRecordingTime(), 0),
490                                         (session.nav.RecordTimer.getNextZapTime(isWakeup=True), 1),
491                                         (plugins.getNextWakeupTime(), 2),
492                                         (isNextWakeupTime(), 3))
493                 if x[0] != -1
494         ]
495         wakeupList.sort()
496         if wakeupList:
497                 from time import strftime
498                 startTime = wakeupList[0]
499                 if (startTime[0] - nowTime) < 270: # no time to switch box back on
500                         wptime = nowTime + 30  # so switch back on in 30 seconds
501                 else:
502                         wptime = startTime[0] - 240
503                 if not config.misc.useTransponderTime.value:
504                         print "dvb time sync disabled... so set RTC now to current linux time!", strftime("%Y/%m/%d %H:%M", localtime(nowTime))
505                         setRTCtime(nowTime)
506                 print "set wakeup time to", strftime("%Y/%m/%d %H:%M", localtime(wptime))
507                 setFPWakeuptime(wptime)
508                 config.misc.prev_wakeup_time.value = int(startTime[0])
509                 config.misc.prev_wakeup_time_type.value = startTime[1]
510                 config.misc.prev_wakeup_time_type.save()
511         else:
512                 config.misc.prev_wakeup_time.value = 0
513         config.misc.prev_wakeup_time.save()
514
515         profile("stopService")
516         session.nav.stopService()
517         profile("nav shutdown")
518         session.nav.shutdown()
519
520         profile("configfile.save")
521         configfile.save()
522         from Screens import InfoBarGenerics
523         InfoBarGenerics.saveResumePoints()
524
525         return 0
526
527 profile("Init:skin")
528 import skin
529 skin.loadSkinData(enigma.getDesktop(0))
530
531 profile("InputDevice")
532 import Components.InputDevice
533 Components.InputDevice.InitInputDevices()
534 import Components.InputHotplug
535
536 profile("SetupDevices")
537 import Components.SetupDevices
538 Components.SetupDevices.InitSetupDevices()
539
540 profile("AVSwitch")
541 import Components.AVSwitch
542 Components.AVSwitch.InitAVSwitch()
543
544 profile("RecordingConfig")
545 import Components.RecordingConfig
546 Components.RecordingConfig.InitRecordingConfig()
547
548 profile("UsageConfig")
549 import Components.UsageConfig
550 Components.UsageConfig.InitUsageConfig()
551
552 profile("keymapparser")
553 import keymapparser
554 keymapparser.readKeymap(config.usage.keymap.value)
555 keymapparser.readKeymap(config.usage.keytrans.value)
556
557 profile("Network")
558 import Components.Network
559 Components.Network.InitNetwork()
560
561 profile("LCD")
562 import Components.Lcd
563 Components.Lcd.InitLcd()
564
565 profile("RFMod")
566 import Components.RFmod
567 Components.RFmod.InitRFmod()
568
569 profile("Init:CI")
570 import Screens.Ci
571 Screens.Ci.InitCiConfig()
572
573 profile("RcModel")
574 import Components.RcModel
575
576 #from enigma import dump_malloc_stats
577 #t = eTimer()
578 #t.callback.append(dump_malloc_stats)
579 #t.start(1000)
580
581 # first, setup a screen
582 try:
583         runScreenTest()
584
585         plugins.shutdown()
586
587         Components.ParentalControl.parentalControl.save()
588 except:
589         print 'EXCEPTION IN PYTHON STARTUP CODE:'
590         print '-'*60
591         print_exc(file=stdout)
592         enigma.quitMainloop(5)
593         print '-'*60