Initial commit
[ta/config-manager.git] / cmframework / src / cmframework / utils / cmpluginmanager.py
1 # Copyright 2019 Nokia
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
15 import re
16 import logging
17
18 from cmframework.apis import cmerror
19
20
21 class CMPluginManager(object):
22
23     def __init__(self, plugins_path):
24         self.pluginlist = {}
25         self.filterdict = {}
26         self.plugins_path = plugins_path
27
28     # pylint: disable=no-self-use
29     def load_plugin(self):
30         raise cmerror.CMError('Not implemented')
31
32     # pylint: disable=no-self-use
33     def build_input(self, indata, filtername):
34         search_re = re.compile(filtername)
35         if isinstance(indata, dict):
36             filter_data = {}
37             for key, value in indata.iteritems():
38                 logging.debug('Matching %s against %s', key, filtername)
39                 if search_re.match(key):
40                     filter_data[key] = value
41         else:
42             filter_data = []
43             for key in indata:
44                 logging.debug('Matching %s against %s', key, filtername)
45                 if search_re.match(key):
46                     filter_data.append(key)
47
48         return filter_data