| Conditions | 9 |
| Total Lines | 77 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 -*- |
||
| 174 | def msg_curse(self, args=None, max_width=None): |
||
| 175 | """Return the dict to display in the curse interface.""" |
||
| 176 | # Init the return message |
||
| 177 | ret = [] |
||
| 178 | |||
| 179 | # Only process if stats exist and display plugin enable... |
||
| 180 | if not self.stats or self.is_disable(): |
||
| 181 | return ret |
||
| 182 | |||
| 183 | # Max size for the interface name |
||
| 184 | name_max_width = max_width - 13 |
||
| 185 | |||
| 186 | # Header |
||
| 187 | msg = '{:{width}}'.format('DISK I/O', width=name_max_width) |
||
| 188 | ret.append(self.curse_add_line(msg, "TITLE")) |
||
| 189 | if args.diskio_iops: |
||
| 190 | msg = '{:>7}'.format('IOR/s') |
||
| 191 | ret.append(self.curse_add_line(msg)) |
||
| 192 | msg = '{:>7}'.format('IOW/s') |
||
| 193 | ret.append(self.curse_add_line(msg)) |
||
| 194 | else: |
||
| 195 | msg = '{:>7}'.format('R/s') |
||
| 196 | ret.append(self.curse_add_line(msg)) |
||
| 197 | msg = '{:>7}'.format('W/s') |
||
| 198 | ret.append(self.curse_add_line(msg)) |
||
| 199 | # Disk list (sorted by name) |
||
| 200 | for i in self.sorted_stats(): |
||
| 201 | # Hide stats if never be different from 0 (issue #1787) |
||
| 202 | if all([self.get_views(item=i[self.get_key()], key=f, option='hidden') for f in self.hide_zero_fields]): |
||
| 203 | continue |
||
| 204 | # Is there an alias for the disk name ? |
||
| 205 | disk_real_name = i['disk_name'] |
||
| 206 | disk_name = self.has_alias(i['disk_name']) |
||
| 207 | if disk_name is None: |
||
| 208 | disk_name = disk_real_name |
||
| 209 | # New line |
||
| 210 | ret.append(self.curse_new_line()) |
||
| 211 | if len(disk_name) > name_max_width: |
||
| 212 | # Cut disk name if it is too long |
||
| 213 | disk_name = '_' + disk_name[-name_max_width+1:] |
||
| 214 | msg = '{:{width}}'.format(nativestr(disk_name), |
||
| 215 | width=name_max_width+1) |
||
| 216 | ret.append(self.curse_add_line(msg)) |
||
| 217 | if args.diskio_iops: |
||
| 218 | # count |
||
| 219 | txps = self.auto_unit( |
||
| 220 | int(i['read_count'] // i['time_since_update'])) |
||
| 221 | rxps = self.auto_unit( |
||
| 222 | int(i['write_count'] // i['time_since_update'])) |
||
| 223 | msg = '{:>7}'.format(txps) |
||
| 224 | ret.append(self.curse_add_line(msg, |
||
| 225 | self.get_views(item=i[self.get_key()], |
||
| 226 | key='read_count', |
||
| 227 | option='decoration'))) |
||
| 228 | msg = '{:>7}'.format(rxps) |
||
| 229 | ret.append(self.curse_add_line(msg, |
||
| 230 | self.get_views(item=i[self.get_key()], |
||
| 231 | key='write_count', |
||
| 232 | option='decoration'))) |
||
| 233 | else: |
||
| 234 | # Bitrate |
||
| 235 | txps = self.auto_unit( |
||
| 236 | int(i['read_bytes'] // i['time_since_update'])) |
||
| 237 | rxps = self.auto_unit( |
||
| 238 | int(i['write_bytes'] // i['time_since_update'])) |
||
| 239 | msg = '{:>7}'.format(txps) |
||
| 240 | ret.append(self.curse_add_line(msg, |
||
| 241 | self.get_views(item=i[self.get_key()], |
||
| 242 | key='read_bytes', |
||
| 243 | option='decoration'))) |
||
| 244 | msg = '{:>7}'.format(rxps) |
||
| 245 | ret.append(self.curse_add_line(msg, |
||
| 246 | self.get_views(item=i[self.get_key()], |
||
| 247 | key='write_bytes', |
||
| 248 | option='decoration'))) |
||
| 249 | |||
| 250 | return ret |
||
| 251 |