def msg_curse(self, args=None, max_width=10): """Return the list to display in the UI.""" # Init the return message ret = [] # Only process if stats exist... if not self.stats or args.disable_quicklook: return ret # Define the bar bar = Bar(max_width, pre_char='|', post_char='|', empty_char=' ') # Build the string message for key in ['cpu', 'mem', 'swap']: bar.percent = self.stats[key] msg = '{0:>4} '.format(key.upper()) ret.append(self.curse_add_line(msg)) msg = '{0}'.format(bar) ret.append(self.curse_add_line(msg, self.get_views(key=key, option='decoration'))) ret.append(self.curse_new_line()) # Return the message with decoration return ret
def msg_curse(self, args=None, max_width=10): """Return the list to display in the UI.""" # Init the return message ret = [] # Only process if stats exist... if not self.stats or args.disable_quicklook: return ret # Define the bar bar = Bar(max_width) # Build the string message if 'cpu_name' in self.stats: msg = '{0} - {1:.2f}/{2:.2f}GHz'.format( self.stats['cpu_name'], self._hz_to_ghz(self.stats['cpu_hz_current']), self._hz_to_ghz(self.stats['cpu_hz'])) if len(msg) - 6 <= max_width: ret.append(self.curse_add_line(msg)) ret.append(self.curse_new_line()) for key in ['cpu', 'mem', 'swap']: if key == 'cpu' and args.percpu: for cpu in self.stats['percpu']: bar.percent = cpu['total'] if cpu[cpu['key']] < 10: msg = '{0:3}{1} '.format(key.upper(), cpu['cpu_number']) else: msg = '{0:4} '.format(cpu['cpu_number']) ret.append(self.curse_add_line(msg)) ret.append( self.curse_add_line(bar.pre_char, decoration='BOLD')) ret.append( self.curse_add_line( str(bar), self.get_views(key=key, option='decoration'))) ret.append( self.curse_add_line(bar.post_char, decoration='BOLD')) ret.append(self.curse_add_line(' ')) ret.append(self.curse_new_line()) else: bar.percent = self.stats[key] msg = '{0:4} '.format(key.upper()) ret.append(self.curse_add_line(msg)) ret.append(self.curse_add_line(bar.pre_char, decoration='BOLD')) ret.append( self.curse_add_line( str(bar), self.get_views(key=key, option='decoration'))) ret.append( self.curse_add_line(bar.post_char, decoration='BOLD')) ret.append(self.curse_add_line(' ')) ret.append(self.curse_new_line()) # Return the message with decoration return ret
def test_011_output_bars_must_be_between_0_and_100_percent(self): """Test quick look plugin.""" print('INFO: [TEST_011] Test progress bar') bar = Bar(size=1) with self.assertRaises(AssertionError): bar.percent = -1 bar.percent = 101 # 0 - 100 is an inclusive range, so these should not error. bar.percent = 0 bar.percent = 100
def msg_curse(self, args=None, max_width=10): """Return the list to display in the UI.""" # Init the return message ret = [] # Only process if stats exist... if not self.stats or args.disable_quicklook: return ret # Define the bar bar = Bar(max_width) # Build the string message if 'cpu_name' in self.stats: msg = '{0} - {1:.2f}/{2:.2f}GHz'.format(self.stats['cpu_name'], self._hz_to_ghz(self.stats['cpu_hz_current']), self._hz_to_ghz(self.stats['cpu_hz'])) if len(msg) - 6 <= max_width: ret.append(self.curse_add_line(msg)) ret.append(self.curse_new_line()) for key in ['cpu', 'mem', 'swap']: if key == 'cpu' and args.percpu: for cpu in self.stats['percpu']: bar.percent = cpu['total'] if cpu[cpu['key']] < 10: msg = '{0:3}{1} '.format(key.upper(), cpu['cpu_number']) else: msg = '{0:4} '.format(cpu['cpu_number']) ret.append(self.curse_add_line(msg)) ret.append(self.curse_add_line(bar.pre_char, decoration='BOLD')) ret.append(self.curse_add_line(str(bar), self.get_views(key=key, option='decoration'))) ret.append(self.curse_add_line(bar.post_char, decoration='BOLD')) ret.append(self.curse_add_line(' ')) ret.append(self.curse_new_line()) else: bar.percent = self.stats[key] msg = '{0:4} '.format(key.upper()) ret.append(self.curse_add_line(msg)) ret.append(self.curse_add_line(bar.pre_char, decoration='BOLD')) ret.append(self.curse_add_line(str(bar), self.get_views(key=key, option='decoration'))) ret.append(self.curse_add_line(bar.post_char, decoration='BOLD')) ret.append(self.curse_add_line(' ')) ret.append(self.curse_new_line()) # Return the message with decoration return ret
def msg_curse(self, args=None, max_width=10): """Return the list to display in the UI.""" # Init the return message ret = [] # Only process if stats exist... if not self.stats or self.is_disable(): return ret # Define the bar bar = Bar(max_width) # Build the string message if 'cpu_name' in self.stats and 'cpu_hz_current' in self.stats and 'cpu_hz' in self.stats: msg_name = '{} - '.format(self.stats['cpu_name']) msg_freq = '{:.2f}/{:.2f}GHz'.format( self._hz_to_ghz(self.stats['cpu_hz_current']), self._hz_to_ghz(self.stats['cpu_hz'])) if len(msg_name + msg_freq) - 6 <= max_width: ret.append(self.curse_add_line(msg_name)) ret.append(self.curse_add_line(msg_freq)) ret.append(self.curse_new_line()) for key in ['cpu', 'mem', 'swap']: if key == 'cpu' and args.percpu: for cpu in self.stats['percpu']: bar.percent = cpu['total'] if cpu[cpu['key']] < 10: msg = '{:3}{} '.format(key.upper(), cpu['cpu_number']) else: msg = '{:4} '.format(cpu['cpu_number']) ret.extend(self._msg_create_line(msg, bar, key)) ret.append(self.curse_new_line()) else: bar.percent = self.stats[key] msg = '{:4} '.format(key.upper()) ret.extend(self._msg_create_line(msg, bar, key)) ret.append(self.curse_new_line()) # Remove the last new line ret.pop() # Return the message with decoration return ret
def msg_curse(self, args=None, max_width=10): """Return the list to display in the UI.""" # Init the return message ret = [] # Only process if stats exist... if not self.stats or self.is_disable(): return ret # Define the bar bar = Bar(max_width) # Build the string message if 'cpu_name' in self.stats and 'cpu_hz_current' in self.stats and 'cpu_hz' in self.stats: msg_name = '{} - '.format(self.stats['cpu_name']) msg_freq = '{:.2f}/{:.2f}GHz'.format(self._hz_to_ghz(self.stats['cpu_hz_current']), self._hz_to_ghz(self.stats['cpu_hz'])) if len(msg_name + msg_freq) - 6 <= max_width: ret.append(self.curse_add_line(msg_name)) ret.append(self.curse_add_line(msg_freq)) ret.append(self.curse_new_line()) for key in ['cpu', 'mem', 'swap']: if key == 'cpu' and args.percpu: for cpu in self.stats['percpu']: bar.percent = cpu['total'] if cpu[cpu['key']] < 10: msg = '{:3}{} '.format(key.upper(), cpu['cpu_number']) else: msg = '{:4} '.format(cpu['cpu_number']) ret.extend(self._msg_create_line(msg, bar, key)) ret.append(self.curse_new_line()) else: bar.percent = self.stats[key] msg = '{:4} '.format(key.upper()) ret.extend(self._msg_create_line(msg, bar, key)) ret.append(self.curse_new_line()) # Remove the last new line ret.pop() # Return the message with decoration return ret
def test_099_output_bars_must_be_between_0_and_100_percent(self): """Test quick look plugin. > bar.min_value 0 > bar.max_value 100 > bar.percent = -1 > bar.percent 0 > bar.percent = 101 > bar.percent 100 """ print('INFO: [TEST_099] Test progress bar') bar = Bar(size=1) bar.percent = -1 self.assertLessEqual(bar.percent, bar.min_value) bar.percent = 101 self.assertGreaterEqual(bar.percent, bar.max_value)
def msg_curse(self, args=None, max_width=10): """Return the list to display in the UI.""" # Init the return message ret = [] # Only process if stats exist... if not self.stats or args.disable_quicklook: return ret # Define the bar bar = Bar(max_width) # Build the string message for key in ['cpu', 'mem', 'swap']: bar.percent = self.stats[key] msg = '{0:4} '.format(key.upper()) ret.append(self.curse_add_line(msg)) ret.append(self.curse_add_line(bar.pre_char, decoration='BOLD')) ret.append(self.curse_add_line(str(bar), self.get_views(key=key, option='decoration'))) ret.append(self.curse_add_line(bar.post_char, decoration='BOLD')) ret.append(self.curse_new_line()) # Return the message with decoration return ret
def msg_curse(self, args=None, max_width=10): """Return the list to display in the UI.""" # Init the return message ret = [] # Only process if stats exist... if not self.stats or self.is_disable(): return ret # Define the data: Bar (default behavor) or Sparkline sparkline_tag = False if self.args.sparkline and self.history_enable(): data = Sparkline(max_width) sparkline_tag = data.available if not sparkline_tag: # Fallback to bar if Sparkline module is not installed data = Bar(max_width, percentage_char=self.get_conf_value('percentage_char', default=['|'])[0]) # Build the string message if 'cpu_name' in self.stats and 'cpu_hz_current' in self.stats and 'cpu_hz' in self.stats: msg_name = '{} - '.format(self.stats['cpu_name']) msg_freq = '{:.2f}/{:.2f}GHz'.format( self._hz_to_ghz(self.stats['cpu_hz_current']), self._hz_to_ghz(self.stats['cpu_hz'])) if len(msg_name + msg_freq) - 6 <= max_width: ret.append(self.curse_add_line(msg_name)) ret.append(self.curse_add_line(msg_freq)) ret.append(self.curse_new_line()) for key in ['cpu', 'mem', 'swap']: if key == 'cpu' and args.percpu: if sparkline_tag: raw_cpu = self.get_raw_history(item='percpu', nb=data.size) for cpu_index, cpu in enumerate(self.stats['percpu']): if sparkline_tag: # Sparkline display an history data.percents = [ i[1][cpu_index]['total'] for i in raw_cpu ] # A simple padding in order to align metrics to the right data.percents += [None ] * (data.size - len(data.percents)) else: # Bar only the last value data.percent = cpu['total'] if cpu[cpu['key']] < 10: msg = '{:3}{} '.format(key.upper(), cpu['cpu_number']) else: msg = '{:4} '.format(cpu['cpu_number']) ret.extend(self._msg_create_line(msg, data, key)) ret.append(self.curse_new_line()) else: if sparkline_tag: # Sparkline display an history data.percents = [ i[1] for i in self.get_raw_history(item=key, nb=data.size) ] # A simple padding in order to align metrics to the right data.percents += [None] * (data.size - len(data.percents)) else: # Bar only the last value data.percent = self.stats[key] msg = '{:4} '.format(key.upper()) ret.extend(self._msg_create_line(msg, data, key)) ret.append(self.curse_new_line()) # Remove the last new line ret.pop() # Return the message with decoration return ret