blob: e3fc26ed11334d99227a137d289b39ae0e056c02 [file] [log] [blame]
Jiri Broulik30e05a62018-06-14 13:31:24 +02001import copy
2import reclass.values.parser_funcs
3from reclass.defaults import *
4
Jiri Broulikd3264612018-06-14 17:06:40 +02005try:
6 basestring
7except NameError:
8 basestring = str
9
Jiri Broulik30e05a62018-06-14 13:31:24 +020010class Settings(object):
11
12 def __init__(self, options={}):
13 self.allow_scalar_over_dict = options.get('allow_scalar_over_dict', OPT_ALLOW_SCALAR_OVER_DICT)
14 self.allow_scalar_over_list = options.get('allow_scalar_over_list', OPT_ALLOW_SCALAR_OVER_LIST)
15 self.allow_list_over_scalar = options.get('allow_list_over_scalar', OPT_ALLOW_LIST_OVER_SCALAR)
16 self.allow_dict_over_scalar = options.get('allow_dict_over_scalar', OPT_ALLOW_DICT_OVER_SCALAR)
17 self.allow_none_override = options.get('allow_none_override', OPT_ALLOW_NONE_OVERRIDE)
18 self.automatic_parameters = options.get('automatic_parameters', AUTOMATIC_RECLASS_PARAMETERS)
19 self.default_environment = options.get('default_environment', DEFAULT_ENVIRONMENT)
20 self.delimiter = options.get('delimiter', PARAMETER_INTERPOLATION_DELIMITER)
21 self.dict_key_override_prefix = options.get('dict_key_override_prefix', PARAMETER_DICT_KEY_OVERRIDE_PREFIX)
22 self.escape_character = options.get('escape_character', ESCAPE_CHARACTER)
23 self.export_sentinels = options.get('export_sentinels', EXPORT_SENTINELS)
24 self.inventory_ignore_failed_node = options.get('inventory_ignore_failed_node', OPT_INVENTORY_IGNORE_FAILED_NODE)
25 self.inventory_ignore_failed_render = options.get('inventory_ignore_failed_render', OPT_INVENTORY_IGNORE_FAILED_RENDER)
26 self.reference_sentinels = options.get('reference_sentinels', REFERENCE_SENTINELS)
27 self.ignore_class_notfound = options.get('ignore_class_notfound', OPT_IGNORE_CLASS_NOTFOUND)
28
29 self.ignore_class_notfound_regexp = options.get('ignore_class_notfound_regexp', OPT_IGNORE_CLASS_NOTFOUND_REGEXP)
30 if isinstance(self.ignore_class_notfound_regexp, basestring):
31 self.ignore_class_notfound_regexp = [ self.ignore_class_notfound_regexp ]
32
33 self.ignore_class_notfound_warning = options.get('ignore_class_notfound_warning', OPT_IGNORE_CLASS_NOTFOUND_WARNING)
34 self.ignore_overwritten_missing_references = options.get('ignore_overwritten_missing_references', OPT_IGNORE_OVERWRITTEN_MISSING_REFERENCES)
35
36 self.group_errors = options.get('group_errors', OPT_GROUP_ERRORS)
37
38 self.ref_parser = reclass.values.parser_funcs.get_ref_parser(self.escape_character, self.reference_sentinels, self.export_sentinels)
39 self.simple_ref_parser = reclass.values.parser_funcs.get_simple_ref_parser(self.escape_character, self.reference_sentinels, self.export_sentinels)
40
41 def __eq__(self, other):
42 return isinstance(other, type(self)) \
43 and self.allow_scalar_over_dict == other.allow_scalar_over_dict \
44 and self.allow_scalar_over_list == other.allow_scalar_over_list \
45 and self.allow_list_over_scalar == other.allow_list_over_scalar \
46 and self.allow_dict_over_scalar == other.allow_dict_over_scalar \
47 and self.allow_none_override == other.allow_none_override \
48 and self.automatic_parameters == other.automatic_parameters \
49 and self.default_environment == other.default_environment \
50 and self.delimiter == other.delimiter \
51 and self.dict_key_override_prefix == other.dict_key_override_prefix \
52 and self.escape_character == other.escape_character \
53 and self.export_sentinels == other.export_sentinels \
54 and self.inventory_ignore_failed_node == other.inventory_ignore_failed_node \
55 and self.inventory_ignore_failed_render == other.inventory_ignore_failed_render \
56 and self.reference_sentinels == other.reference_sentinels \
57 and self.ignore_class_notfound == other.ignore_class_notfound \
58 and self.ignore_class_notfound_regexp == other.ignore_class_notfound_regexp \
59 and self.ignore_class_notfound_warning == other.ignore_class_notfound_warning
60
61 def __copy__(self):
62 cls = self.__class__
63 result = cls.__new__(cls)
64 result.__dict__.update(self.__dict__)
65 return result
66
67 def __deepcopy__(self, memo):
68 return self.__copy__()