Ejemplo n.º 1
0
    def GetParserFilterListsFromString(cls, parser_filter_string):
        """Determines an include and exclude list of parser names.

    Takes a comma separated string and splits it up into two lists,
    of parsers to include and to exclude from selection. If a particular
    filter is prepended with a minus sign it will be included in the
    exclude section, otherwise in the include.

    Args:
      parser_filter_string: The parser filter string.

    Returns:
      A tuple of two lists, include and exclude.
    """
        if not parser_filter_string:
            return [], []

        # Build the plugin to parser map, which cannot be a class member
        # otherwise the map will become invalid if a parser with plugins
        # is deregistered.
        plugin_to_parser_map = {}
        for parser_name, parser_class in cls._parser_classes.iteritems():
            if parser_class.SupportsPlugins():
                for plugin_name in parser_class.GetPluginNames():
                    plugin_to_parser_map[plugin_name] = parser_name

        includes = set()
        excludes = set()

        preset_categories = presets.categories.keys()

        for filter_string in parser_filter_string.split(u','):
            filter_string = filter_string.strip()
            if not filter_string:
                continue

            if filter_string.startswith(u'-'):
                active_list = excludes
                filter_string = filter_string[1:]
            else:
                active_list = includes

            filter_string = filter_string.lower()
            if filter_string in cls._parser_classes:
                active_list.add(filter_string)

            elif filter_string in preset_categories:
                for entry in presets.GetParsersFromCategory(filter_string):
                    active_list.add(plugin_to_parser_map.get(entry, entry))

            else:
                active_list.add(
                    plugin_to_parser_map.get(filter_string, filter_string))

        return list(includes), list(excludes)
Ejemplo n.º 2
0
    def _GetParserFilters(cls, parser_filter_expression):
        """Retrieves the parsers and plugins to include and exclude.

    Takes a comma separated string and splits it up into two dictionaries,
    of parsers and plugins to include and to exclude from selection. If a
    particular filter is prepended with an exclamation point it will be
    added to the exclude section, otherwise in the include.

    Args:
      parser_filter_expression: a string containing the parser filter
                                expression, where None represents all parsers
                                and plugins.

    Returns:
      A tuple containing dictionaries of the names of the included and
      excluded parsers and plugins. Where the keys contain the names of
      the parser and the corresponding value the names of the plugins.
    """
        if not parser_filter_expression:
            return {}, {}

        includes = {}
        excludes = {}

        preset_categories = presets.categories.keys()

        for parser_filter in parser_filter_expression.split(u','):
            parser_filter = parser_filter.strip()
            if not parser_filter:
                continue

            if parser_filter.startswith(u'!'):
                parser_filter = parser_filter[1:]
                active_dict = excludes
            else:
                active_dict = includes

            parser_filter = parser_filter.lower()
            if parser_filter in preset_categories:
                for parser_in_category in presets.GetParsersFromCategory(
                        parser_filter):
                    parser, _, plugin = parser_in_category.partition(u'/')
                    active_dict.setdefault(parser, [])
                    if plugin:
                        active_dict[parser].append(plugin)

            else:
                parser, _, plugin = parser_filter.partition(u'/')
                active_dict.setdefault(parser, [])
                if plugin:
                    active_dict[parser].append(plugin)

        cls._ReduceParserFilters(includes, excludes)
        return includes, excludes
Ejemplo n.º 3
0
    def GetFilterListsFromString(cls, parser_filter_string):
        """Determines an include and exclude list of parser and plugin names.

    Takes a comma separated string and splits it up into two lists,
    of parsers, those to include and exclude from selection.

    If a particular filter is prepended with a minus sign it will
    be included in the exclude section, otherwise it is placed in the include.

    Args:
      parser_filter_string: The parser filter string.

    Returns:
      A tuple of two lists, include and exclude.
    """
        includes = []
        excludes = []

        if not parser_filter_string:
            return includes, excludes

        preset_categories = presets.categories.keys()

        for filter_string in parser_filter_string.split(u','):
            filter_string = filter_string.strip()
            if not filter_string:
                continue

            if filter_string.startswith(u'-'):
                active_list = excludes
                filter_string = filter_string[1:]
            else:
                active_list = includes

            filter_string = filter_string.lower()
            if filter_string in cls._parser_classes:
                parser_class = cls._parser_classes[filter_string]
                active_list.append(filter_string)

                if parser_class.SupportsPlugins():
                    active_list.extend(parser_class.GetPluginNames())

            elif filter_string in preset_categories:
                active_list.extend(
                    presets.GetParsersFromCategory(filter_string))

            else:
                active_list.append(filter_string)

        return includes, excludes
Ejemplo n.º 4
0
def GetParserListsFromString(parser_string):
    """Return a list of parsers to include and exclude from a string.

  Takes a comma separated string and splits it up into two lists,
  of parsers or plugins to include and to exclude from selection.
  If a particular filter is prepended with a minus sign it will
  be included int he exclude section, otherwise in the include.

  Args:
    parser_string: The comma separated string.

  Returns:
    A tuple of two lists, include and exclude.
  """
    include = []
    exclude = []

    preset_categories = presets.categories.keys()

    for filter_string in parser_string.split(','):
        filter_string = filter_string.strip()
        if not filter_string:
            continue
        if filter_string.startswith('-'):
            filter_strings_use = exclude
            filter_string = filter_string[1:]
        else:
            filter_strings_use = include

        filter_string_lower = filter_string.lower()
        if filter_string_lower in preset_categories:
            filter_strings_use.extend(
                presets.GetParsersFromCategory(filter_string_lower))
        else:
            filter_strings_use.append(filter_string_lower)

    return include, exclude