| Conditions | 9 |
| Total Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | # -*- coding: utf-8 -*- |
||
| 68 | def msg_curse(self, args=None): |
||
| 69 | """Return the dict to display in the curse interface.""" |
||
| 70 | # Init the return message |
||
| 71 | ret = [] |
||
| 72 | |||
| 73 | # Only process if stats exist and display plugin enable... |
||
| 74 | if args.disable_process: |
||
| 75 | msg = "PROCESSES DISABLED (press 'z' to display)" |
||
| 76 | ret.append(self.curse_add_line(msg)) |
||
| 77 | return ret |
||
| 78 | |||
| 79 | if not self.stats: |
||
| 80 | return ret |
||
| 81 | |||
| 82 | # Display the filter (if it exists) |
||
| 83 | if glances_processes.process_filter is not None: |
||
| 84 | msg = 'Processes filter:' |
||
| 85 | ret.append(self.curse_add_line(msg, "TITLE")) |
||
| 86 | msg = ' {0} '.format(glances_processes.process_filter) |
||
| 87 | ret.append(self.curse_add_line(msg, "FILTER")) |
||
| 88 | msg = '(\'ENTER\' to edit, \'E\' to reset)' |
||
| 89 | ret.append(self.curse_add_line(msg)) |
||
| 90 | ret.append(self.curse_new_line()) |
||
| 91 | |||
| 92 | # Build the string message |
||
| 93 | # Header |
||
| 94 | msg = 'TASKS' |
||
| 95 | ret.append(self.curse_add_line(msg, "TITLE")) |
||
| 96 | # Compute processes |
||
| 97 | other = self.stats['total'] |
||
| 98 | msg = '{0:>4}'.format(self.stats['total']) |
||
| 99 | ret.append(self.curse_add_line(msg)) |
||
| 100 | |||
| 101 | if 'thread' in self.stats: |
||
| 102 | msg = ' ({0} thr),'.format(self.stats['thread']) |
||
| 103 | ret.append(self.curse_add_line(msg)) |
||
| 104 | |||
| 105 | if 'running' in self.stats: |
||
| 106 | other -= self.stats['running'] |
||
| 107 | msg = ' {0} run,'.format(self.stats['running']) |
||
| 108 | ret.append(self.curse_add_line(msg)) |
||
| 109 | |||
| 110 | if 'sleeping' in self.stats: |
||
| 111 | other -= self.stats['sleeping'] |
||
| 112 | msg = ' {0} slp,'.format(self.stats['sleeping']) |
||
| 113 | ret.append(self.curse_add_line(msg)) |
||
| 114 | |||
| 115 | msg = ' {0} oth '.format(other) |
||
| 116 | ret.append(self.curse_add_line(msg)) |
||
| 117 | |||
| 118 | # Display sort information |
||
| 119 | if glances_processes.auto_sort: |
||
| 120 | msg = 'sorted automatically' |
||
| 121 | ret.append(self.curse_add_line(msg)) |
||
| 122 | msg = ' by {0}'.format(glances_processes.sort_key) |
||
| 123 | ret.append(self.curse_add_line(msg)) |
||
| 124 | else: |
||
| 125 | msg = 'sorted by {0}'.format(glances_processes.sort_key) |
||
| 126 | ret.append(self.curse_add_line(msg)) |
||
| 127 | ret[-1]["msg"] += ", %s view" % ("tree" if glances_processes.is_tree_enabled() else "flat") |
||
| 128 | # if args.disable_irix: |
||
| 129 | # ret[-1]["msg"] += " - IRIX off" |
||
| 130 | |||
| 131 | # Return the message with decoration |
||
| 132 | return ret |
||
| 133 |