示例#1
0
 def __init__(self, provider_list, config, settings, ns, display=None):
     super().__init__(provider_list, config)
     self.settings = settings
     self.display = display
     self.ns = ns
     self.whitelists = []
     self._local_only = False  # Only run local jobs
     if self.ns.whitelist:
         for whitelist in self.ns.whitelist:
             self.whitelists.append(WhiteList.from_file(whitelist.name))
     elif self.config.whitelist is not Unset:
         self.whitelists.append(WhiteList.from_file(self.config.whitelist))
     elif self.ns.include_pattern_list:
         self.whitelists.append(WhiteList(self.ns.include_pattern_list))
示例#2
0
 def __init__(self, provider_list, config, settings, ns, display=None):
     super().__init__(provider_list, config)
     self.settings = settings
     self.display = display
     self.ns = ns
     self.whitelists = []
     self._local_only = False  # Only run local jobs
     if self.ns.whitelist:
         for whitelist in self.ns.whitelist:
             self.whitelists.append(WhiteList.from_file(whitelist.name))
     elif self.config.whitelist is not Unset:
         self.whitelists.append(WhiteList.from_file(self.config.whitelist))
     elif self.ns.include_pattern_list:
         self.whitelists.append(WhiteList(self.ns.include_pattern_list))
示例#3
0
    def __init__(self, provider_list, config, settings, ns):
        super().__init__(provider_list)
        self.provider_list = provider_list
        self.config = config
        self.settings = settings
        self.ns = ns
        self.whitelists = []
        if self.ns.whitelist:
            for whitelist in self.ns.whitelist:
                self.whitelists.append(WhiteList.from_file(whitelist.name))
        elif self.config.whitelist is not Unset:
            self.whitelists.append(WhiteList.from_file(self.config.whitelist))
        elif self.ns.include_pattern_list:
            self.whitelists.append(WhiteList(self.ns.include_pattern_list))

        if self.is_interactive:
            if self.settings['welcome_text']:
                try:
                    curses.wrapper(show_welcome, self.settings['welcome_text'])
                except curses.error:
                    raise SystemExit('Terminal size must be at least 80x24')
            if not self.whitelists:
                whitelists = []
                for p in self.provider_list:
                    if p.name in self.settings['default_providers']:
                        whitelists.extend(
                            [w.name for w in p.get_builtin_whitelists()])
                try:
                    selection = curses.wrapper(show_menu, "Suite selection",
                                               whitelists)
                except curses.error:
                    raise SystemExit('Terminal size must be at least 80x24')
                if not selection:
                    raise SystemExit('No whitelists selected, aborting...')
                for s in selection:
                    self.whitelists.append(
                        get_whitelist_by_name(provider_list, whitelists[s]))
        else:
            self.whitelists.append(
                get_whitelist_by_name(
                    provider_list, self.settings['default_whitelist']))

        print("[ Analyzing Jobs ]".center(80, '='))
        self.session = None
        self.runner = None
 def test_from_file(self):
     """
     verify that WhiteList.from_file() works
     """
     with self.mocked_file(self._name, self._content):
         whitelist = WhiteList.from_file(self._name)
     # verify that the patterns are okay
     self.assertEqual(repr(whitelist.qualifier_list[0]),
                      "RegExpJobQualifier('^foo$', inclusive=True)")
     # verify that whitelist name got set
     self.assertEqual(whitelist.name, "whitelist")
     # verify that the origin got set
     self.assertEqual(whitelist.origin,
                      Origin(FileTextSource("whitelist.txt"), 1, 3))
示例#5
0
 def test_from_file(self):
     """
     verify that WhiteList.from_file() works
     """
     with self.mocked_file(self._name, self._content):
         whitelist = WhiteList.from_file(self._name)
     # verify that the patterns are okay
     self.assertEqual(
         repr(whitelist.qualifier_list[0]),
         "RegExpJobQualifier('^foo$', inclusive=True)")
     # verify that whitelist name got set
     self.assertEqual(whitelist.name, "whitelist")
     # verify that the origin got set
     self.assertEqual(
         whitelist.origin,
         Origin(FileTextSource("whitelist.txt"), 1, 3))
示例#6
0
    def get_whitelist_from_file(self, filename, stream=None):
        """
        Load a whitelist from a file, with special behavior.

        :param filename:
            name of the file to load
        :param stream:
            (optional) pre-opened stream pointing at the whitelist
        :returns:
            The loaded whitelist or None if loading fails for any reason

        This function implements special loading behavior for whitelists that
        makes them inherit the implicit namespace of the provider they may be a
        part of. Before loading the whitelist directly from the file, all known
        providers are interrogated to see if any of them has a whitelist that
        was loaded from the same file (as indicated by os.path.realpath())

        The stream argument can be provided if the caller already has an open
        file object, which is typically the case when working with argparse.
        """
        # Look up a whitelist with the same name in any of the providers
        wanted_realpath = os.path.realpath(filename)
        for provider in self.provider_list:
            for whitelist in provider.get_builtin_whitelists():
                if (whitelist.origin is not None
                        and whitelist.origin.source is not None
                        and isinstance(whitelist.origin.source,
                                       FileTextSource)
                        and os.path.realpath(
                            whitelist.origin.source.filename) ==
                        wanted_realpath):
                    logger.debug(
                        _("Using whitelist %r obtained from provider %r"),
                        whitelist.name, provider)
                    return whitelist
        # Or load it directly
        try:
            if stream is not None:
                return WhiteList.from_string(stream.read(), filename=filename)
            else:
                return WhiteList.from_file(filename)
        except Exception as exc:
            logger.warning(
                _("Unable to load whitelist %r: %s"), filename, exc)
示例#7
0
    def get_whitelist_from_file(self, filename, stream=None):
        """
        Load a whitelist from a file, with special behavior.

        :param filename:
            name of the file to load
        :param stream:
            (optional) pre-opened stream pointing at the whitelist
        :returns:
            The loaded whitelist or None if loading fails for any reason

        This function implements special loading behavior for whitelists that
        makes them inherit the implicit namespace of the provider they may be a
        part of. Before loading the whitelist directly from the file, all known
        providers are interrogated to see if any of them has a whitelist that
        was loaded from the same file (as indicated by os.path.realpath())

        The stream argument can be provided if the caller already has an open
        file object, which is typically the case when working with argparse.
        """
        # Look up a whitelist with the same name in any of the providers
        wanted_realpath = os.path.realpath(filename)
        for provider in self.provider_list:
            for whitelist in provider.get_builtin_whitelists():
                if (whitelist.origin is not None
                        and whitelist.origin.source is not None
                        and isinstance(whitelist.origin.source, FileTextSource)
                        and os.path.realpath(whitelist.origin.source.filename)
                        == wanted_realpath):
                    logger.debug(
                        _("Using whitelist %r obtained from provider %r"),
                        whitelist.name, provider)
                    return whitelist
        # Or load it directly
        try:
            if stream is not None:
                return WhiteList.from_string(stream.read(), filename=filename)
            else:
                return WhiteList.from_file(filename)
        except Exception as exc:
            logger.warning(_("Unable to load whitelist %r: %s"), filename, exc)