Completed
Push — master ( 71ae82...8cfcf4 )
by Thomas
01:04
created

doorpi.status.status_lib.get()   F

Complexity

Conditions 12

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 12
dl 0
loc 31
rs 2.7855

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
13
        webserver = kwargs['DoorPiObject'].webserver
14
15
        status = {}
16
        for name_requested in kwargs['name']:
17
            if name_requested in 'config_status':
18
                status['config_status'] = webserver.config_status
19
20
            if name_requested in 'session_ids':
21
                status['session_ids'] = webserver.sessions.session_ids
22
23
            if name_requested in 'sessions':
24
                status['sessions'] = webserver.sessions.sessions
25
26
            if name_requested in 'running':
27
                status['running'] = True if webserver and webserver.keep_running else False
28
29
            if name_requested in 'server_name':
30
                status['server_name'] = webserver.server_name
31
32
            if name_requested in 'server_port':
33
                status['server_port'] = webserver.server_port
34
35
        return status
36
    except Exception as exp:
37
        logger.exception(exp)
38
        return {'Error': 'could not create '+str(__name__)+' object - '+str(exp)}
39
40
def is_active(doorpi_object):
41
    return True if doorpi_object.webserver else False
42