Conditions | 10 |
Total Lines | 19 |
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 | 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 | |||
30 |