PushService: Initial release
[enigma2-plugins.git] / pushservice / src / PushService.py
1 '''
2 Created on 06.11.2011
3
4 @author: Frank Glaser
5 '''
6
7
8 import os
9 import sys, traceback
10
11 from Components.config import *
12 from enigma import eTimer
13 from time import localtime, strftime
14
15
16 # Plugin internal
17 from . import _
18 from PushServiceBase import PushServiceBase
19
20
21 #######################################################
22 # Logical part
23 class PushService(PushServiceBase):
24
25         def __init__(self):
26                 PushServiceBase.__init__(self)
27                 
28                 self.plugins = []
29                 
30                 self.state = "First"
31                 self.timer = eTimer()
32                 self.timer.callback.append(self.go)
33
34         def start(self, state = None):
35                 if self.timer.isActive():
36                         self.timer.stop()
37                 
38                 # Read XML file, parse it and instantiate configured plugins
39                 plugins = self.load()
40                 if plugins:
41                         self.plugins = plugins
42                 
43                 self.begin(self.plugins)
44                 
45                 self.next(state)
46
47         def next(self, state = None):
48                 #TODO Start run in a new thread !!!!!!!!!
49                 # Override statemachine
50                 if state: self.state = state
51                 
52                 if self.state == "Now":
53                         self.state = "First"
54                         self.go()
55                 
56                 if self.state == "Boot":
57                         self.state = "First"
58                         self.timer.startLongTimer( 10 )
59                 
60                 elif self.state == "First":
61                         self.state = "Period"
62                         cltime = config.pushservice.time.value
63                         lotime = localtime()
64                         ltime = lotime[3]*60 + lotime[4]
65                         ctime = cltime[0]*60 + cltime[1]
66                         seconds = 60 * abs(ctime - ltime)
67                         self.timer.startLongTimer( seconds )
68                 
69                 elif self.state == "Period":
70                         period = config.pushservice.period.value
71                         if period > 0:
72                                 self.timer.startLongTimer( int(period)*60*60 )
73
74         def stop(self):
75                 # Stop Timer
76                 if self.timer.isActive():
77                         self.timer.stop()
78                 self.state = "First"
79                 self.end(self.plugins)
80
81         def go(self):
82                 self.run(self.plugins)
83                 self.next()