(self, indices)
Make changes to the current set of indices.
Make changes to the current set of indices.
Make changes to the current set of indices .
def indices(self, indices):
        """Make changes to the current set of indices."""

        if indices == '_all':
            self._indices = '_all'
            self.commit()
            return

        def _is_string_or_int(item):
            return isinstance(item, (str, int))

        if not isinstance(indices, list):
            logger.warning(
                'Indices needs to be a list of strings (indices that were '
                'passed in were not a list).')
            return
        if not all(map(_is_string_or_int, indices)):
            logger.warning(
                'Indices needs to be a list of strings or ints, not all '
                'entries in the indices list are valid string/int.')
            return

        if len(indices) == 1 and indices[0] == '_all':
            self._indices = '_all'
            self.commit()
            return

        # Indices here can be either a list of timeline names, IDs or a list
        # of search indices. We need to verify that these exist before saving
        # them.
        valid_ids = set()
        timeline_indices = {}  # Dict[index] = List[name]
        timeline_names = {}  # Dict[name] = id

        for timeline_object in self._sketch.list_timelines():
            timeline_indices.setdefault(timeline_object.index_name, [])
            timeline_indices[timeline_object.index_name].append(
                timeline_object.name)
            valid_ids.add(timeline_object.id)

            timeline_names[timeline_object.name] = timeline_object.id

        new_indices = []
        for index in indices:
            # Is this an index name, include all timeline IDs.
            if index in timeline_indices:
                new_indices.extend(timeline_indices[index])
                continue

            # Is this a timeline ID?
            if isinstance(index, int):
                if index in valid_ids:
                    new_indices.append(str(index))
                    continue

            if index.isdigit():
                if int(index) in valid_ids:
                    new_indices.append(index)
                    continue

            # Is this a timeline name?
            if index in timeline_names:
                new_indices.append(timeline_names[index])

        if not new_indices:
            logger.warning('No valid indices found, not changing the value.')
            return

        self._indices = new_indices
        self.commit()
def indices ( self , indices ) : if indices == '_all' : self . _indices = '_all' self . commit ( ) return def _is_string_or_int ( item ) : return isinstance ( item , ( str , int ) ) if not isinstance ( indices , list ) : logger . warning ( 'Indices needs to be a list of strings (indices that were ' 'passed in were not a list).' ) return if not all ( map ( _is_string_or_int , indices ) ) : logger . warning ( 'Indices needs to be a list of strings or ints, not all ' 'entries in the indices list are valid string/int.' ) return if len ( indices ) == 1 and indices [ 0 ] == '_all' : self . _indices = '_all' self . commit ( ) return # Indices here can be either a list of timeline names, IDs or a list # of search indices. We need to verify that these exist before saving # them. valid_ids = set ( ) timeline_indices = { } # Dict[index] = List[name] timeline_names = { } # Dict[name] = id for timeline_object in self . _sketch . list_timelines ( ) : timeline_indices . setdefault ( timeline_object . index_name , [ ] ) timeline_indices [ timeline_object . index_name ] . append ( timeline_object . name ) valid_ids . add ( timeline_object . id ) timeline_names [ timeline_object . name ] = timeline_object . id new_indices = [ ] for index in indices : # Is this an index name, include all timeline IDs. if index in timeline_indices : new_indices . extend ( timeline_indices [ index ] ) continue # Is this a timeline ID? if isinstance ( index , int ) : if index in valid_ids : new_indices . append ( str ( index ) ) continue if index . isdigit ( ) : if int ( index ) in valid_ids : new_indices . append ( index ) continue # Is this a timeline name? if index in timeline_names : new_indices . append ( timeline_names [ index ] ) if not new_indices : logger . warning ( 'No valid indices found, not changing the value.' ) return self . _indices = new_indices self . commit ( )