Merge commit 'origin/bug_112_enable_extensions_manager' into experimental
[enigma2.git] / lib / python / Components / Converter / ConfigEntryTest.py
1 from Converter import Converter
2 from Components.Element import cached
3
4 from Components.config import configfile
5
6 class ConfigEntryTest(Converter, object):
7         def __init__(self, argstr):
8                 Converter.__init__(self, argstr)
9                 args = argstr.split(',')
10                 self.argerror = False
11                 self.checkSourceBoolean = False
12                 self.invert = False
13                 self.configKey = None
14                 self.configValue = None
15                 if len(args) < 2:
16                         self.argerror = True
17                 else:
18                         if args[0].find("config.") != -1:
19                                 self.configKey = args[0]
20                                 self.configValue = args[1]
21                                 if len(args) > 2:
22                                         if args[2] == 'Invert':
23                                                 self.invert = True
24                                         elif args[2] == 'CheckSourceBoolean':
25                                                 self.checkSourceBoolean = True
26                                         else:
27                                                 self.argerror = True
28                                 if len(args) > 3:
29                                         if args[3] == 'Invert':
30                                                 self.invert = True
31                                         elif args[3] == 'CheckSourceBoolean':
32                                                 self.checkSourceBoolean = True
33                                         else:
34                                                 self.argerror = True
35                         else:
36                                 self.argerror = True
37                 if self.argerror:
38                         print "ConfigEntryTest Converter got incorrect arguments", args, "!!!\narg[0] must start with 'config.',\narg[1] is the compare string,\narg[2],arg[3] are optional arguments and must be 'Invert' or 'CheckSourceBoolean'"
39
40         @cached
41         def getBoolean(self):
42                 if self.argerror:
43                         print "ConfigEntryTest got invalid arguments", self.converter_arguments, "force True!!"
44                         return True
45                 if self.checkSourceBoolean and not self.source.boolean:
46                         return False
47                 val = configfile.getResolvedKey(self.configKey)
48                 ret = val == self.configValue
49                 return ret ^ self.invert
50
51         boolean = property(getBoolean)