PushService: Fixed load error
[enigma2-plugins.git] / pushservice / src / plugin.py
1 #######################################################################
2 #
3 #    Push Service for Enigma-2
4 #    Coded by betonme (c) 2012 <glaserfrank(at)gmail.com>
5 #    Support: http://www.i-have-a-dreambox.com/wbb2/thread.php?threadid=167779
6 #
7 #    This program is free software; you can redistribute it and/or
8 #    modify it under the terms of the GNU General Public License
9 #    as published by the Free Software Foundation; either version 2
10 #    of the License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU General Public License for more details.
16 #
17 #######################################################################
18
19 import os, sys, traceback
20
21 # Plugin
22 from Plugins.Plugin import PluginDescriptor
23
24 # Config
25 from Components.config import config, ConfigSubsection, ConfigNothing, ConfigEnableDisable, ConfigText, ConfigClock, ConfigSelectionNumber
26
27 # Default encoding
28 #from Components.Language import language
29
30 # Plugin internal
31 from __init__ import _
32 from PushService import PushService
33 #from ConfigScreen import ConfigScreen
34
35
36 # Constants
37 NAME = "PushService"
38 VERSION = "0.2.3"
39 SUPPORT = "http://www.i-have-a-dreambox.com/wbb2/thread.php?threadid=167779"
40 DONATE = "http://bit.ly/pspaypal"
41 ABOUT = "\n  " + NAME + " " + VERSION + "\n\n" \
42                                 + _("  (C) 2012 by betonme @ IHAD \n\n") \
43                                 + _("  If You like this plugin and want to support it,\n") \
44                                 + _("  or if just want to say ''thanks'',\n") \
45                                 + _("  feel free to donate via PayPal. \n\n") \
46                                 + _("  Thanks a lot ! \n\n  PayPal: ") + DONATE
47
48
49 # Globals
50 gPushService = None
51
52
53 # Config options
54 config.pushservice                           = ConfigSubsection()
55
56 config.pushservice.about                     = ConfigNothing()
57
58 config.pushservice.enable                    = ConfigEnableDisable(default = True)
59
60 config.pushservice.boxname                   = ConfigText(default = "Dreambox", fixed_size = False)
61 config.pushservice.xmlpath                   = ConfigText(default = "/etc/enigma2/pushservice.xml", fixed_size = False)
62
63 config.pushservice.runonboot                 = ConfigEnableDisable(default = True)
64 config.pushservice.time                      = ConfigClock(default = 0)
65 config.pushservice.period                    = ConfigSelectionNumber(0, 1000, 1, default = 24)
66
67
68 #######################################################
69 # Plugin configuration
70 def setup(session, **kwargs):
71         try:
72                 ### For testing only
73                 import ConfigScreen
74                 reload(ConfigScreen)
75                 ###
76                 session.open(ConfigScreen.ConfigScreen)
77         except Exception, e:
78                 print _("PushService setup exception ") + str(e)
79                 exc_type, exc_value, exc_traceback = sys.exc_info()
80                 traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout)
81
82
83 #######################################################
84 # Autostart
85 def autostart(reason, **kwargs):
86         if reason == 0:  # start
87                 if config.pushservice.enable.value:
88                         try:
89                                 global gPushService
90                                 gPushService = PushService()
91                                 gPushService.start()
92                         except Exception, e:
93                                 print _("PushService autostart exception ") + str(e)
94                                 exc_type, exc_value, exc_traceback = sys.exc_info()
95                                 traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout)
96
97
98 #######################################################
99 # Plugin main function
100 def Plugins(**kwargs):
101         
102         descriptors = []
103         
104         if config.pushservice.enable.value:
105                 # AutoStart
106                 descriptors.append( PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart, needsRestart = False) )
107                 
108         #TODO icon
109         descriptors.append( PluginDescriptor(name = NAME, description = NAME + " " +_("configuration"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc = setup, needsRestart = False) ) #icon = "/icon.png"
110
111         return descriptors