Conditions | 13 |
Total Lines | 24 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Complex classes like tcllib.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 | #!/usr/bin/env python3 |
||
50 | def print_prd_diff(old_prds, new_prds): |
||
51 | """Print changes between old and new databases.""" |
||
52 | added_prds = [prd for prd in new_prds if prd not in old_prds] |
||
53 | removed_prds = [prd for prd in old_prds if prd not in new_prds] |
||
54 | for prd in removed_prds: |
||
55 | 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
|
|||
56 | for prd in added_prds: |
||
57 | print("> New device {} ({} / OTA: {}).".format(ansi.GREEN + prd + ansi.RESET, new_prds[prd]["last_full"], new_prds[prd]["last_ota"])) |
||
1 ignored issue
–
show
|
|||
58 | for prd, pdata in new_prds.items(): |
||
59 | if prd in added_prds: |
||
60 | continue |
||
61 | odata = old_prds[prd] |
||
62 | if pdata["last_full"] != odata["last_full"] and pdata["last_ota"] != odata["last_ota"]: |
||
63 | print("> {}: {} ⇨ {} (OTA: {} ⇨ {})".format( |
||
64 | prd, |
||
65 | ansi.CYAN_DARK + str(odata["last_full"]) + ansi.RESET, |
||
66 | ansi.CYAN + str(pdata["last_full"]) + ansi.RESET, |
||
67 | ansi.YELLOW_DARK + str(odata["last_ota"]) + ansi.RESET, |
||
68 | ansi.YELLOW + str(pdata["last_ota"]) + ansi.RESET |
||
69 | )) |
||
70 | elif pdata["last_full"] != odata["last_full"]: |
||
71 | 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
|
|||
72 | elif pdata["last_ota"] != odata["last_ota"]: |
||
73 | 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
|
|||
74 |
This check looks for lines that are too long. You can specify the maximum line length.