PushService: Fixed load error
[enigma2-plugins.git] / pushservice / src / ModuleBase.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 from Components.config import ConfigYesNo, NoSave
20
21 try:
22         #Python >= 2.7
23         from collections import OrderedDict
24 except:
25         from OrderedDict import OrderedDict
26
27
28 # Module base class
29 class ModuleBase(object):
30
31         def __init__(self):
32                 # Is called on instance creation
33                 
34                 # Default configuration
35                 self.enable = NoSave(ConfigYesNo( default = False ))
36                 
37                 self.options = OrderedDict()
38                 
39                 # Build a list of key-value string tuples
40                 # [ (key, value, description, config element) , ]
41                 #self.options['enabled'] = ConfigYesNo( default = False )
42
43
44         ################################################
45         # Base classmethod functions
46         @classmethod
47         def getClass(cls):
48                 # Return the Class
49                 return cls.__name__
50
51
52         ################################################
53         # Base functions
54         def getName(self):
55                 # Return the Class Name
56                 return self.__class__.__name__
57
58         def getNameId(self):
59                 return self.getName() + " (" + str(self.getUniqueID()) + ")"
60
61         def getValue(self, key):
62                 if key in self.options:
63                         return self.options[key][0].value
64                 else:
65                         return None
66
67         def setValue(self, key, value):
68                 self.options[key][0].value = value
69
70         def getOption(self, key):
71                 if key in self.options:
72                         return self.options[key]
73                 else:
74                         return None
75
76         def setOption(self, key, option, description):
77                 self.options[key] = ( option, description )
78
79         def setOptions(self, options):
80                 # Parse a list of key-value string tuples
81                 # [ (key, value) , ]
82                 # If something is missing, the last/default value is used
83                 for key, value in options:
84                         try:
85                                 default = self.getValue(key)
86                                 if type(default) is str:
87                                         self.setValue(key, value)
88                                 elif type(default) is bool:
89                                         self.setValue(key, eval(value))
90                                 elif type(default) is int:
91                                         self.setValue(key, int(value))
92                         except:
93                                 print _("[PushService] Module %s: Skipping config option: %s %s") % ( self.getName(), str(key), str(value) )
94                                 continue
95
96         def getUniqueID(self):
97                 return self.uniqueid
98
99         def getEnable(self):
100                 return self.enable.value
101
102         def setEnable(self, enable):
103                 self.enable.value = enable
104
105         def getConfigEnable(self):
106                 return self.enable
107
108         def getStringEnable(self):
109                 return str(self.enable.value)
110
111         def getStringOptions(self):
112                 return [ ( str(key), str(option.value), str(description) ) for ( key, ( option, description ) ) in self.options.items() ]
113
114         def getConfigOptions(self):
115                 return [ ( key, option, description) for ( key, ( option, description ) ) in self.options.items() ]
116
117
118         ################################################
119         # Functions to be implemented in the plugin
120         def begin(self):
121                 # Is called after starting PushSerive
122                 pass
123
124         def end(self):
125                 # Is called after stopping PushSerive
126                 pass
127
128         def cancel(self):
129                 # Cancel activities
130                 pass