2 Copyright (c) 2017-2019 Intel Corporation
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
20 from mo.utils.custom_replacement_config import parse_custom_replacement_config_file
21 from mo.utils.error import Error
22 from mo.utils.utils import refer_to_faq_msg
25 class CustomReplacementRegistry(object):
27 Registry that contains registered custom calls descriptors.
30 class __CustomReplacementRegistry:
35 return repr(self) + str(self.registry)
38 if not CustomReplacementRegistry.instance:
39 CustomReplacementRegistry.instance = CustomReplacementRegistry.__CustomReplacementRegistry()
42 # CustomCallRegistry.instance.val = arg
44 def __getattr__(self, name):
45 return getattr(self.instance, name)
49 def add_custom_replacement_description_from_config(self, file_name: str):
50 if not os.path.exists(file_name):
51 raise Error("Custom replacement configuration file '{}' doesn't exist. ".format(file_name) +
54 descriptions = parse_custom_replacement_config_file(file_name)
55 for desc in descriptions:
56 self.registry.setdefault(desc.id, list()).append(desc)
57 log.info("Registered custom replacement with id '{}'".format(desc.id))
59 def get_custom_replacement_description(self, replacement_id: str):
60 if replacement_id in self.registry:
61 return self.registry[replacement_id]
63 log.warning("Configuration file for custom replacement with id '{}' doesn't exist".format(replacement_id))
66 def get_all_replacements_descriptions(self):
68 for l in self.registry.values():