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