Exemplo n.º 1
0
def init_callback():
    tester = Eucaops(credpath=CREDPATH)
    global PLUGINS
    PLUGINS = ExtensionManager(namespace=NAMESPACE,
                               invoke_on_load=True,
                               invoke_args=(tester, ))
    PLUGINS.propagate_map_exceptions = True
Exemplo n.º 2
0
Arquivo: loader.py Projeto: tzmvp/st2
def get_available_plugins(namespace):
    """Return names of the available / installed plugins for a given namespace.
    """
    from stevedore.extension import ExtensionManager

    manager = ExtensionManager(namespace=namespace, invoke_on_load=False)
    return manager.names()
Exemplo n.º 3
0
 def __init__(self, filename):
     super(VarLoader, self).__init__()
     self.filename = filename
     loaders = ExtensionManager(namespace='usagi.var_loaders', )
     self.loaders = dict(
         (name, loaders[name].plugin) for name in loaders.names())
     self.loader_keys = set(self.loaders.keys())
Exemplo n.º 4
0
def get_available_plugins(namespace):
    """Return names of the available / installed plugins for a given namespace.
    """
    from stevedore.extension import ExtensionManager

    manager = ExtensionManager(namespace=namespace, invoke_on_load=False)
    return manager.names()
Exemplo n.º 5
0
def list_providers():
    """
    Return a list of installed providers.
    """
    em = ExtensionManager(NAMESPACE)
    return em.map(lambda p:
                  {'name': p.name, 'version': p.plugin().get_version()})
Exemplo n.º 6
0
def get_scripts_by_name(namespace):
    scripts_by_name = defaultdict(list)
    extension_manager = ExtensionManager(namespace, invoke_on_load=True)
    for name, extension in zip(extension_manager.names(), extension_manager.extensions):
        scripts_by_name[name].append(extension.obj)
    for name, scripts in scripts_by_name.items():
        scripts_by_name[name] = sorted(scripts, key=lambda x: x.priority)
    return scripts_by_name
Exemplo n.º 7
0
def get_available_backends():
    """
    Return names of the available / installed authentication backends.

    :rtype: ``list`` of ``str``
    """
    manager = ExtensionManager(namespace=BACKENDS_NAMESPACE, invoke_on_load=False)
    return manager.names()
Exemplo n.º 8
0
def get_available_drivers(invoke_on_load=False):
    """
    Return names of the available drivers
    """
    from stevedore.extension import ExtensionManager
    manager = ExtensionManager(namespace=NAMESPACE,
                               invoke_on_load=invoke_on_load)
    return manager.names()
Exemplo n.º 9
0
def get_available_backends():
    """
    Return names of the available / installed authentication backends.

    :rtype: ``list`` of ``str``
    """
    manager = ExtensionManager(namespace=BACKENDS_NAMESPACE,
                               invoke_on_load=False)
    return manager.names()
Exemplo n.º 10
0
def list_providers():
    """
    Return a list of installed providers.
    """
    em = ExtensionManager(NAMESPACE)
    return em.map(lambda p: {
        'name': p.name,
        'version': p.plugin().get_version()
    })
Exemplo n.º 11
0
def get_available_backends():
    """
    Return names of the available / installed action runners.

    :rtype: ``list`` of ``str``
    """
    from stevedore.extension import ExtensionManager

    manager = ExtensionManager(namespace=BACKENDS_NAMESPACE, invoke_on_load=False)
    return manager.names()
Exemplo n.º 12
0
 def __init__(self, filename):
     super(VarLoader, self).__init__()
     self.filename = filename
     loaders = ExtensionManager(
         namespace='usagi.var_loaders',
     )
     self.loaders = dict(
         (name, loaders[name].plugin)
         for name in loaders.names()
     )
     self.loader_keys = set(self.loaders.keys())
Exemplo n.º 13
0
def get_available_backends():
    """
    Return names of the available / installed action runners.

    :rtype: ``list`` of ``str``
    """
    from stevedore.extension import ExtensionManager

    manager = ExtensionManager(namespace=BACKENDS_NAMESPACE,
                               invoke_on_load=False)
    return manager.names()
Exemplo n.º 14
0
 def get_available_plugins(cls, namespace=None):
     """
     Returns a dict of all the plugins that have been made available through the platform.
     """
     # Note: we're creating the extension manager lazily to ensure that the Python path
     # has been correctly set up. Trying to create this statically will fail, unfortunately.
     plugins = OrderedDict()
     extension_manager = ExtensionManager(namespace=namespace or cls.NAMESPACE)  # pylint: disable=no-member
     for plugin_name in extension_manager.names():
         plugins[plugin_name] = extension_manager[plugin_name].plugin
     return plugins
Exemplo n.º 15
0
    def __init__(self):
        self.hook_managers = OrderedDict()
        self.hook_managers[self.ENVIRONMENT_HOOK] = ExtensionManager(
            namespace=self.ENVIRONMENT_HOOK, )
        self.hook_managers[self.RESULT_HANDLERS] = ExtensionManager(
            namespace=self.RESULT_HANDLERS, )

        self.driver_managers = OrderedDict()
        self.driver_managers[self.TEST_DISCOVERY] = ExtensionManager(
            namespace=self.TEST_DISCOVERY, )
        self.driver_managers[self.TEST_RUNNER] = ExtensionManager(
            namespace=self.TEST_RUNNER, )
Exemplo n.º 16
0
def get_available_backends(namespace, invoke_on_load=False):
    """
    Return names of the available / installed backends.

    :rtype: ``list`` of ``str``
    """
    # NOTE: We use lazy import because importing from stevedore adds significat import time
    # overhead to other modules which don't need this package (stevedore needs to inspect various
    # entrypoint files on disk for all the installed Python packages which is slow)
    from stevedore.extension import ExtensionManager

    manager = ExtensionManager(namespace=namespace, invoke_on_load=invoke_on_load)
    return manager.names()
Exemplo n.º 17
0
    def _load_plugins(self, plugins):
        """ Load plugins via Stevedore. """
        mgr = ExtensionManager(
            namespace='force.bdss.extensions',
            invoke_on_load=True,
            on_load_failure_callback=functools.partial(_load_failure_callback,
                                                       plugins)
        )

        try:
            mgr.map(functools.partial(_import_extensions, plugins))
        except NoMatches:
            log.info("No extensions found")
Exemplo n.º 18
0
def get_available_backends(namespace, invoke_on_load=False):
    """
    Return names of the available / installed backends.

    :rtype: ``list`` of ``str``
    """
    # NOTE: We use lazy import because importing from stevedore adds significat import time
    # overhead to other modules which don't need this package (stevedore needs to inspect various
    # entrypoint files on disk for all the installed Python packages which is slow)
    from stevedore.extension import ExtensionManager

    manager = ExtensionManager(namespace=namespace, invoke_on_load=invoke_on_load)
    return manager.names()
Exemplo n.º 19
0
    def setUp(self):
        super(PartitionTestCase, self).setUp()
        # Set up two user partition schemes: mock and random
        self.non_random_scheme = MockUserPartitionScheme(self.TEST_SCHEME_NAME)
        self.random_scheme = MockUserPartitionScheme("random")
        extensions = [
            Extension(self.non_random_scheme.name,
                      USER_PARTITION_SCHEME_NAMESPACE, self.non_random_scheme,
                      None),
            Extension(self.random_scheme.name, USER_PARTITION_SCHEME_NAMESPACE,
                      self.random_scheme, None),
        ]
        UserPartition.scheme_extensions = ExtensionManager.make_test_instance(
            extensions, namespace=USER_PARTITION_SCHEME_NAMESPACE)

        # Create a test partition
        self.user_partition = UserPartition(
            self.TEST_ID,
            self.TEST_NAME,
            self.TEST_DESCRIPTION,
            self.TEST_GROUPS,
            extensions[0].plugin,
            self.TEST_PARAMETERS,
        )

        # Make sure the names are set on the schemes (which happens normally in code, but may not happen in tests).
        self.user_partition.get_scheme(self.non_random_scheme.name)
        self.user_partition.get_scheme(self.random_scheme.name)
Exemplo n.º 20
0
    def test_environment_hook_options_no_plugins(self):
        # Given
        environment_manager = ExtensionManager.make_test_instance(
            [],
            namespace=PluginManager.ENVIRONMENT_HOOK,
        )
        hook_managers = [(PluginManager.ENVIRONMENT_HOOK, environment_manager)]
        plugin_manager = PluginManager.testing_plugin_manager(
            hook_managers=hook_managers, driver_managers=())
        parser = ArgumentParser(add_help=False)

        # When
        plugin_manager.add_plugin_arguments(parser)

        # Then
        actions = parser._actions
        self.assertEqual(len(actions), 0)

        # When
        args = parser.parse_args([])
        enabled_plugins = plugin_manager.get_enabled_hook_plugins(
            plugin_manager.ENVIRONMENT_HOOK, args)

        # Then
        self.assertEqual(enabled_plugins, [])
Exemplo n.º 21
0
    def init_app(self, obj):
        """Sets up client with config values from obj

        Args:
            obj (instance): config object
        """
        self.data_dir = obj.config.get(u'DEV_DATA_DIR', None)
        if self.data_dir is not None:
            self.data_dir = os.path.join(self.data_dir, u'pyi-data')
            self.deploy_dir = os.path.join(self.data_dir, u'deploy')
        else:
            log.debug(u'DEV_DATA_DIR is None. Setup failed.')

        self.remote_dir = obj.config.get(u'REMOTE_DIR', None)
        self.host = obj.config.get(u'HOST', None)

        self.username = obj.config.get(u'USERNAME', None)

        # If password is now get ssh key path
        self.password = obj.config.get(u'PASSWORD', None)
        if self.password is None:
            self.password = obj.config.get(u'SSH_KEY_PATH')

        self.uploader = None
        self.test = False

        # Extension Manager
        self.mgr = ExtensionManager(namespace=u'pyiupdater.uploaders',
                                    )
Exemplo n.º 22
0
    def test_get_default_driver(self):
        # Given
        class OtherRunner(BaseTestRunner):
            pass

        default = Extension(
            'default', None, BaseTestRunner, None)
        other = Extension(
            'other', None, OtherRunner, None)
        driver_managers = [
            (PluginManager.TEST_RUNNER, ExtensionManager.make_test_instance(
                [default, other], namespace=PluginManager.TEST_RUNNER)),
        ]
        plugin_manager = PluginManager.testing_plugin_manager(
            hook_managers=(), driver_managers=driver_managers)
        parser = create_argument_parser()
        plugin_manager.add_plugin_arguments(parser)

        # When
        args = parser.parse_args([])
        plugin_manager.get_driver(plugin_manager.TEST_RUNNER, args)
        runner = plugin_manager.get_driver(plugin_manager.TEST_RUNNER, args)

        # Then
        self.assertNotIsInstance(runner, OtherRunner)
Exemplo n.º 23
0
class SyncCommand(AbstractCommand):
    """Sync with IaaS or PaaS."""

    service_manager = ExtensionManager(namespace='termius.sync.providers')
    save_strategy = RelatedSaveStrategy
    get_strategy = RelatedGetStrategy

    def extend_parser(self, parser):
        """Add more arguments to parser."""
        parser.add_argument('-c',
                            '--credentials',
                            help='Credentials (path or file) for service.')
        parser.add_argument('service', metavar='SERVICE', help='Service name.')
        return parser

    def get_service(self, service_name):
        """Load service instance by name."""
        try:
            extension = self.service_manager[service_name]
        except KeyError:
            raise NoSuchServiceException(
                'Do not support service: {}.'.format(service_name))
        return extension.plugin

    def sync_with_service(self, service, credentials):
        """Connect to service and retrieve it's hosts.."""
        service_class = self.get_service(service)
        service = service_class(self.storage, credentials)
        service.sync()

    def take_action(self, parsed_args):
        """Process CLI call."""
        self.sync_with_service(parsed_args.service, parsed_args.credentials)
        self.log.info('Sync with service %s.', parsed_args.service)
Exemplo n.º 24
0
def get_grader(grader_type):
    """Returns grader by the `grader_type(str)`."""
    extension = ExtensionManager(namespace='openedx.graders')
    try:
        return extension[grader_type].plugin
    except KeyError:
        raise UnrecognizedGraderError("Unrecognized grader `{0}`".format(grader_type))
Exemplo n.º 25
0
def _get_extension_plugin_modules(log, warn=True):
    """
    Get the modules registered by installed python modules that
    provide extensions in the ``smqtk_plugins`` namespace.

    :return: Iterator of python modules registered by installed extensions.
    :rtype: collections.Iterator[types.ModuleType]

    """
    # Get the cached extension manager.
    try:
        m = _get_extension_plugin_modules.ext_manager
    except AttributeError:
        log.debug("Creating and caching ExtensionManager for namespace '{}'."
                  .format(EXTENSION_NAMESPACE))
        m = _get_extension_plugin_modules.ext_manager = \
            ExtensionManager(EXTENSION_NAMESPACE)
    # Yield registered extensions that are actually modules.
    for ext in m:
        ext_plugin_module = ext.plugin
        if not isinstance(ext_plugin_module, types.ModuleType):
            if warn:
                warnings.warn("Skipping extension provided by package '{} "
                              "({})' that did NOT resolve to a python module "
                              "(got an object of type {} instead: {})."
                              .format(ext.entry_point.dist.key,
                                      ext.entry_point.dist.version,
                                      type(ext_plugin_module).__name__,
                                      ext_plugin_module))
        else:
            yield ext.plugin
Exemplo n.º 26
0
    def __init__(self, config, plugins=None):
        if isinstance(plugins, list):
            _all_plugins = plugins
        else:
            _all_plugins = []

            for pn in self.PLUGIN_NAMESPACES:
                try:
                    namespace = ExtensionManager(pn, invoke_on_load=True)
                except Exception as err:
                    log.debug(err, exc_info=True)
                else:
                    for p in namespace.extensions:
                        _all_plugins.append(p.obj)

        # Sorting by name then author
        plugins = sorted(_all_plugins, key=lambda x: (x.name, x.author))

        # Used as a counter when creating names to plugin
        # User may have multiple plugins with the same
        # name installed
        self.unique_names = {}

        # A list of dicts of all installed plugins.
        # Keys: name author plugin
        self.plugins = []
        self.configs = PluginManager._get_config(config)
        self._load(plugins)
Exemplo n.º 27
0
def manager():
    m = g.get('manager')
    if m is None:
        m = g['manager'] = ExtensionManager('torabot.mods',
                                            invoke_on_load=True,
                                            invoke_args=(get_current_conf(), ))
    return m
Exemplo n.º 28
0
    def setUp(self):
        super(PartitionTestCase, self).setUp()
        # Set up two user partition schemes: mock and random
        self.non_random_scheme = MockUserPartitionScheme(self.TEST_SCHEME_NAME)
        self.random_scheme = MockUserPartitionScheme("random")
        extensions = [
            Extension(
                self.non_random_scheme.name, USER_PARTITION_SCHEME_NAMESPACE, self.non_random_scheme, None
            ),
            Extension(
                self.random_scheme.name, USER_PARTITION_SCHEME_NAMESPACE, self.random_scheme, None
            ),
        ]
        UserPartition.scheme_extensions = ExtensionManager.make_test_instance(
            extensions, namespace=USER_PARTITION_SCHEME_NAMESPACE
        )

        # Create a test partition
        self.user_partition = UserPartition(
            self.TEST_ID,
            self.TEST_NAME,
            self.TEST_DESCRIPTION,
            self.TEST_GROUPS,
            extensions[0].plugin,
            self.TEST_PARAMETERS,
        )

        # Make sure the names are set on the schemes (which happens normally in code, but may not happen in tests).
        self.user_partition.get_scheme(self.non_random_scheme.name)
        self.user_partition.get_scheme(self.random_scheme.name)
Exemplo n.º 29
0
    def test_environment_hook_options(self):
        class TestingPlugin(BaseTestingPlugin):
            add_parser_arguments_called = 0
            from_args_called = 0

            @classmethod
            def add_parser_arguments(cls, parser, name, option_prefix,
                                     dest_prefix):
                cls.add_parser_arguments_called += 1
                return super(TestingPlugin, cls).add_parser_arguments(
                    parser, name, option_prefix, dest_prefix)

            @classmethod
            def from_args(cls, args, name, dest_prefix):
                cls.from_args_called += 1
                return super(TestingPlugin, cls).from_args(
                    args, name, dest_prefix)

        # Given
        extension = Extension(
            'testing-plugin', None, TestingPlugin, None)
        environment_manager = ExtensionManager.make_test_instance(
            [extension], namespace=PluginManager.ENVIRONMENT_HOOK,
        )
        hook_managers = [(PluginManager.ENVIRONMENT_HOOK, environment_manager)]
        plugin_manager = PluginManager.testing_plugin_manager(
            hook_managers=hook_managers, driver_managers=())
        parser = ArgumentParser(add_help=False)

        # When
        plugin_manager.add_plugin_arguments(parser)

        # Then
        self.assertEqual(TestingPlugin.add_parser_arguments_called, 1)
        actions = parser._actions
        self.assertEqual(len(actions), 1)
        action, = actions
        self.assertEqual(action.option_strings, ['--with-testing-plugin'])

        # When
        args = parser.parse_args([])
        enabled_plugins = plugin_manager.get_enabled_hook_plugins(
            plugin_manager.ENVIRONMENT_HOOK, args)

        # Then
        self.assertEqual(enabled_plugins, [])
        self.assertEqual(TestingPlugin.from_args_called, 1)

        # When
        args = parser.parse_args(['--with-testing-plugin'])
        enabled_plugins = plugin_manager.get_enabled_hook_plugins(
            plugin_manager.ENVIRONMENT_HOOK, args)

        # Then
        self.assertEqual(len(enabled_plugins), 1)

        plugin_obj, = enabled_plugins
        self.assertEqual(TestingPlugin.from_args_called, 2)
        self.assertTrue(plugin_obj.enabled)
Exemplo n.º 30
0
def _init_classes():
    """Avoid leaking state variables by wrapping `LAYER_CLASSES` construction
    in a function"""
    classes = {}
    for doc_type in ('cfr', 'preamble'):    # @todo - make this dynamic
        namespace = 'eregs_ns.parser.layer.{0}'.format(doc_type)
        classes[doc_type] = {
            extension.name: extension.plugin
            for extension in ExtensionManager(namespace)
        }

    # For backwards compatibility. @todo - remove in later release
    old_namespace = 'eregs_ns.parser.layers'
    classes['cfr'].update({
        extension.plugin.shorthand: extension.plugin
        for extension in ExtensionManager(old_namespace)
    })
    return classes
Exemplo n.º 31
0
    def make_plugin_options(self):
        plugin_options = []

        self.mgr = ExtensionManager(u'pyiupdater.uploaders')
        plugin_names = self.mgr.names()
        log.debug(u'Plugin names: {}'.format(plugin_names))

        for pgn in plugin_names:
            # passing none as a place holder for logic in
            # cli.ui.menu for processing of plugin menu creation
            # Logic will pass this to else since its len is
            # more then 2
            log.debug(u'Plugin name: {}'.format(pgn))
            option = (pgn, self.upload, None)
            plugin_options.append(option)
        plugin_options.append((u'Main Menu', self.done))

        return plugin_options
Exemplo n.º 32
0
def initialize_data_types(suffix_by_data_type=None):
    for x in ExtensionManager('crosscompute.types').extensions:
        data_type = x.plugin
        for suffix in data_type.suffixes:
            DATA_TYPE_BY_SUFFIX[suffix] = data_type
        DATA_TYPE_BY_NAME[x.name] = data_type
    for suffix, data_type_spec in (suffix_by_data_type or {}).items():
        data_type = resolve_attribute(data_type_spec)
        DATA_TYPE_BY_SUFFIX[suffix] = data_type
Exemplo n.º 33
0
 def manager(self):
     name = '_manager'
     value = getattr(self, name, None)
     if value is None:
         from .local import get_current_conf
         value = ExtensionManager('torabot.mods',
                                  invoke_on_load=True,
                                  invoke_args=(get_current_conf(), ))
         setattr(self, name, value)
     return value
Exemplo n.º 34
0
    def __init__(self, loader):
        super(YamlTestLoader, self).__init__()
        self._loader = loader

        assertions = ExtensionManager(
            namespace='usagi.assertions',
        )
        test_parameters = ExtensionManager(
            namespace='usagi.parameters'
        )

        self._assertions_map = dict(
            (name, assertions[name].plugin)
            for name in assertions.names()
        )
        self._test_parameters = dict(
            (name, test_parameters[name].plugin)
            for name in test_parameters.names()
        )
Exemplo n.º 35
0
def register_runners(experimental=False, fail_on_failure=True):
    """
    Register runners
    """
    LOG.debug('Start : register runners')
    runner_count = 0

    manager = ExtensionManager(namespace=RUNNERS_NAMESPACE, invoke_on_load=False)
    extension_names = manager.names()

    for name in extension_names:
        LOG.debug('Found runner "%s"' % (name))

        manager = DriverManager(namespace=RUNNERS_NAMESPACE, invoke_on_load=False, name=name)
        runner_metadata = manager.driver.get_metadata()
        runner_count += register_runner(runner_metadata, experimental)

    LOG.debug('End : register runners')

    return runner_count
Exemplo n.º 36
0
def register_runners(experimental=False, fail_on_failure=True):
    """
    Register runners
    """
    LOG.debug('Start : register runners')
    runner_count = 0

    manager = ExtensionManager(namespace=RUNNERS_NAMESPACE, invoke_on_load=False)
    extension_names = manager.names()

    for name in extension_names:
        LOG.debug('Found runner "%s"' % (name))

        manager = DriverManager(namespace=RUNNERS_NAMESPACE, invoke_on_load=False, name=name)
        runner_metadata = manager.driver.get_metadata()
        runner_count += register_runner(runner_metadata, experimental)

    LOG.debug('End : register runners')

    return runner_count
Exemplo n.º 37
0
    def __init__(self, config: Config, invoke_on_load=False):
        self._logger = logging.getLogger(__name__)

        self.failed_plugins = list()
        self._disabled_plugins = config.plugins.disabled

        self._settings_initialized = False

        def check(ext: Extension):
            return self._check_extension(config, ext)

        self.weather = DriverManager(
            "blueweather.plugins.weather",
            config.plugins.weather_driver,
            on_load_failure_callback=self._on_load_fail
        )
        self.plugins = ExtensionManager(
            "blueweather.plugins.plugin",
            on_load_failure_callback=self._on_load_fail
        )
        self.api = EnabledExtensionManager(
            "blueweather.plugins.api",
            check_func=check,
            on_load_failure_callback=self._on_load_fail
        )
        self.startup = EnabledExtensionManager(
            "blueweather.plugins.startup",
            check_func=check,
            on_load_failure_callback=self._on_load_fail
        )
        self.settings = EnabledExtensionManager(
            "blueweather.plugins.settings",
            check_func=check,
            on_load_failure_callback=self._on_load_fail
        )
        self.unitConversion = DispatchExtensionManager(
            "blueweather.plugins.unitconv",
            check_func=check,
            on_load_failure_callback=self._on_load_fail
        )

        if self._logger.isEnabledFor(logging.INFO):
            extensions = self.getAllExtensions()
            for k, v in extensions.items():
                extensions[k] = '\n\t'.join(v.keys())

            extensions = '\n'.join(
                ["%s: \n\t%s" % (k, v) for k, v in extensions.items()]
            )

            self._logger.info("Discovered Extensions: \n%s", extensions)

        if invoke_on_load:
            self.invoke()
Exemplo n.º 38
0
 def wrapper(*args):
     with patch('haas.haas_application.ResultCollector') as result_cls:
         with patch('haas.plugins.runner.BaseTestRunner') as runner_class:
             environment_manager = ExtensionManager.make_test_instance(
                 [],
                 namespace=PluginManager.ENVIRONMENT_HOOK,
             )
             result_handler = Extension('default', None, result_cls, None)
             env_managers = [
                 (PluginManager.ENVIRONMENT_HOOK, environment_manager),
                 (
                     PluginManager.RESULT_HANDLERS,
                     ExtensionManager.make_test_instance(
                         [result_handler],
                         namespace=PluginManager.RESULT_HANDLERS),
                 ),
             ]
             runner = Extension('default', None, runner_class, None)
             discoverer = Extension('default', None, Discoverer, None)
             driver_managers = [
                 (
                     PluginManager.TEST_DISCOVERY,
                     ExtensionManager.make_test_instance(
                         [discoverer],
                         namespace=PluginManager.TEST_DISCOVERY),
                 ),
                 (
                     PluginManager.TEST_RUNNER,
                     ExtensionManager.make_test_instance(
                         [runner], namespace=PluginManager.TEST_RUNNER),
                 ),
             ]
             plugin_manager = PluginManager.testing_plugin_manager(
                 hook_managers=env_managers,
                 driver_managers=driver_managers)
             args_ = args + (
                 runner_class,
                 result_cls,
                 plugin_manager,
             )
             return fn(*args_)
Exemplo n.º 39
0
def update_dictionary(namespace, original):
    """
        Use the extension manager to update a dictionary.
        Assumes the keys are strings and the values are lists.
    """
    result = defaultdict(list, original)

    for extension in ExtensionManager(namespace):
        assert isinstance(extension.plugin, dict)
        for key, value in extension.plugin.items():
            result[key].extend(value)
    return dict(result)
Exemplo n.º 40
0
def main():
    seconds_passed = 0
    while True:
        for extension in ExtensionManager('pytimed', invoke_on_load=True):
            try:
                seconds, callable = extension.obj
            except:
                pass
            else:
                if seconds_passed % seconds == 0:
                    callable()
            time.sleep(1)
            seconds_passed += 1
Exemplo n.º 41
0
    def run(self):
        self.result = ViewList()

        ext_manager = ExtensionManager(namespace='metrics_store')

        for extension in ext_manager.extensions:
            driver_class = extension.plugin
            self.add_extension(driver_class)

        node = nodes.paragraph()
        node.document = self.state.document
        self.state.nested_parse(self.result, 0, node)
        return node.children
Exemplo n.º 42
0
 def get_scheme(name):
     """
     Returns the user partition scheme with the given name.
     """
     # Note: we're creating the extension manager lazily to ensure that the Python path
     # has been correctly set up. Trying to create this statically will fail, unfortunately.
     if not UserPartition.scheme_extensions:
         UserPartition.scheme_extensions = ExtensionManager(namespace=USER_PARTITION_SCHEME_NAMESPACE)
     try:
         scheme = UserPartition.scheme_extensions[name].plugin  # lint-amnesty, pylint: disable=unsubscriptable-object
     except KeyError:
         raise UserPartitionError("Unrecognized scheme '{0}'".format(name))  # lint-amnesty, pylint: disable=raise-missing-from
     scheme.name = name
     return scheme
Exemplo n.º 43
0
 def wrapper(*args):
     with patch('haas.haas_application.ResultCollector') as result_cls:
         with patch('haas.plugins.runner.BaseTestRunner') as runner_class:
             environment_manager = ExtensionManager.make_test_instance(
                 [], namespace=PluginManager.ENVIRONMENT_HOOK,
             )
             result_handler = Extension(
                 'default', None, result_cls, None)
             env_managers = [
                 (PluginManager.ENVIRONMENT_HOOK, environment_manager),
                 (
                     PluginManager.RESULT_HANDLERS,
                     ExtensionManager.make_test_instance(
                         [result_handler],
                         namespace=PluginManager.RESULT_HANDLERS),
                 ),
             ]
             runner = Extension('default', None, runner_class, None)
             discoverer = Extension('default', None, Discoverer, None)
             driver_managers = [
                 (
                     PluginManager.TEST_DISCOVERY,
                     ExtensionManager.make_test_instance(
                         [discoverer],
                         namespace=PluginManager.TEST_DISCOVERY),
                 ),
                 (
                     PluginManager.TEST_RUNNER,
                     ExtensionManager.make_test_instance(
                         [runner], namespace=PluginManager.TEST_RUNNER),
                 ),
             ]
             plugin_manager = PluginManager.testing_plugin_manager(
                 hook_managers=env_managers,
                 driver_managers=driver_managers)
             args_ = args + (runner_class, result_cls, plugin_manager,)
             return fn(*args_)
Exemplo n.º 44
0
    def test_no_driver_hook_found(self):
        # Given
        driver_managers = [
            (PluginManager.TEST_RUNNER, ExtensionManager.make_test_instance(
                [], namespace=PluginManager.TEST_RUNNER)),
        ]
        plugin_manager = PluginManager.testing_plugin_manager(
            hook_managers=(), driver_managers=driver_managers)
        parser = ArgumentParser(add_help=False)

        # When
        plugin_manager.add_plugin_arguments(parser)

        # Then
        actions = parser._actions
        self.assertEqual(len(actions), 0)
 def get_insert_cmpt_mgr():
     return ExtensionManager.make_test_instance([Extension(
         'prepare_data',
         'monasca_transform.component.insert.prepare_data:PrepareData',
         PrepareData(),
         None),
         Extension('insert_data',
                   'tests.functional.component.insert.dummy_insert:'
                   'DummyInsert',
                   DummyInsert(),
                   None),
         Extension('insert_data_pre_hourly',
                   'tests.functional.component.insert.dummy_insert:'
                   'DummyInsert',
                   DummyInsert(),
                   None),
     ])
 def get_setter_cmpt_mgr():
     return ExtensionManager.make_test_instance([Extension(
         'set_aggregated_metric_name',
         'monasca_transform.component.setter.'
         'set_aggregated_metric_name:SetAggregatedMetricName',
         SetAggregatedMetricName(),
         None),
         Extension('set_aggregated_period',
                   'monasca_transform.component.setter.'
                   'set_aggregated_period:SetAggregatedPeriod',
                   SetAggregatedPeriod(),
                   None),
         Extension('rollup_quantity',
                   'monasca_transform.component.setter.'
                   'rollup_quantity:RollupQuantity',
                   RollupQuantity(),
                   None)
     ])
Exemplo n.º 47
0
class Upload(CommonLogic, Menu):

    def __init__(self, helpers):
        self.unpack_helpers(helpers)
        header = u'Upload'
        message = (u'Make sure updates are in "new" folder '
                   'then press "1" to start.')

        options = self.make_plugin_options()
        super(Upload, self).__init__(header, options, message)

    def make_plugin_options(self):
        plugin_options = []

        self.mgr = ExtensionManager(u'pyiupdater.uploaders')
        plugin_names = self.mgr.names()
        log.debug(u'Plugin names: {}'.format(plugin_names))

        for pgn in plugin_names:
            # passing none as a place holder for logic in
            # cli.ui.menu for processing of plugin menu creation
            # Logic will pass this to else since its len is
            # more then 2
            log.debug(u'Plugin name: {}'.format(pgn))
            option = (pgn, self.upload, None)
            plugin_options.append(option)
        plugin_options.append((u'Main Menu', self.done))

        return plugin_options

    def upload(self, name):
        # Load plugin & invoke upload method
        self.uploader.set_uploader(name)
        self.display_menu_header(u'{} Uploader'.format(name))
        try:
            self.uploader.upload()
            time.sleep(3)
        except Exception as e:
            msg = (u'Looks like you forgot to add USERNAME, PASSWORD '
                   'and/or REMOTE_DIR')
            self.display_msg(msg)
            log.debug(str(e), exc_info=True)
            input()
Exemplo n.º 48
0
    def test_driver_hooks_found(self):
        # Given
        extension = Extension(
            'haas.runner', None, BaseTestRunner, None)
        driver_managers = [
            (PluginManager.TEST_RUNNER, ExtensionManager.make_test_instance(
                [extension], namespace=PluginManager.TEST_RUNNER)),
        ]
        plugin_manager = PluginManager.testing_plugin_manager(
            hook_managers=(), driver_managers=driver_managers)
        parser = ArgumentParser(add_help=False)

        # When
        plugin_manager.add_plugin_arguments(parser)

        # Then
        actions = parser._actions
        self.assertEqual(len(actions), 1)
        action, = actions
        self.assertEqual(action.option_strings, ['--runner'])
Exemplo n.º 49
0
    def setUp(self):
        # Set up two user partition schemes: mock and random
        extensions = [
            Extension(
                self.TEST_SCHEME_NAME, USER_PARTITION_SCHEME_NAMESPACE,
                MockUserPartitionScheme(self.TEST_SCHEME_NAME), None
            ),
            Extension(
                "random", USER_PARTITION_SCHEME_NAMESPACE, MockUserPartitionScheme("random"), None
            ),
        ]
        UserPartition.scheme_extensions = ExtensionManager.make_test_instance(
            extensions, namespace=USER_PARTITION_SCHEME_NAMESPACE
        )

        # Create a test partition
        self.user_partition = UserPartition(
            self.TEST_ID,
            self.TEST_NAME,
            self.TEST_DESCRIPTION,
            self.TEST_GROUPS,
            extensions[0].plugin
        )
 def get_usage_cmpt_mgr():
     return ExtensionManager.make_test_instance([Extension(
         'fetch_quantity',
         'monasca_transform.component.usage.'
         'fetch_quantity:'
         'FetchQuantity',
         FetchQuantity(),
         None),
         Extension(
         'fetch_quantity_util',
         'monasca_transform.component.usage.'
         'fetch_quantity_util:'
         'FetchQuantityUtil',
         FetchQuantityUtil(),
         None),
         Extension(
             'calculate_rate',
             'monasca_transform.component.usage.'
             'calculate_rate:'
             'CalculateRate',
             CalculateRate(),
             None),
     ])
Exemplo n.º 51
0
    def test_hook_plugin_none(self):
        class TestingPlugin(BaseTestingPlugin):

            @classmethod
            def from_args(cls, args, name, dest_prefix):
                return None

        # Given
        extension = Extension(
            'testing-plugin', None, TestingPlugin, None)
        environment_manager = ExtensionManager.make_test_instance(
            [extension], namespace=PluginManager.ENVIRONMENT_HOOK,
        )
        hook_managers = [(PluginManager.ENVIRONMENT_HOOK, environment_manager)]
        plugin_manager = PluginManager.testing_plugin_manager(
            hook_managers=hook_managers, driver_managers=())
        parser = ArgumentParser(add_help=False)
        args = parser.parse_args([])

        # When
        plugin = plugin_manager._create_hook_plugin(extension, args)

        # Then
        self.assertIsNone(plugin)
Exemplo n.º 52
0
    def test_environment_hook_options_no_plugins(self):
        # Given
        environment_manager = ExtensionManager.make_test_instance(
            [], namespace=PluginManager.ENVIRONMENT_HOOK,
        )
        hook_managers = [(PluginManager.ENVIRONMENT_HOOK, environment_manager)]
        plugin_manager = PluginManager.testing_plugin_manager(
            hook_managers=hook_managers, driver_managers=())
        parser = ArgumentParser(add_help=False)

        # When
        plugin_manager.add_plugin_arguments(parser)

        # Then
        actions = parser._actions
        self.assertEqual(len(actions), 0)

        # When
        args = parser.parse_args([])
        enabled_plugins = plugin_manager.get_enabled_hook_plugins(
            plugin_manager.ENVIRONMENT_HOOK, args)

        # Then
        self.assertEqual(enabled_plugins, [])
Exemplo n.º 53
0
    def _register_extensions(self, namespace):
        """Register any extensions under the given namespace."""

        # Register any extension classes for this class.
        extmanager = ExtensionManager(
            'extensions.classes.{}'.format(namespace),
            propagate_map_exceptions=True
        )

        if extmanager.extensions:
            extmanager.map(util.register_extension_class, base=self)

        # Register any extension methods for this class.
        extmanager = ExtensionManager(
            'extensions.methods.{}'.format(namespace),
            propagate_map_exceptions=True
        )
        if extmanager.extensions:
            extmanager.map(util.register_extension_method, base=self)
Exemplo n.º 54
0
def register_providers(context):
    conn = get_connection('collector')
    em = ExtensionManager(Provider.__plugin_ns__)
    em.map(_register, context, conn)
Exemplo n.º 55
0
def get_data_type_by_name():
    data_type_by_name = {}
    x_manager = ExtensionManager('crosscompute.types')
    for data_type_name, x in zip(x_manager.names(), x_manager.extensions):
        data_type_by_name[data_type_name] = x.plugin
    return data_type_by_name
Exemplo n.º 56
0
    def setUp(self):
        super(GroupAccessTestCase, self).setUp()

        UserPartition.scheme_extensions = ExtensionManager.make_test_instance(
            [
                Extension(
                    "memory",
                    USER_PARTITION_SCHEME_NAMESPACE,
                    MemoryUserPartitionScheme(),
                    None
                ),
                Extension(
                    "random",
                    USER_PARTITION_SCHEME_NAMESPACE,
                    MemoryUserPartitionScheme(),
                    None
                )
            ],
            namespace=USER_PARTITION_SCHEME_NAMESPACE
        )

        self.cat_group = Group(10, 'cats')
        self.dog_group = Group(20, 'dogs')
        self.worm_group = Group(30, 'worms')
        self.animal_partition = UserPartition(
            0,
            'Pet Partition',
            'which animal are you?',
            [self.cat_group, self.dog_group, self.worm_group],
            scheme=UserPartition.get_scheme("memory"),
        )

        self.red_group = Group(1000, 'red')
        self.blue_group = Group(2000, 'blue')
        self.gray_group = Group(3000, 'gray')
        self.color_partition = UserPartition(
            100,
            'Color Partition',
            'what color are you?',
            [self.red_group, self.blue_group, self.gray_group],
            scheme=UserPartition.get_scheme("memory"),
        )

        self.course = CourseFactory.create(
            user_partitions=[self.animal_partition, self.color_partition],
        )
        with self.store.bulk_operations(self.course.id, emit_signals=False):
            chapter = ItemFactory.create(category='chapter', parent=self.course)
            section = ItemFactory.create(category='sequential', parent=chapter)
            vertical = ItemFactory.create(category='vertical', parent=section)
            component = ItemFactory.create(category='problem', parent=vertical)

            self.chapter_location = chapter.location
            self.section_location = section.location
            self.vertical_location = vertical.location
            self.component_location = component.location

        self.red_cat = UserFactory()  # student in red and cat groups
        self.set_user_group(self.red_cat, self.animal_partition, self.cat_group)
        self.set_user_group(self.red_cat, self.color_partition, self.red_group)

        self.blue_dog = UserFactory()  # student in blue and dog groups
        self.set_user_group(self.blue_dog, self.animal_partition, self.dog_group)
        self.set_user_group(self.blue_dog, self.color_partition, self.blue_group)

        self.white_mouse = UserFactory()  # student in no group

        self.gray_worm = UserFactory()  # student in deleted group
        self.set_user_group(self.gray_worm, self.animal_partition, self.worm_group)
        self.set_user_group(self.gray_worm, self.color_partition, self.gray_group)
        # delete the gray/worm groups from the partitions now so we can test scenarios
        # for user whose group is missing.
        self.animal_partition.groups.pop()
        self.color_partition.groups.pop()

        # add a staff user, whose access will be unconditional in spite of group access.
        self.staff = StaffFactory.create(course_key=self.course.id)
Exemplo n.º 57
0
 def builder_names(ext_mgr=None):
     if not ext_mgr:
         ext_mgr = ExtensionManager(BUILDER_DRIVER_NAMESPACE)
     return ext_mgr.names()