mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 12:35:46 +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
|
'INVENTREE_PLUGIN_RETRY', 'PLUGIN_RETRY', 3, typecast=int
|
||||||
) # How often should plugin loading be tried?
|
) # 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 = []
|
STATICFILES_DIRS = []
|
||||||
|
|
||||||
|
@ -103,6 +103,19 @@ def get_install_info(packagename: str) -> str:
|
|||||||
return info
|
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():
|
def install_plugins_file():
|
||||||
"""Install plugins from the plugins file."""
|
"""Install plugins from the plugins file."""
|
||||||
logger.info('Installing plugins from plugins file')
|
logger.info('Installing plugins from plugins file')
|
||||||
@ -127,9 +140,8 @@ def install_plugins_file():
|
|||||||
log_error('pip')
|
log_error('pip')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Update static files
|
# Collect plugin static files
|
||||||
plugin.staticfiles.collect_plugins_static_files()
|
plugin.staticfiles.collect_plugins_static_files()
|
||||||
plugin.staticfiles.clear_plugins_static_files()
|
|
||||||
|
|
||||||
# At this point, the plugins file has been installed
|
# At this point, the plugins file has been installed
|
||||||
return True
|
return True
|
||||||
|
@ -287,6 +287,7 @@ class PluginsRegistry:
|
|||||||
|
|
||||||
if collect:
|
if collect:
|
||||||
logger.info('Collecting plugins')
|
logger.info('Collecting plugins')
|
||||||
|
self.install_plugin_file()
|
||||||
self.plugin_modules = self.collect_plugins()
|
self.plugin_modules = self.collect_plugins()
|
||||||
|
|
||||||
self.plugins_loaded = False
|
self.plugins_loaded = False
|
||||||
@ -430,16 +431,13 @@ class PluginsRegistry:
|
|||||||
|
|
||||||
def install_plugin_file(self):
|
def install_plugin_file(self):
|
||||||
"""Make sure all plugins are installed in the current environment."""
|
"""Make sure all plugins are installed in the current environment."""
|
||||||
if settings.PLUGIN_FILE_CHECKED:
|
from plugin.installer import install_plugins_file, plugins_file_hash
|
||||||
logger.info('Plugin file was already checked')
|
|
||||||
return True
|
|
||||||
|
|
||||||
from plugin.installer import install_plugins_file
|
file_hash = plugins_file_hash()
|
||||||
|
|
||||||
if install_plugins_file():
|
if file_hash != settings.PLUGIN_FILE_HASH:
|
||||||
settings.PLUGIN_FILE_CHECKED = True
|
install_plugins_file()
|
||||||
return 'first_run'
|
settings.PLUGIN_FILE_HASH = file_hash
|
||||||
return False
|
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user