Andrew Pickford | d7045b0 | 2017-09-05 16:55:08 +0200 | [diff] [blame] | 1 | import copy |
Andrew Pickford | 000ecf1 | 2017-08-08 14:42:12 +0200 | [diff] [blame] | 2 | import reclass.values.parser_funcs |
Andrew Pickford | 49ef7db | 2017-09-04 17:04:32 +0200 | [diff] [blame] | 3 | from reclass.defaults import * |
Andrew Pickford | 000ecf1 | 2017-08-08 14:42:12 +0200 | [diff] [blame] | 4 | |
| 5 | class Settings(object): |
| 6 | |
| 7 | def __init__(self, options={}): |
Andrew Pickford | 8258dad | 2017-09-04 17:09:28 +0200 | [diff] [blame] | 8 | 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 Michalec | 0a3a368 | 2018-03-28 15:30:15 +0200 | [diff] [blame] | 12 | self.allow_none_override = options.get('allow_none_override', OPT_ALLOW_NONE_OVERRIDE) |
Andrew Pickford | 49ef7db | 2017-09-04 17:04:32 +0200 | [diff] [blame] | 13 | 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 Pickford | 8258dad | 2017-09-04 17:09:28 +0200 | [diff] [blame] | 19 | 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 Pickford | 49ef7db | 2017-09-04 17:04:32 +0200 | [diff] [blame] | 21 | self.reference_sentinels = options.get('reference_sentinels', REFERENCE_SENTINELS) |
| 22 | self.ignore_class_notfound = options.get('ignore_class_notfound', OPT_IGNORE_CLASS_NOTFOUND) |
Andrew Pickford | 000ecf1 | 2017-08-08 14:42:12 +0200 | [diff] [blame] | 23 | |
Andrew Pickford | 2c48d60 | 2017-09-13 17:21:27 +0200 | [diff] [blame] | 24 | 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 Pickford | 8e41525 | 2018-03-15 11:44:39 +0100 | [diff] [blame] | 29 | self.ignore_overwritten_missing_references = options.get('ignore_overwritten_missing_references', OPT_IGNORE_OVERWRITTEN_MISSING_REFERENCES) |
Andrew Pickford | 2c48d60 | 2017-09-13 17:21:27 +0200 | [diff] [blame] | 30 | |
Andrew Pickford | ffd77b4 | 2018-03-16 14:37:03 +0100 | [diff] [blame] | 31 | self.group_errors = options.get('group_errors', OPT_GROUP_ERRORS) |
| 32 | |
Andrew Pickford | 000ecf1 | 2017-08-08 14:42:12 +0200 | [diff] [blame] | 33 | 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 Michalec | 0a3a368 | 2018-03-28 15:30:15 +0200 | [diff] [blame] | 42 | and self.allow_none_override == other.allow_none_override \ |
Andrew Pickford | 000ecf1 | 2017-08-08 14:42:12 +0200 | [diff] [blame] | 43 | 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 Pickford | d7045b0 | 2017-09-05 16:55:08 +0200 | [diff] [blame] | 49 | and self.inventory_ignore_failed_node == other.inventory_ignore_failed_node \ |
| 50 | and self.inventory_ignore_failed_render == other.inventory_ignore_failed_render \ |
Andrew Pickford | 8fe8468 | 2017-09-04 16:47:56 +0200 | [diff] [blame] | 51 | and self.reference_sentinels == other.reference_sentinels \ |
Andrew Pickford | 2c48d60 | 2017-09-13 17:21:27 +0200 | [diff] [blame] | 52 | 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 Pickford | d7045b0 | 2017-09-05 16:55:08 +0200 | [diff] [blame] | 55 | |
| 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__() |