def _serve_section_info(self, request): path = '{}/{}'.format(self.PLUGIN_LOGDIR, shared_config.SECTION_INFO_FILENAME) info = file_system_tools.read_pickle(path, default=self.most_recent_info) self.most_recent_info = info return http_util.Respond(request, info, 'application/json')
def _serve_section_info(self, request): path = "{}/{}".format(self.PLUGIN_LOGDIR, shared_config.SECTION_INFO_FILENAME) with self._lock: default = self.most_recent_info info = file_system_tools.read_pickle(path, default=default) if info is not default: with self._lock: self.most_recent_info = info return http_util.Respond(request, info, "application/json")
def _serve_section_info(self, request): path = '{}/{}'.format( self.PLUGIN_LOGDIR, shared_config.SECTION_INFO_FILENAME) with self._lock: default = self.most_recent_info info = file_system_tools.read_pickle(path, default=default) if info is not default: with self._lock: self.most_recent_info = info return http_util.Respond(request, info, 'application/json')
def _get_config(self): '''Reads the config file from disk or creates a new one.''' filename = '{}/{}'.format(self.PLUGIN_LOGDIR, CONFIG_FILENAME) modified_time = os.path.getmtime(filename) if modified_time != self.config_last_modified_time: config = read_pickle(filename, default=self.previous_config) self.previous_config = config else: config = self.previous_config self.config_last_modified_time = modified_time return config
def is_config_writable(self): try: if not tf.gfile.Exists(self.PLUGIN_LOGDIR): tf.gfile.MakeDirs(self.PLUGIN_LOGDIR) config_filename = '{}/{}'.format( self.PLUGIN_LOGDIR, shared_config.CONFIG_FILENAME) with self._config_file_lock: file_system_tools.write_pickle( file_system_tools.read_pickle( config_filename, shared_config.DEFAULT_CONFIG), config_filename) return True except tf.errors.PermissionDeniedError as e: tf.logging.warning( 'Unable to write Beholder config, controls will be disabled: %s', e) return False
def is_config_writable(self): try: if not tf.io.gfile.exists(self.PLUGIN_LOGDIR): tf.io.gfile.makedirs(self.PLUGIN_LOGDIR) config_filename = "{}/{}".format(self.PLUGIN_LOGDIR, shared_config.CONFIG_FILENAME) with self._config_file_lock: file_system_tools.write_pickle( file_system_tools.read_pickle( config_filename, shared_config.DEFAULT_CONFIG), config_filename, ) return True except tf.errors.PermissionDeniedError as e: logger.warn( "Unable to write Beholder config, controls will be disabled: %s", e, ) return False