mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +00:00
Add function to clear out static files which do not match installed plugin(s)
This commit is contained in:
@ -32,6 +32,8 @@ def clear_static_dir(path, recursive=True):
|
|||||||
# Finally, delete the directory itself to remove orphan folders when uninstalling a plugin
|
# Finally, delete the directory itself to remove orphan folders when uninstalling a plugin
|
||||||
staticfiles_storage.delete(path)
|
staticfiles_storage.delete(path)
|
||||||
|
|
||||||
|
logger.info('Cleared static directory: %s', path)
|
||||||
|
|
||||||
|
|
||||||
def collect_plugins_static_files():
|
def collect_plugins_static_files():
|
||||||
"""Copy static files from all installed plugins into the static directory."""
|
"""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)
|
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):
|
def copy_plugin_static_files(slug, check_reload=True):
|
||||||
"""Copy static files for the specified plugin."""
|
"""Copy static files for the specified plugin."""
|
||||||
if check_reload:
|
if check_reload:
|
||||||
|
Reference in New Issue
Block a user