Example #1
0
 def __init__(self):
     BaseOptions.__init__(self)
     self['remotes'] = []
     self['running_whitelist'] = []
     self['filters'] = []
     self['handlers'] = []
     self['verbosity'] = 1
Example #2
0
    def postOptions(self):
        BaseOptions.postOptions(self)
        if self['running_author-whitelist']:
            self['author-whitelist'] = self['running_author-whitelist']
        else:
            self['author-whitelist'] = [ip_network(self['author-whitelist'], strict=False)]

        if self['running_subscriber-whitelist']:
            self['subscriber-whitelist'] = self['running_subscriber-whitelist']
        else:
            self['subscriber-whitelist'] = [ip_network(self['subscriber-whitelist'], strict=False)]

        if self['verbosity'] >= 2:
            log.LEVEL = log.Levels.DEBUG
        elif self['verbosity'] == 1:
            log.LEVEL = log.Levels.INFO
        else:
            log.LEVEL = log.Levels.WARNING

        # Now enable plugins if requested.
        # We loop over all plugins, checking if the user supplied their name
        # on the command line and adding them to our list of handlers if so.
        for plugin in getPlugins(IHandler, comet.plugins):
            if self[plugin.name]:
                if IHasOptions.providedBy(plugin):
                    for name, _, _ in plugin.get_options():
                        plugin.set_option(name, self["%s-%s" % (plugin.name, name)])
                self['handlers'].append(plugin)
Example #3
0
    def postOptions(self):
        BaseOptions.postOptions(self)
        if self['running_author-whitelist']:
            self['author-whitelist'] = self['running_author-whitelist']
        else:
            self['author-whitelist'] = [ip_network(self['author-whitelist'], strict=False)]

        if self['running_subscriber-whitelist']:
            self['subscriber-whitelist'] = self['running_subscriber-whitelist']
        else:
            self['subscriber-whitelist'] = [ip_network(self['subscriber-whitelist'], strict=False)]

        if self['verbosity'] >= 2:
            log.LEVEL = log.Levels.DEBUG
        elif self['verbosity'] == 1:
            log.LEVEL = log.Levels.INFO
        else:
            log.LEVEL = log.Levels.WARNING

        # Now enable plugins if requested.
        # We loop over all plugins, checking if the user supplied their name
        # on the command line and adding them to our list of handlers if so.
        for plugin in getPlugins(IHandler, comet.plugins):
            if self[plugin.name]:
                if IHasOptions.providedBy(plugin):
                    for name, _, _ in plugin.get_options():
                        plugin.set_option(name, self["%s-%s" % (plugin.name, name)])
                self['handlers'].append(plugin)
Example #4
0
 def __init__(self):
     BaseOptions.__init__(self)
     self['remotes'] = []
     self['running_author-whitelist'] = []
     self['running_subscriber-whitelist'] = []
     self['filters'] = []
     self['handlers'] = []
     self['verbosity'] = 1
Example #5
0
    def test_pluginpath(self):
        # The COMET_PLUGINPATH environment variable should set the locations
        # set for plugins.
        dummy_plugin = dedent(f"""
        # Comet VOEvent Broker.
        # This is a no-op plugin, used to demonstrate plugin registration.

        from zope.interface import implementer
        from twisted.plugin import IPlugin
        from comet.icomet import IHandler

        # Event handlers must implement IPlugin and IHandler.
        @implementer(IPlugin, IHandler)
        class TestPlugin(object):
            name = "test-plugin-{os.getpid()}"

            # When the handler is called, it is passed an instance of
            # comet.utility.xml.xml_document.
            def __call__(self, event):
                pass

        # This instance of the handler is what actually constitutes our plugin.
        test_plugin = TestPlugin()""")

        # We'll restore the initial environment at the end of the test case.
        init_environ = os.environ.copy()
        init_pluginpath = comet.plugins.__path__.copy()

        initial_plugin_count = len(list(getPlugins(IHandler, comet.plugins)))

        try:
            with TemporaryDirectory() as tempdir:
                with open(os.path.join(tempdir, "plugin.py"), "w") as f:
                    f.write(dummy_plugin)

                os.environ["COMET_PLUGINPATH"] = tempdir

                # Trigger update of comet.plugins.__path__
                BaseOptions()

                # Should now be one more plugin available.
                self.assertEqual(
                    len(list(getPlugins(IHandler, comet.plugins))),
                    initial_plugin_count + 1)

        finally:
            os.environ = init_environ
            comet.plugins.__path__ = init_pluginpath

        # Should be back to the original plugin count.
        self.assertEqual(len(list(getPlugins(IHandler, comet.plugins))),
                         initial_plugin_count)