def main_window(self): # initiating the graphs self.graphs = OrderedDict() self.summaries = OrderedDict() # TODO: Update to find sensors automatically freq_source = FreqSource(is_admin) self.graphs[freq_source.get_source_name()] = StuiBarGraph(freq_source, 'freq light', 'freq dark', 'freq light smooth', 'freq dark smooth') self.summaries[freq_source.get_source_name()] = SummaryTextList(freq_source) util_source = UtilSource() self.graphs[util_source.get_source_name()] = StuiBarGraph(util_source, 'util light', 'util dark', 'util light smooth', 'util dark smooth') self.summaries[util_source.get_source_name()] = SummaryTextList(util_source) temp_source = TemperatureSource(self.custom_temp) alert_colors = ['high temp light', 'high temp dark', 'high temp light smooth', 'high temp dark smooth'] self.graphs[temp_source.get_source_name()] = StuiBarGraph(temp_source, 'temp light', 'temp dark', 'temp light smooth', 'temp dark smooth', alert_colors=alert_colors) self.summaries[temp_source.get_source_name()] = SummaryTextList(temp_source, 'high temp txt') rapl_power_source = RaplPowerSource() self.graphs[rapl_power_source.get_source_name()] = StuiBarGraph(rapl_power_source, 'power dark', 'power light', 'power dark smooth', 'power light smooth') self.summaries[rapl_power_source.get_source_name()] = SummaryTextList(rapl_power_source) # only interested in available graph self.available_graphs = OrderedDict((key, val) for key, val in self.graphs.items() if val.get_is_available()) self.available_summaries = OrderedDict((key, val) for key, val in self.summaries.items() if val.get_is_available()) self.visible_graphs = self.available_graphs.copy() self.show_graphs() cpu_stats = self.cpu_stats() graph_controls = self.graph_controls() graph_stats = self.graph_stats() text_col = ViListBox(urwid.SimpleListWalker(cpu_stats + graph_controls + [urwid.Divider()] + graph_stats)) vline = urwid.AttrWrap(urwid.SolidFill(u'\u2502'), 'line') w = urwid.Columns([ ('fixed', 20, text_col), ('fixed', 1, vline), ('weight', 2, self.graph_place_holder), ], dividechars=1, focus_column=0) w = urwid.Padding(w, ('fixed left', 1), ('fixed right', 0)) w = urwid.AttrWrap(w, 'body') w = urwid.LineBox(w) w = urwid.AttrWrap(w, 'line') self.main_window_w = w return self.main_window_w
def main(): args = get_args() # Print version and exit if args.version: print(VERSION_MESSAGE) exit(0) # Setup logging util global log_file level = "" log_file = DEFAULT_LOG_FILE if args.debug_run: args.debug = True if args.debug or args.debug_file is not None: level = logging.DEBUG if args.debug_file is not None: log_file = args.debug_file log_formatter = logging.Formatter( "%(asctime)s [%(funcName)s()] [%(levelname)-5.5s] %(message)s") root_logger = logging.getLogger() file_handler = logging.FileHandler(log_file) file_handler.setFormatter(log_formatter) root_logger.addHandler(file_handler) root_logger.setLevel(level) global is_admin try: is_admin = os.getuid() == 0 except (AttributeError): is_admin = ctypes.windll.shell32.IsUserAnAdmin() != 0 if not is_admin: logging.info("Started without root permissions") if args.terminal or args.json: logging.info("Printing single line to terminal") sources = [ FreqSource(is_admin), TempSource(args.custom_temp), UtilSource(), RaplPowerSource(), FanSource(args.custom_fan) ] if args.terminal: output_to_terminal(sources) elif args.json: output_to_json(sources) global graph_controller graph_controller = GraphController(args) graph_controller.main()
def __init__(self, controller): # constants self.left_margin = 0 self.top_margin = 0 # main control self.controller = controller self.main_window_w = [] # general urwid items clock_text = seconds_to_text(self.controller.stress_time) self.clock_view = urwid.Text(('bold text', clock_text), align="center") self.refresh_rate_ctrl = urwid.Edit(('bold text', u'Refresh[s]:'), self.controller.refresh_rate) self.hline = urwid.AttrWrap(urwid.SolidFill(u'_'), 'line') self.mode_buttons = [] # Visible graphs are the graphs currently displayed, this is a # subset of the available graphs for display self.visible_graphs = {} self.graph_place_holder = urwid.WidgetPlaceholder(urwid.Pile([])) # construct sources possible_source = [TempSource(self.controller.temp_thresh), FreqSource(), UtilSource(), RaplPowerSource()] self.source_list = [s for s in possible_source if s.get_is_available()] # construct the variouse menus during init phase self.stress_menu = StressMenu(self.on_menu_close) self.help_menu = HelpMenu(self.on_menu_close) self.about_menu = AboutMenu(self.on_menu_close) self.sensors_menu = SensorsMenu(self.on_sensors_menu_close, self.source_list) self.global_data = GlobalData(is_admin) self.stress_menu.sqrt_workers = str(self.global_data.num_cpus) # call super urwid.WidgetPlaceholder.__init__(self, self.main_window()) urwid.connect_signal(self.refresh_rate_ctrl, 'change', self.update_refresh_rate)
def main_window(self): # initiating the graphs self.graphs = OrderedDict() self.summaries = OrderedDict() # TODO: Update to find sensors automatically ''' freq_source = FreqSource(is_admin) self.graphs[freq_source.get_source_name()] = StuiBarGraph( freq_source, 'freq light', 'freq dark', 'freq light smooth', 'freq dark smooth' ) self.summaries[freq_source.get_source_name()] = SummaryTextList( freq_source ) ''' util_source = UtilSource() self.graphs[util_source.get_source_name()] = StuiBarGraph( util_source, 'util light', 'util dark', 'util light smooth', 'util dark smooth') self.summaries[util_source.get_source_name()] = SummaryTextList( util_source) temp_source = TempSource(self.controller.custom_temp, self.controller.temp_thresh) if self.controller.script_hooks_enabled: temp_source.add_edge_hook( self.controller.script_loader.load_script( temp_source.__class__.__name__, 30000) ) # Invoke threshold script every 30s while threshold is exceeded. alert_colors = [ 'high temp light', 'high temp dark', 'high temp light smooth', 'high temp dark smooth' ] self.graphs[temp_source.get_source_name()] = StuiBarGraph( temp_source, 'temp light', 'temp dark', 'temp light smooth', 'temp dark smooth', alert_colors=alert_colors) self.summaries[temp_source.get_source_name()] = SummaryTextList( temp_source, 'high temp txt') mem_source = MemorySource() self.graphs[mem_source.get_source_name()] = StuiBarGraph( mem_source, 'power dark', 'power light', 'power dark smooth', 'power light smooth') self.summaries[mem_source.get_source_name()] = SummaryTextList( mem_source) #fan_source = FanSource(self.controller.args.custom_fan) #self.summaries[fan_source.get_source_name()] = SummaryTextList( # fan_source) # only interested in available graph self.available_graphs = OrderedDict( (key, val) for key, val in self.graphs.items() if val.get_is_available()) self.available_summaries = OrderedDict( (key, val) for key, val in self.summaries.items() if val.get_is_available()) self.visible_graphs = self.available_graphs.copy() # Remove graphs from shown graphs if user configed them out # TODO: get this information from the state conf = self.controller.conf for graph_name in self.available_graphs.keys(): try: if conf.getboolean('GraphControll', graph_name) is False: del self.visible_graphs[graph_name] except (AttributeError, configparser.NoOptionError, ValueError, configparser.NoSectionError): pass self.show_graphs() cpu_stats = self.cpu_stats() graph_controls = self.graph_controls(conf) graph_stats = self.graph_stats() text_col = ViListBox( urwid.SimpleListWalker(cpu_stats + graph_controls + [urwid.Divider()] + graph_stats)) vline = urwid.AttrWrap(urwid.SolidFill(u'\u2502'), 'line') w = urwid.Columns([ ('fixed', 20, text_col), ('fixed', 1, vline), ('weight', 2, self.graph_place_holder), ], dividechars=1, focus_column=0) w = urwid.Padding(w, ('fixed left', 1), ('fixed right', 0)) w = urwid.AttrWrap(w, 'body') w = urwid.LineBox(w) w = urwid.AttrWrap(w, 'line') self.main_window_w = w return self.main_window_w
def main_window(self): user_config_path = None if not user_config_dir_exists(): user_config_path = make_user_config_dir() else: user_config_path = get_user_config_path() script_hooks_enabled = True if user_config_path is None: logging.warn('Failed to find or create scripts directory, proceeding without scripting support') script_hooks_enabled = False else: self.script_loader = ScriptHookLoader(user_config_path) # initiating the graphs self.graphs = OrderedDict() self.summaries = OrderedDict() # TODO: Update to find sensors automatically freq_source = FreqSource(is_admin) self.graphs[freq_source.get_source_name()] = StuiBarGraph(freq_source, 'freq light', 'freq dark', 'freq light smooth', 'freq dark smooth') self.summaries[freq_source.get_source_name()] = SummaryTextList(freq_source) util_source = UtilSource() self.graphs[util_source.get_source_name()] = StuiBarGraph(util_source, 'util light', 'util dark', 'util light smooth', 'util dark smooth') self.summaries[util_source.get_source_name()] = SummaryTextList(util_source) temp_source = TemperatureSource(self.custom_temp) if script_hooks_enabled: temp_source.add_edge_hook(self.script_loader.load_script(temp_source.__class__.__name__, 30000)) # Invoke threshold script every 30s while threshold is exceeded. alert_colors = ['high temp light', 'high temp dark', 'high temp light smooth', 'high temp dark smooth'] self.graphs[temp_source.get_source_name()] = StuiBarGraph(temp_source, 'temp light', 'temp dark', 'temp light smooth', 'temp dark smooth', alert_colors=alert_colors) self.summaries[temp_source.get_source_name()] = SummaryTextList(temp_source, 'high temp txt') rapl_power_source = RaplPowerSource() self.graphs[rapl_power_source.get_source_name()] = StuiBarGraph(rapl_power_source, 'power dark', 'power light', 'power dark smooth', 'power light smooth') self.summaries[rapl_power_source.get_source_name()] = SummaryTextList(rapl_power_source) fan_source = FanSource(self.custom_fan) self.summaries[fan_source.get_source_name()] = SummaryTextList(fan_source) # only interested in available graph self.available_graphs = OrderedDict((key, val) for key, val in self.graphs.items() if val.get_is_available()) self.available_summaries = OrderedDict((key, val) for key, val in self.summaries.items() if val.get_is_available()) self.visible_graphs = self.available_graphs.copy() self.show_graphs() cpu_stats = self.cpu_stats() graph_controls = self.graph_controls() graph_stats = self.graph_stats() text_col = ViListBox(urwid.SimpleListWalker(cpu_stats + graph_controls + [urwid.Divider()] + graph_stats)) vline = urwid.AttrWrap(urwid.SolidFill(u'\u2502'), 'line') w = urwid.Columns([ ('fixed', 20, text_col), ('fixed', 1, vline), ('weight', 2, self.graph_place_holder), ], dividechars=1, focus_column=0) w = urwid.Padding(w, ('fixed left', 1), ('fixed right', 0)) w = urwid.AttrWrap(w, 'body') w = urwid.LineBox(w) w = urwid.AttrWrap(w, 'line') self.main_window_w = w return self.main_window_w