use celementtree to parse config,
[enigma2-plugins.git] / epgrefresh / src / plugin.py
1 # Config
2 from Components.config import config, ConfigEnableDisable, ConfigNumber, \
3         ConfigSubsection, ConfigClock
4
5 # Calculate default begin/end
6 from time import time, localtime, mktime
7 now = localtime()
8 begin = mktime((
9         now.tm_year, now.tm_mon, now.tm_mday, 20, 15, \
10         0, now.tm_wday, now.tm_yday, now.tm_isdst)
11 )
12 end = mktime((
13         now.tm_year, now.tm_mon, now.tm_mday, 06, 30, \
14         0, now.tm_wday, now.tm_yday, now.tm_isdst)
15 )
16
17 config.plugins.epgrefresh = ConfigSubsection()
18 config.plugins.epgrefresh.enabled = ConfigEnableDisable(default = False)
19 config.plugins.epgrefresh.begin = ConfigClock(default = int(begin))
20 config.plugins.epgrefresh.end = ConfigClock(default = int(end))
21 config.plugins.epgrefresh.interval = ConfigNumber(default = 2)
22 config.plugins.epgrefresh.delay_standby = ConfigNumber(default = 10)
23 config.plugins.epgrefresh.inherit_autotimer = ConfigEnableDisable(default = False)
24 config.plugins.epgrefresh.afterevent = ConfigEnableDisable(default = False)
25 config.plugins.epgrefresh.force = ConfigEnableDisable(default = False)
26 config.plugins.epgrefresh.lastscan = ConfigNumber(default = 0)
27
28 del now, begin, end
29
30 # Plugin
31 from EPGRefresh import epgrefresh
32 from EPGRefreshConfiguration import EPGRefreshConfiguration
33
34 # Plugin definition
35 from Plugins.Plugin import PluginDescriptor
36
37 # Autostart
38 def autostart(reason, **kwargs):
39         if config.plugins.epgrefresh.enabled.value and reason == 0 \
40                 and kwargs.has_key("session"):
41
42                 epgrefresh.start(kwargs["session"])
43
44         elif reason == 1:
45                 epgrefresh.stop()
46
47 def getNextWakeup():
48         # Return invalid time if not automatically refreshing
49         if not config.plugins.epgrefresh.enabled.value:
50                 return -1
51         now = localtime()
52         begin = int(mktime(
53                 (now.tm_year, now.tm_mon, now.tm_mday,
54                 config.plugins.epgrefresh.begin.value[0],
55                 config.plugins.epgrefresh.begin.value[1],
56                 0, now.tm_wday, now.tm_yday, now.tm_isdst)
57         ))
58         # todays timespan has not yet begun
59         if begin > time():
60                 return begin
61         # otherwise add 1 day
62         return begin+86400
63
64 # Mainfunction
65 def main(session, **kwargs):
66         epgrefresh.stop()
67         session.openWithCallback(
68                 doneConfiguring,
69                 EPGRefreshConfiguration
70         )
71
72 def doneConfiguring(session, **kwargs):
73         if config.plugins.epgrefresh.enabled.value:
74                 epgrefresh.start(session)
75
76 def Plugins(**kwargs):
77         return [
78                 PluginDescriptor(
79                         name="EPGRefresh",
80                         description = "Automated EPGRefresher",
81                         where = [
82                                 PluginDescriptor.WHERE_AUTOSTART,
83                                 PluginDescriptor.WHERE_SESSIONSTART
84                         ],
85                         fnc = autostart,
86                         wakeupfnc = getNextWakeup
87                 ),
88                 PluginDescriptor(
89                         name="EPGRefresh",
90                         description = "Automated EPGRefresher",
91                         where = PluginDescriptor.WHERE_PLUGINMENU,
92                         fnc = main
93                 )
94         ]