mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add function to clear out static files which do not match installed plugin(s)
This commit is contained in:
parent
3c7fcee391
commit
3725aef839
@ -32,6 +32,8 @@ def clear_static_dir(path, recursive=True):
|
||||
# Finally, delete the directory itself to remove orphan folders when uninstalling a plugin
|
||||
staticfiles_storage.delete(path)
|
||||
|
||||
logger.info('Cleared static directory: %s', path)
|
||||
|
||||
|
||||
def collect_plugins_static_files():
|
||||
"""Copy static files from all installed plugins into the static directory."""
|
||||
@ -43,6 +45,26 @@ def collect_plugins_static_files():
|
||||
copy_plugin_static_files(slug, check_reload=False)
|
||||
|
||||
|
||||
def clear_plugins_static_files():
|
||||
"""Clear out static files for plugins which are no longer active."""
|
||||
installed_plugins = set(registry.plugins.keys())
|
||||
|
||||
path = 'plugins/'
|
||||
|
||||
# Check that the directory actually exists
|
||||
if not staticfiles_storage.exists(path):
|
||||
return
|
||||
|
||||
# Get all static files in the 'plugins' static directory
|
||||
dirs, _files = staticfiles_storage.listdir('plugins/')
|
||||
|
||||
for d in dirs:
|
||||
# Check if the directory is a plugin directory
|
||||
if d not in installed_plugins:
|
||||
# Clear out the static files for this plugin
|
||||
clear_static_dir(f'plugins/{d}/', recursive=True)
|
||||
|
||||
|
||||
def copy_plugin_static_files(slug, check_reload=True):
|
||||
"""Copy static files for the specified plugin."""
|
||||
if check_reload:
|
||||
|
Loading…
Reference in New Issue
Block a user