mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-01-16 10:48:46 -05:00
Override init fix of schedules
This commit is contained in:
@@ -1289,7 +1289,7 @@ input[readonly] {
|
||||
|
||||
#tableDevices .fab
|
||||
{
|
||||
font-size: 1.5em;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
#tableDevices .fa
|
||||
|
||||
@@ -17,7 +17,7 @@ from logger import mylog
|
||||
from api import update_api
|
||||
from scheduler import schedule_class
|
||||
from plugin import print_plugin_info, run_plugin_scripts
|
||||
from plugin_utils import get_plugins_configs, get_plugin_setting_obj
|
||||
from plugin_utils import get_plugins_configs, get_plugin_setting_obj, get_set_value_for_init
|
||||
from notification import write_notification
|
||||
|
||||
#===============================================================================
|
||||
@@ -212,21 +212,10 @@ def importConfigs (db, all_plugins):
|
||||
# ...or based on if is already enabled, or if the default configuration loads the plugin (RUN function != disabled )
|
||||
|
||||
# get default plugin run value
|
||||
plugin_run = ''
|
||||
setting_obj = get_plugin_setting_obj(plugin, "RUN")
|
||||
|
||||
if setting_obj is not None:
|
||||
set_type = setting_obj.get('type') # lower case "type" - default json value vs uppper-case "setType" (= from user defined settings)
|
||||
set_value = setting_obj.get('default_value')
|
||||
|
||||
plugin_run = setting_value_to_python_type(set_type, set_value)
|
||||
|
||||
# get user-defined run value if available
|
||||
if pref + "_RUN" in c_d:
|
||||
plugin_run = c_d[pref + "_RUN" ]
|
||||
plugin_run = get_set_value_for_init(plugin, c_d, "RUN")
|
||||
|
||||
# only include loaded plugins, and the ones that are enabled
|
||||
if pref in conf.LOADED_PLUGINS or plugin_run != 'disabled' or setting_obj is None or plugin_run is None:
|
||||
if pref in conf.LOADED_PLUGINS or plugin_run != 'disabled' or plugin_run is None:
|
||||
|
||||
stringSqlParams = []
|
||||
|
||||
@@ -327,20 +316,10 @@ def importConfigs (db, all_plugins):
|
||||
mylog('debug', [f"[Config] File {app_conf_override_path} does not exist."])
|
||||
|
||||
# setup execution schedules AFTER OVERRIDE handling
|
||||
index = 0
|
||||
for plugin in all_plugins:
|
||||
|
||||
pref = plugin["unique_prefix"]
|
||||
|
||||
plugin_run = ''
|
||||
|
||||
# get user-defined run value if available
|
||||
if pref + "_RUN" in c_d:
|
||||
plugin_run = c_d[pref + "_RUN" ]
|
||||
|
||||
for plugin in all_plugins:
|
||||
# Setup schedules
|
||||
if plugin_run == 'schedule':
|
||||
newSchedule = Cron(c_d[pref + "_RUN_SCHD" ]).schedule(start_date=datetime.datetime.now(conf.tz))
|
||||
if get_set_value_for_init(plugin, c_d, "RUN") == 'schedule':
|
||||
newSchedule = Cron(get_set_value_for_init(plugin, c_d, "RUN_SCHD")).schedule(start_date=datetime.datetime.now(conf.tz))
|
||||
conf.mySchedules.append(schedule_class(pref, newSchedule, newSchedule.next(), False))
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import json
|
||||
import conf
|
||||
from logger import mylog
|
||||
from const import pluginsPath, logPath, apiPath
|
||||
from helper import timeNowTZ, updateState, get_file_content, write_file, get_setting, get_setting_value
|
||||
from helper import timeNowTZ, updateState, get_file_content, write_file, get_setting, get_setting_value, setting_value_to_python_type
|
||||
from crypto_utils import decrypt_data
|
||||
|
||||
module_name = 'Plugin utils'
|
||||
@@ -305,4 +305,45 @@ def decode_and_rename_files(file_dir, file_prefix):
|
||||
else:
|
||||
mylog('debug', [f'[Plugins] The file {file_path} does not exist'])
|
||||
|
||||
return files_to_process
|
||||
return files_to_process
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Retrieve the value for a plugin's setting, prioritizing user-defined values over defaults.
|
||||
def get_set_value_for_init(plugin, c_d, setting_key):
|
||||
"""
|
||||
Retrieve the value for a plugin's setting, prioritizing user-defined values over defaults.
|
||||
|
||||
Args:
|
||||
plugin (str): The name or identifier of the plugin.
|
||||
pref (str): Prefix for user-defined settings (e.g., plugin identifier prefix).
|
||||
c_d (dict): Dictionary containing user-defined settings.
|
||||
setting_key (str): The key for the setting to fetch (default is 'RUN').
|
||||
|
||||
Returns:
|
||||
Any: The value for the specified setting, converted to an appropriate Python type.
|
||||
"""
|
||||
|
||||
pref = plugin["unique_prefix"]
|
||||
|
||||
# Step 1: Initialize the setting value as an empty string
|
||||
setting_value = ''
|
||||
|
||||
# Step 2: Get the default setting object for the plugin's specified key
|
||||
setting_obj = get_plugin_setting_obj(plugin, setting_key)
|
||||
|
||||
if setting_obj is not None:
|
||||
# Retrieve the type and default value from the setting object
|
||||
set_type = setting_obj.get('type') # Lowercase 'type'
|
||||
set_value = setting_obj.get('default_value')
|
||||
|
||||
# Convert the value to the appropriate Python type
|
||||
setting_value = setting_value_to_python_type(set_type, set_value)
|
||||
|
||||
# Step 3: Check for user-defined setting value in the dictionary
|
||||
user_key = f"{pref}_{setting_key}"
|
||||
if user_key in c_d:
|
||||
setting_value = c_d[user_key]
|
||||
|
||||
# Return the final setting value
|
||||
return setting_value
|
||||
|
||||
Reference in New Issue
Block a user