mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 03:55:41 +00:00
Better management of plugins file
- Use file hash to determine if it should be reloaded
This commit is contained in:
@ -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 = []
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user