From fd50f3c384d84841bcf5a53d9be837e2dede3133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Fri, 4 Sep 2020 12:03:50 +0200 Subject: [PATCH] Improve plugin data deletion --- CHANGELOG.md | 1 + tutor/commands/plugins.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 562ff92..4b7e31c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Note: Breaking changes between versions are indicated by "💥". ## Unreleased +- [Improvement] Improve plugin data deletion - [Improvement] Introduce the `OPENEDX_COMMON_VERSION` setting - [Bugfix] Make it possible to run init jobs without starting the entire platform - [Improvement] Reduce "openedx" Docker image size with static asset de-duplication diff --git a/tutor/commands/plugins.py b/tutor/commands/plugins.py index 0137c1d..7fc9362 100644 --- a/tutor/commands/plugins.py +++ b/tutor/commands/plugins.py @@ -57,10 +57,7 @@ def disable(context, plugin_names): config = tutor_config.load_user(context.root) for plugin in plugin_names: plugins.disable(config, plugin) - - plugin_dir = tutor_env.pathjoin(context.root, "plugins", plugin) - if os.path.exists(plugin_dir): - shutil.rmtree(plugin_dir) + delete_plugin(context.root, plugin) fmt.echo_info("Plugin {} disabled".format(plugin)) tutor_config.save_config_file(context.root, config) @@ -69,6 +66,19 @@ def disable(context, plugin_names): ) +def delete_plugin(root, name): + plugin_dir = tutor_env.pathjoin(root, "plugins", name) + if os.path.exists(plugin_dir): + try: + shutil.rmtree(plugin_dir) + except PermissionError as e: + raise exceptions.TutorError( + "Could not delete file {} from plugin {} in folder {}".format( + e.filename, name, plugin_dir + ) + ) + + @click.command( short_help="Print the location of yaml-based plugins", help="""Print the location of yaml-based plugins. This location can be manually