def _get_changes_entities(self): entities_updates = [] files = file_utils.list_files( self.cfg.static_physical.directory, '.yaml') for file_ in files: full_path = self.cfg.static_physical.directory +\ '/' + file_ config = file_utils.load_yaml_file(full_path) if StaticDriver._is_valid_config(config): LOG.warning("Skipped config of new static datasource: {}" .format(file_)) return [] if config: if file_ in self.cache: if str(config) != str(self.cache[file_]): # TODO(alexey_weyl): need also to remove deleted # files from cache old_config = copy.deepcopy(config) self._update_on_existing_entities( self.cache[file_][self.ENTITIES_SECTION], config[self.ENTITIES_SECTION], entities_updates) self._update_on_new_entities( config[self.ENTITIES_SECTION], self.cache[file_][self.ENTITIES_SECTION], entities_updates) self.cache[file_] = old_config else: self.cache[file_] = config entities_updates += \ self._get_entities_from_file(file_, full_path) # iterate over deleted files deleted_files = set(self.cache.keys()) - set(files) for file_ in deleted_files: self._update_on_existing_entities( self.cache[file_][self.ENTITIES_SECTION], {}, entities_updates) del self.cache[file_] return entities_updates
def _get_changes_entities(self): entities_updates = [] files = file_utils.list_files( self.cfg.static_physical.directory, '.yaml') for file_ in files: full_path = self.cfg.static_physical.directory +\ '/' + file_ config = file_utils.load_yaml_file(full_path) if StaticDriver.is_valid_config(config): LOG.warning("Skipped config of new static datasource: {}" .format(file_)) return [] if config: if file_ in self.cache: if str(config) != str(self.cache[file_]): # TODO(alexey_weyl): need also to remove deleted # files from cache old_config = copy.deepcopy(config) self._update_on_existing_entities( self.cache[file_][self.ENTITIES_SECTION], config[self.ENTITIES_SECTION], entities_updates) self._update_on_new_entities( config[self.ENTITIES_SECTION], self.cache[file_][self.ENTITIES_SECTION], entities_updates) self.cache[file_] = old_config else: self.cache[file_] = config entities_updates += \ self._get_entities_from_file(file_, full_path) # iterate over deleted files deleted_files = set(self.cache.keys()) - set(files) for file_ in deleted_files: self._update_on_existing_entities( self.cache[file_][self.ENTITIES_SECTION], {}, entities_updates) del self.cache[file_] return entities_updates
def _get_entities_from_file(self, file_, path): static_entities = [] config = file_utils.load_yaml_file(path) if StaticDriver._is_valid_config(config): LOG.warning("Skipped config of new static datasource: {}" .format(file_)) return [] for entity in config[self.ENTITIES_SECTION]: static_entities.append(entity.copy()) self.cache[file_] = config return static_entities
def _get_entities_from_file(self, file_, path): static_entities = [] config = file_utils.load_yaml_file(path) if StaticDriver.is_valid_config(config): LOG.warning("Skipped config of new static datasource: {}" .format(file_)) return [] for entity in config[self.ENTITIES_SECTION]: static_entities.append(entity.copy()) self.cache[file_] = config return static_entities