Beispiel #1
0
def upgrade_from_lilac(config: Config) -> None:
    if not plugins.is_installed("forum"):
        fmt.echo_alert(
            "The Open edX forum feature was moved to a separate plugin in Maple. To keep using this feature, "
            "you must install and enable the tutor-forum plugin: https://github.com/overhangio/tutor-forum"
        )
    elif not plugins.is_loaded("forum"):
        fmt.echo_info(
            "The Open edX forum feature was moved to a separate plugin in Maple. To keep using this feature, "
            "we will now enable the 'forum' plugin. If you do not want to use this feature, you should disable the "
            "plugin with: `tutor plugins disable forum`.")
        plugins.load("forum")
        tutor_config.save_enabled_plugins(config)

    if not plugins.is_installed("mfe"):
        fmt.echo_alert(
            "In Maple the legacy courseware is no longer supported. You need to install and enable the 'mfe' plugin "
            "to make use of the new learning microfrontend: https://github.com/overhangio/tutor-mfe"
        )
    elif not plugins.is_loaded("mfe"):
        fmt.echo_info(
            "In Maple the legacy courseware is no longer supported. To start using the new learning microfrontend, "
            "we will now enable the 'mfe' plugin. If you do not want to use this feature, you should disable the "
            "plugin with: `tutor plugins disable mfe`.")
        plugins.load("mfe")
        tutor_config.save_enabled_plugins(config)
Beispiel #2
0
 def test_enable_twice(self) -> None:
     plugins_v0.DictPlugin({"name": "plugin1"})
     plugins.load("plugin1")
     plugins.load("plugin1")
     config: Config = {tutor_config.PLUGINS_CONFIG_KEY: []}
     tutor_config.save_enabled_plugins(config)
     self.assertEqual(["plugin1"], config[tutor_config.PLUGINS_CONFIG_KEY])
Beispiel #3
0
def enable(context: Context, plugin_names: t.List[str]) -> None:
    config = tutor_config.load_minimal(context.root)
    for plugin in plugin_names:
        plugins.load(plugin)
        fmt.echo_info(f"Plugin {plugin} enabled")
    tutor_config.save_enabled_plugins(config)
    tutor_config.save_config_file(context.root, config)
    fmt.echo_info(
        "You should now re-generate your environment with `tutor config save`."
    )
Beispiel #4
0
    def test_plugin_templates(self) -> None:
        with tempfile.TemporaryDirectory() as plugin_templates:
            DictPlugin({
                "name": "plugin1",
                "version": "0",
                "templates": plugin_templates
            })
            # Create two templates
            os.makedirs(os.path.join(plugin_templates, "plugin1", "apps"))
            with open(
                    os.path.join(plugin_templates, "plugin1",
                                 "unrendered.txt"),
                    "w",
                    encoding="utf-8",
            ) as f:
                f.write("This file should not be rendered")
            with open(
                    os.path.join(plugin_templates, "plugin1", "apps",
                                 "rendered.txt"),
                    "w",
                    encoding="utf-8",
            ) as f:
                f.write("Hello my ID is {{ ID }}")

            # Render templates
            with temporary_root() as root:
                # Create configuration
                config: Config = tutor_config.load_full(root)
                config["ID"] = "Hector Rumblethorpe"
                plugins.load("plugin1")
                tutor_config.save_enabled_plugins(config)

                # Render environment
                with patch.object(fmt, "STDOUT"):
                    env.save(root, config)

                # Check that plugin template was rendered
                root_env = os.path.join(root, "env")
                dst_unrendered = os.path.join(root_env, "plugins", "plugin1",
                                              "unrendered.txt")
                dst_rendered = os.path.join(root_env, "plugins", "plugin1",
                                            "apps", "rendered.txt")
                self.assertFalse(os.path.exists(dst_unrendered))
                self.assertTrue(os.path.exists(dst_rendered))
                with open(dst_rendered, encoding="utf-8") as f:
                    self.assertEqual("Hello my ID is Hector Rumblethorpe",
                                     f.read())