def filter_by_regex()

in curator/snapshotlist.py [0:0]


    def filter_by_regex(self, kind=None, value=None, exclude=False):
        """
        Filter out snapshots not matching the pattern, or in the case of
        exclude, filter those matching the pattern.

        :param kind: Can be one of: ``suffix``, ``prefix``, ``regex``, or
            ``timestring``. This option defines what kind of filter you will be
            building.
        :param value: Depends on ``kind``. It is the :py:func:`time.strftime`
            string if ``kind`` is ``timestring``. It's used to build the regular
            expression for other kinds.
        :param exclude: If ``exclude=True``, this filter will remove matching
            snapshots from ``snapshots``. If ``exclude=False``, then only matching
            snapshots will be kept in ``snapshots``. Default is ``False``
        """
        if kind not in ['regex', 'prefix', 'suffix', 'timestring']:
            raise ValueError(f'{kind}: Invalid value for kind')

        # Stop here if None or empty value, but zero is okay
        if value == 0:
            pass
        elif not value:
            raise ValueError(
                (
                    f'{value}: Invalid value for "value". Cannot be "None" type, '
                    f'empty, or False'
                )
            )

        if kind == 'timestring':
            regex = settings.regex_map()[kind].format(get_date_regex(value))
        else:
            regex = settings.regex_map()[kind].format(value)

        self.empty_list_check()
        pattern = re.compile(regex)
        for snapshot in self.working_list():
            match = pattern.search(snapshot)
            self.loggit.debug('Filter by regex: Snapshot: %s', snapshot)
            if match:
                self.__excludify(True, exclude, snapshot)
            else:
                self.__excludify(False, exclude, snapshot)