Conditions | 13 |
Total Lines | 30 |
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 | event_handler = kwargs['DoorPiObject'].event_handler |
||
14 | |||
15 | status = {} |
||
16 | for name_requested in kwargs['name']: |
||
17 | if name_requested in 'sources': |
||
18 | status['sources'] = event_handler.sources |
||
19 | if name_requested in 'events': |
||
20 | status['events'] = event_handler.events |
||
21 | if name_requested in 'events_by_source': |
||
22 | status['events_by_source'] = event_handler.events_by_source |
||
23 | if name_requested in 'actions': |
||
24 | status['actions'] = {} |
||
25 | for event in event_handler.actions: |
||
26 | status['actions'][event] = [] |
||
27 | for action in event_handler.actions[event]: |
||
28 | status['actions'][event].append(str(action)) |
||
29 | if name_requested in 'threads': |
||
30 | status['threads'] = str(event_handler.threads) |
||
31 | if name_requested in 'idle': |
||
32 | status['idle'] = event_handler.idle |
||
33 | |||
34 | return status |
||
35 | except Exception as exp: |
||
36 | logger.exception(exp) |
||
37 | return {'Error': 'could not create '+str(__name__)+' object - '+str(exp)} |
||
38 | |||
41 |