Conditions | 12 |
Total Lines | 31 |
Lines | 0 |
Ratio | 0 % |
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 |
||
8 | def get(*args, **kwargs): |
||
|
|||
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 | |||
42 |