Conditions | 13 |
Total Lines | 24 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Complex classes like tcllib.devlist.DevList.print_prd_diff() 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 | # -*- coding: utf-8 -*- |
||
42 | @staticmethod |
||
43 | def print_prd_diff(old_prds, new_prds): |
||
44 | added_prds = [prd for prd in new_prds if prd not in old_prds] |
||
45 | removed_prds = [prd for prd in old_prds if prd not in new_prds] |
||
46 | for prd in removed_prds: |
||
47 | print("> Removed device {} (was at {} / OTA: {}).".format(ansi.RED + prd + ansi.RESET, old_prds[prd]["last_full"], old_prds[prd]["last_ota"])) |
||
1 ignored issue
–
show
|
|||
48 | for prd in added_prds: |
||
49 | print("> New device {} ({} / OTA: {}).".format(ansi.GREEN + prd + ansi.RESET, new_prds[prd]["last_full"], new_prds[prd]["last_ota"])) |
||
1 ignored issue
–
show
|
|||
50 | for prd, pdata in new_prds.items(): |
||
51 | if prd in added_prds: |
||
52 | continue |
||
53 | odata = old_prds[prd] |
||
54 | if pdata["last_full"] != odata["last_full"] and pdata["last_ota"] != odata["last_ota"]: |
||
1 ignored issue
–
show
|
|||
55 | print("> {}: {} ⇨ {} (OTA: {} ⇨ {})".format( |
||
56 | prd, |
||
57 | ansi.CYAN_DARK + str(odata["last_full"]) + ansi.RESET, |
||
58 | ansi.CYAN + str(pdata["last_full"]) + ansi.RESET, |
||
59 | ansi.YELLOW_DARK + str(odata["last_ota"]) + ansi.RESET, |
||
60 | ansi.YELLOW + str(pdata["last_ota"]) + ansi.RESET |
||
61 | )) |
||
62 | elif pdata["last_full"] != odata["last_full"]: |
||
63 | print("> {}: {} ⇨ {} (FULL)".format(prd, ansi.CYAN_DARK + str(odata["last_full"]) + ansi.RESET, ansi.CYAN + str(pdata["last_full"]) + ansi.RESET)) |
||
1 ignored issue
–
show
|
|||
64 | elif pdata["last_ota"] != odata["last_ota"]: |
||
65 | print("> {}: {} ⇨ {} (OTA)".format(prd, ansi.YELLOW_DARK + str(odata["last_ota"]) + ansi.RESET, ansi.YELLOW + str(pdata["last_ota"]) + ansi.RESET)) |
||
1 ignored issue
–
show
|
|||
66 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.