Completed
Push — master ( 51a4d2...0dd74a )
by Thomas
01:56 queued 47s
created

doorpi.status.status_lib.get()   C

Complexity

Conditions 10

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 10
dl 0
loc 19
rs 6

How to fix   Complexity   

Complexity

Complex classes like doorpi.status.status_lib.get() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
import logging
5
logger = logging.getLogger(__name__)
6
logger.debug("%s loaded", __name__)
7
8
def get(*args, **kwargs):
0 ignored issues
show
Unused Code introduced by Thomas
The argument args seems to be unused.
Loading history...
9
    try:
10
        if len(kwargs['name']) == 0: kwargs['name'] = ['']
11
        if len(kwargs['value']) == 0: kwargs['value'] = ['']
12
        return_dict = {}
13
        for section_request in kwargs['name']:
14
            for section in kwargs['DoorPiObject'].config.get_sections(section_request):
15
                return_dict[section] = {}
16
                for value_request in kwargs['value']:
17
                    for key in kwargs['DoorPiObject'].config.get_keys(section, value_request):
18
                        return_dict[section][key] = kwargs['DoorPiObject'].config.get(section, key)
19
20
        for section in return_dict.keys():
21
            if len(return_dict[section]) == 0: del return_dict[section]
22
23
        return return_dict
24
    except Exception as exp:
25
        logger.exception(exp)
26
        return {'Error': 'could not create '+str(__name__)+' object - '+str(exp)}
27
28
def is_active(doorpi_object):
29
    return True if doorpi_object.config else False
30