diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2015-11-03 03:31:56 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2015-11-03 03:31:56 +0200 |
commit | 8495075ceeb7c2d12589a9226d74e19f5cfc7e9b (patch) | |
tree | 6f5ae49754981a388b0c1e9ff194e52fb3aba29a /mesonlib.py | |
parent | e2313b85d7f0d10c0995ea9887bee00c2763290a (diff) | |
download | meson-8495075ceeb7c2d12589a9226d74e19f5cfc7e9b.zip meson-8495075ceeb7c2d12589a9226d74e19f5cfc7e9b.tar.gz meson-8495075ceeb7c2d12589a9226d74e19f5cfc7e9b.tar.bz2 |
Turned builtin options into proper objects.
Diffstat (limited to 'mesonlib.py')
-rw-r--r-- | mesonlib.py | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/mesonlib.py b/mesonlib.py index f422095..bb69632 100644 --- a/mesonlib.py +++ b/mesonlib.py @@ -264,80 +264,3 @@ def stringlistify(item): if not isinstance(i, str): raise MesonException('List item not a string.') return item - -class UserOption: - def __init__(self, name, description): - super().__init__() - self.name = name - self.description = description - - def parse_string(self, valuestring): - return valuestring - -class UserStringOption(UserOption): - def __init__(self, name, description, value): - super().__init__(name, description) - self.set_value(value) - - def set_value(self, newvalue): - if not isinstance(newvalue, str): - raise MesonException('Value "%s" for string option "%s" is not a string.' % (str(newvalue), self.name)) - self.value = newvalue - -class UserBooleanOption(UserOption): - def __init__(self, name, description, value): - super().__init__(name, description) - self.set_value(value) - - def tobool(self, thing): - if isinstance(thing, bool): - return thing - if thing.lower() == 'true': - return True - if thing.lower() == 'false': - return False - raise MesonException('Value %s is not boolean (true or false).' % thing) - - def set_value(self, newvalue): - self.value = self.tobool(newvalue) - - def parse_string(self, valuestring): - if valuestring == 'false': - return False - if valuestring == 'true': - return True - raise MesonException('Value "%s" for boolean option "%s" is not a boolean.' % (valuestring, self.name)) - -class UserComboOption(UserOption): - def __init__(self, name, description, choices, value): - super().__init__(name, description) - self.choices = choices - if not isinstance(self.choices, list): - raise MesonException('Combo choices must be an array.') - for i in self.choices: - if not isinstance(i, str): - raise MesonException('Combo choice elements must be strings.') - self.set_value(value) - - def set_value(self, newvalue): - if newvalue not in self.choices: - optionsstring = ', '.join(['"%s"' % (item,) for item in self.choices]) - raise MesonException('Value "%s" for combo option "%s" is not one of the choices. Possible choices are: %s.' % (newvalue, self.name, optionsstring)) - self.value = newvalue - -class UserStringArrayOption(UserOption): - def __init__(self, name, description, value): - super().__init__(name, description) - self.set_value(value) - - def set_value(self, newvalue): - if isinstance(newvalue, str): - if not newvalue.startswith('['): - raise MesonException('Valuestring does not define an array: ' + newvalue) - newvalue = eval(newvalue, {}, {}) # Yes, it is unsafe. - if not isinstance(newvalue, list): - raise MesonException('String array value is not an array.') - for i in newvalue: - if not isinstance(i, str): - raise MesonException('String array element not a string.') - self.value = newvalue |