Completed
Push — master ( fe66bc...2a24eb )
by Manas
18:11
created

st2client.utils.PolicyListCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %
Metric Value
wmc 6
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 7 1
B run() 0 16 5
1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
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.
15
16
import copy
17
18
import six
19
20
__all__ = [
21
    'merge_dicts'
22
]
23
24
25
def merge_dicts(d1, d2):
26
    """
27
    Merge values from d2 into d1 ignoring empty / None values.
28
29
    :type d1: ``dict``
30
    :type d2: ``dict``
31
32
    :rtype: ``dict``
33
    """
34
    result = copy.deepcopy(d1)
35
36
    for key, value in six.iteritems(d2):
37
        if isinstance(value, dict):
38
            result[key] = merge_dicts(result[key], value)
39
        elif key not in result or value is not None:
40
            result[key] = value
41
42
    return result
43