blob: 44c58d8bd1b3bc5766de57e3dfcdd1a29cfc1004 [file] [log] [blame]
Andrew Pickfordd7045b02017-09-05 16:55:08 +02001import copy
Andrew Pickford000ecf12017-08-08 14:42:12 +02002import reclass.values.parser_funcs
Andrew Pickford49ef7db2017-09-04 17:04:32 +02003from reclass.defaults import *
Andrew Pickford000ecf12017-08-08 14:42:12 +02004
5class Settings(object):
6
7 def __init__(self, options={}):
Andrew Pickford8258dad2017-09-04 17:09:28 +02008 self.allow_scalar_over_dict = options.get('allow_scalar_over_dict', OPT_ALLOW_SCALAR_OVER_DICT)
9 self.allow_scalar_over_list = options.get('allow_scalar_over_list', OPT_ALLOW_SCALAR_OVER_LIST)
10 self.allow_list_over_scalar = options.get('allow_list_over_scalar', OPT_ALLOW_LIST_OVER_SCALAR)
11 self.allow_dict_over_scalar = options.get('allow_dict_over_scalar', OPT_ALLOW_DICT_OVER_SCALAR)
Petr Michalec0a3a3682018-03-28 15:30:15 +020012 self.allow_none_override = options.get('allow_none_override', OPT_ALLOW_NONE_OVERRIDE)
Andrew Pickford49ef7db2017-09-04 17:04:32 +020013 self.automatic_parameters = options.get('automatic_parameters', AUTOMATIC_RECLASS_PARAMETERS)
14 self.default_environment = options.get('default_environment', DEFAULT_ENVIRONMENT)
15 self.delimiter = options.get('delimiter', PARAMETER_INTERPOLATION_DELIMITER)
16 self.dict_key_override_prefix = options.get('dict_key_override_prefix', PARAMETER_DICT_KEY_OVERRIDE_PREFIX)
17 self.escape_character = options.get('escape_character', ESCAPE_CHARACTER)
18 self.export_sentinels = options.get('export_sentinels', EXPORT_SENTINELS)
Andrew Pickford8258dad2017-09-04 17:09:28 +020019 self.inventory_ignore_failed_node = options.get('inventory_ignore_failed_node', OPT_INVENTORY_IGNORE_FAILED_NODE)
20 self.inventory_ignore_failed_render = options.get('inventory_ignore_failed_render', OPT_INVENTORY_IGNORE_FAILED_RENDER)
Andrew Pickford49ef7db2017-09-04 17:04:32 +020021 self.reference_sentinels = options.get('reference_sentinels', REFERENCE_SENTINELS)
22 self.ignore_class_notfound = options.get('ignore_class_notfound', OPT_IGNORE_CLASS_NOTFOUND)
Andrew Pickford000ecf12017-08-08 14:42:12 +020023
Andrew Pickford2c48d602017-09-13 17:21:27 +020024 self.ignore_class_notfound_regexp = options.get('ignore_class_notfound_regexp', OPT_IGNORE_CLASS_NOTFOUND_REGEXP)
25 if isinstance(self.ignore_class_notfound_regexp, basestring):
26 self.ignore_class_notfound_regexp = [ self.ignore_class_notfound_regexp ]
27
28 self.ignore_class_notfound_warning = options.get('ignore_class_notfound_warning', OPT_IGNORE_CLASS_NOTFOUND_WARNING)
Andrew Pickford8e415252018-03-15 11:44:39 +010029 self.ignore_overwritten_missing_references = options.get('ignore_overwritten_missing_references', OPT_IGNORE_OVERWRITTEN_MISSING_REFERENCES)
Andrew Pickford2c48d602017-09-13 17:21:27 +020030
Andrew Pickfordffd77b42018-03-16 14:37:03 +010031 self.group_errors = options.get('group_errors', OPT_GROUP_ERRORS)
32
Andrew Pickford000ecf12017-08-08 14:42:12 +020033 self.ref_parser = reclass.values.parser_funcs.get_ref_parser(self.escape_character, self.reference_sentinels, self.export_sentinels)
34 self.simple_ref_parser = reclass.values.parser_funcs.get_simple_ref_parser(self.escape_character, self.reference_sentinels, self.export_sentinels)
35
36 def __eq__(self, other):
37 return isinstance(other, type(self)) \
38 and self.allow_scalar_over_dict == other.allow_scalar_over_dict \
39 and self.allow_scalar_over_list == other.allow_scalar_over_list \
40 and self.allow_list_over_scalar == other.allow_list_over_scalar \
41 and self.allow_dict_over_scalar == other.allow_dict_over_scalar \
Petr Michalec0a3a3682018-03-28 15:30:15 +020042 and self.allow_none_override == other.allow_none_override \
Andrew Pickford000ecf12017-08-08 14:42:12 +020043 and self.automatic_parameters == other.automatic_parameters \
44 and self.default_environment == other.default_environment \
45 and self.delimiter == other.delimiter \
46 and self.dict_key_override_prefix == other.dict_key_override_prefix \
47 and self.escape_character == other.escape_character \
48 and self.export_sentinels == other.export_sentinels \
Andrew Pickfordd7045b02017-09-05 16:55:08 +020049 and self.inventory_ignore_failed_node == other.inventory_ignore_failed_node \
50 and self.inventory_ignore_failed_render == other.inventory_ignore_failed_render \
Andrew Pickford8fe84682017-09-04 16:47:56 +020051 and self.reference_sentinels == other.reference_sentinels \
Andrew Pickford2c48d602017-09-13 17:21:27 +020052 and self.ignore_class_notfound == other.ignore_class_notfound \
53 and self.ignore_class_notfound_regexp == other.ignore_class_notfound_regexp \
54 and self.ignore_class_notfound_warning == other.ignore_class_notfound_warning
Andrew Pickfordd7045b02017-09-05 16:55:08 +020055
56 def __copy__(self):
57 cls = self.__class__
58 result = cls.__new__(cls)
59 result.__dict__.update(self.__dict__)
60 return result
61
62 def __deepcopy__(self, memo):
63 return self.__copy__()