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 = "" if args.debug: level = logging.DEBUG log_file = DEFAULT_LOG_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.csv: logging.info("Printing output to csv " + DEFAULT_CSV_FILE) if args.terminal or args.json: logging.info("Printing single line to terminal") sources = [ FreqSource(is_admin), TemperatureSource(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 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