(self)
Save the current configuration to a user config file
Save the current configuration to a user config file
Save the current configuration to a user config file
def save_settings(self):
        """ Save the current configuration to a user config file """
        def _save_displayed_setting(conf, submenu):
            items = []
            if (submenu == "Graphs"):
                items = self.view.graphs_menu.active_sensors.items()
            elif (submenu == "Summaries"):
                items = self.view.summary_menu.active_sensors.items()

            for source, visible_sensors in items:
                section = source + "," + submenu
                conf.add_section(section)

                sources = self.sources
                logging.debug("Saving settings for %s", source)
                logging.debug("Visible sensors %s", visible_sensors)
                # TODO: consider changing sensors_list to dict
                curr_sensor = [x for x in sources if
                               x.get_source_name() == source][0]
                sensor_list = curr_sensor.get_sensor_list()
                for sensor_id, sensor in enumerate(sensor_list):
                    try:
                        conf.set(section, sensor, str(
                            visible_sensors[sensor_id]))
                    except IndexError:
                        conf.set(section, sensor, str(True))

        if not user_config_dir_exists():
            make_user_config_dir()

        conf = configparser.ConfigParser()
        config_file = get_user_config_file()
        with open(config_file, 'w') as cfgfile:
            conf.add_section('GraphControll')
            # Save the configured refresh rete
            conf.set('GraphControll', 'refresh', str(
                self.refresh_rate))
            # Save the configured UTF8 setting
            conf.set('GraphControll', 'UTF8', str(
                self.smooth_graph_mode))
            # Save the configured t_thresh
            if self.temp_thresh:
                conf.set('GraphControll', 'TTHRESH', str(
                    self.temp_thresh))

            _save_displayed_setting(conf, "Graphs")
            _save_displayed_setting(conf, "Summaries")
            conf.write(cfgfile)
def save_settings ( self ) : def _save_displayed_setting ( conf , submenu ) : items = [ ] if ( submenu == "Graphs" ) : items = self . view . graphs_menu . active_sensors . items ( ) elif ( submenu == "Summaries" ) : items = self . view . summary_menu . active_sensors . items ( ) for source , visible_sensors in items : section = source + "," + submenu conf . add_section ( section ) sources = self . sources logging . debug ( "Saving settings for %s" , source ) logging . debug ( "Visible sensors %s" , visible_sensors ) # TODO: consider changing sensors_list to dict curr_sensor = [ x for x in sources if x . get_source_name ( ) == source ] [ 0 ] sensor_list = curr_sensor . get_sensor_list ( ) for sensor_id , sensor in enumerate ( sensor_list ) : try : conf . set ( section , sensor , str ( visible_sensors [ sensor_id ] ) ) except IndexError : conf . set ( section , sensor , str ( True ) ) if not user_config_dir_exists ( ) : make_user_config_dir ( ) conf = configparser . ConfigParser ( ) config_file = get_user_config_file ( ) with open ( config_file , 'w' ) as cfgfile : conf . add_section ( 'GraphControll' ) # Save the configured refresh rete conf . set ( 'GraphControll' , 'refresh' , str ( self . refresh_rate ) ) # Save the configured UTF8 setting conf . set ( 'GraphControll' , 'UTF8' , str ( self . smooth_graph_mode ) ) # Save the configured t_thresh if self . temp_thresh : conf . set ( 'GraphControll' , 'TTHRESH' , str ( self . temp_thresh ) ) _save_displayed_setting ( conf , "Graphs" ) _save_displayed_setting ( conf , "Summaries" ) conf . write ( cfgfile )