create op_occs
[vfc/nfvo/lcm.git] / lcm / pub / utils / values.py
1 # Copyright 2016 ZTE Corporation.
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
15 import logging
16
17 logger = logging.getLogger(__name__)
18
19
20 def ignore_case_get(args, key, def_val=""):
21     if not key:
22         return def_val
23     if key in args:
24         return args[key]
25     for old_key in args:
26         if old_key.upper() == key.upper():
27             return args[old_key]
28     return def_val
29
30
31 def update_value(origin_data, new_data):
32     logger.debug(origin_data)
33     if not isinstance(origin_data, dict):
34         str_data = origin_data.encode('utf-8')
35         logger.debug(str_data)
36         origin_data = eval(str_data)
37     logger.debug(isinstance(origin_data, dict))
38     logger.debug(new_data)
39     for k, v in new_data.iteritems():
40         if k not in origin_data:
41             origin_data[k] = v
42         else:
43             if isinstance(origin_data[k], list):
44                 origin_data[k] = origin_data[k].extend(v)
45             else:
46                 origin_data[k] = v
47     return origin_data