aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Components/Converter/ConfigEntryTest.py
blob: 166e6beaa088a8df8df1876ca496e4cbb4d79896 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from Converter import Converter
from Components.Element import cached

from Components.config import configfile

class ConfigEntryTest(Converter, object):
	def __init__(self, argstr):
		Converter.__init__(self, argstr)
		args = argstr.split(',')
		self.argerror = False
		self.checkSourceBoolean = False
		self.invert = False
		self.configKey = None
		self.configValue = None
		if len(args) < 2:
			self.argerror = True
		else:
			if args[0].find("config.") != -1:
				self.configKey = args[0]
				self.configValue = args[1]
				if len(args) > 2:
					if args[2] == 'Invert':
						self.invert = True
					elif args[2] == 'CheckSourceBoolean':
						self.checkSourceBoolean = True
					else:
						self.argerror = True
				if len(args) > 3:
					if args[3] == 'Invert':
						self.invert = True
					elif args[3] == 'CheckSourceBoolean':
						self.checkSourceBoolean = True
					else:
						self.argerror = True
			else:
				self.argerror = True
		if self.argerror:
			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'"

	@cached
	def getBoolean(self):
		if self.argerror:
			print "ConfigEntryTest got invalid arguments", self.converter_arguments, "force True!!"
			return True
		if self.checkSourceBoolean and not self.source.boolean:
			return False
		val = configfile.getResolvedKey(self.configKey)
		ret = val == self.configValue
		return ret ^ self.invert

	boolean = property(getBoolean)