2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-15 19:45:46 +00:00

Better management of plugins file

- Use file hash to determine if it should be reloaded
This commit is contained in:
Oliver Walters
2024-11-18 09:33:00 +00:00
parent 76cd6e019b
commit cdce6815eb
3 changed files with 22 additions and 11 deletions

View File

@ -160,7 +160,8 @@ PLUGIN_RETRY = get_setting(
'INVENTREE_PLUGIN_RETRY', 'PLUGIN_RETRY', 3, typecast=int
) # How often should plugin loading be tried?
PLUGIN_FILE_CHECKED = False # Was the plugin file checked?
# Hash of the plugin file (will be updated on each change)
PLUGIN_FILE_HASH = ''
STATICFILES_DIRS = []

View File

@ -103,6 +103,19 @@ def get_install_info(packagename: str) -> str:
return info
def plugins_file_hash():
"""Return the file hash for the plugins file."""
import hashlib
pf = settings.PLUGIN_FILE
if not pf or not pf.exists():
return None
with pf.open('rb') as f:
return hashlib.md5(f.read()).hexdigest()
def install_plugins_file():
"""Install plugins from the plugins file."""
logger.info('Installing plugins from plugins file')
@ -127,9 +140,8 @@ def install_plugins_file():
log_error('pip')
return False
# Update static files
# Collect plugin static files
plugin.staticfiles.collect_plugins_static_files()
plugin.staticfiles.clear_plugins_static_files()
# At this point, the plugins file has been installed
return True

View File

@ -287,6 +287,7 @@ class PluginsRegistry:
if collect:
logger.info('Collecting plugins')
self.install_plugin_file()
self.plugin_modules = self.collect_plugins()
self.plugins_loaded = False
@ -430,16 +431,13 @@ class PluginsRegistry:
def install_plugin_file(self):
"""Make sure all plugins are installed in the current environment."""
if settings.PLUGIN_FILE_CHECKED:
logger.info('Plugin file was already checked')
return True
from plugin.installer import install_plugins_file, plugins_file_hash
from plugin.installer import install_plugins_file
file_hash = plugins_file_hash()
if install_plugins_file():
settings.PLUGIN_FILE_CHECKED = True
return 'first_run'
return False
if file_hash != settings.PLUGIN_FILE_HASH:
install_plugins_file()
settings.PLUGIN_FILE_HASH = file_hash
# endregion