From 844c23975f369f85c7179379ec419e1bd067de18 Mon Sep 17 00:00:00 2001 From: Nick Harrison <42382362+nickpharrison@users.noreply.github.com> Date: Sun, 29 Oct 2023 15:40:58 +0000 Subject: Add assertions for checking additional settings freezing parameters --- modules/options.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'modules/options.py') diff --git a/modules/options.py b/modules/options.py index ab40aff7..1ac32d95 100644 --- a/modules/options.py +++ b/modules/options.py @@ -85,18 +85,35 @@ class Options: if self.data is not None: if key in self.data or key in self.data_labels: + + # Check that settings aren't globally frozen assert not cmd_opts.freeze_settings, "changing settings is disabled" + # Get the info related to the setting being changed info = self.data_labels.get(key, None) if info.do_not_save: return + # Restrict component arguments comp_args = info.component_args if info else None if isinstance(comp_args, dict) and comp_args.get('visible', True) is False: - raise RuntimeError(f"not possible to set {key} because it is restricted") + raise RuntimeError(f"not possible to set '{key}' because it is restricted") + # Check that this section isn't frozen + if cmd_opts.freeze_settings_in_sections is not None: + frozen_sections = list(map(str.strip, cmd_opts.freeze_settings_in_sections.split(','))) # Trim whitespace from section names + section_key = info.section[0] + section_name = info.section[1] + assert section_key not in frozen_sections, f"not possible to set '{key}' because settings in section '{section_name}' ({section_key}) are frozen with --freeze-settings-in-sections" + + # Check that this section of the settings isn't frozen + if cmd_opts.freeze_specific_settings is not None: + frozen_keys = list(map(str.strip, cmd_opts.freeze_specific_settings.split(','))) # Trim whitespace from setting keys + assert key not in frozen_keys, f"not possible to set '{key}' because this setting is frozen with --freeze-specific-settings" + + # Check shorthand option which disables editing options in "saving-paths" if cmd_opts.hide_ui_dir_config and key in self.restricted_opts: - raise RuntimeError(f"not possible to set {key} because it is restricted") + raise RuntimeError(f"not possible to set '{key}' because it is restricted with --hide_ui_dir_config") self.data[key] = value return @@ -210,8 +227,6 @@ class Options: def add_option(self, key, info): self.data_labels[key] = info - if key not in self.data: - self.data[key] = info.default def reorder(self): """reorder settings so that all items related to section always go together""" -- cgit v1.2.3 From be31e7e71a08dc27543d31aa6e6532463ccbf20f Mon Sep 17 00:00:00 2001 From: Nick Harrison <42382362+nickpharrison@users.noreply.github.com> Date: Sun, 29 Oct 2023 16:05:01 +0000 Subject: Remove blank line whitespace --- modules/options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/options.py') diff --git a/modules/options.py b/modules/options.py index 1ac32d95..e270a42d 100644 --- a/modules/options.py +++ b/modules/options.py @@ -85,7 +85,7 @@ class Options: if self.data is not None: if key in self.data or key in self.data_labels: - + # Check that settings aren't globally frozen assert not cmd_opts.freeze_settings, "changing settings is disabled" -- cgit v1.2.3 From 50158a1fc9b4dd47a7bef70d34fbb0b30d5e8b47 Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Thu, 4 Jan 2024 06:21:53 +0900 Subject: handle config.json failed to load --- modules/options.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'modules/options.py') diff --git a/modules/options.py b/modules/options.py index 09ff9403..503b40e9 100644 --- a/modules/options.py +++ b/modules/options.py @@ -1,3 +1,4 @@ +import os import json import sys from dataclasses import dataclass @@ -6,6 +7,7 @@ import gradio as gr from modules import errors from modules.shared_cmd_options import cmd_opts +from modules.paths_internal import script_path class OptionInfo: @@ -193,9 +195,13 @@ class Options: return type_x == type_y def load(self, filename): - with open(filename, "r", encoding="utf8") as file: - self.data = json.load(file) - + try: + with open(filename, "r", encoding="utf8") as file: + self.data = json.load(file) + except Exception: + errors.report(f'\nCould not load settings\nThe config file "{filename}" is likely corrupted\nIt has been moved to the "tmp/config.json"\nReverting config to default\n\n''', exc_info=True) + os.replace(filename, os.path.join(script_path, "tmp", "config.json")) + self.data = {} # 1.6.0 VAE defaults if self.data.get('sd_vae_as_default') is not None and self.data.get('sd_vae_overrides_per_model_preferences') is None: self.data['sd_vae_overrides_per_model_preferences'] = not self.data.get('sd_vae_as_default') -- cgit v1.2.3 From 47cf92039b524bb6dad05e96607208b8b9df7ede Mon Sep 17 00:00:00 2001 From: w-e-w <40751091+w-e-w@users.noreply.github.com> Date: Fri, 26 Jan 2024 17:16:53 +0900 Subject: minor fix to #14525 --- modules/options.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'modules/options.py') diff --git a/modules/options.py b/modules/options.py index 503b40e9..35ccade2 100644 --- a/modules/options.py +++ b/modules/options.py @@ -198,6 +198,8 @@ class Options: try: with open(filename, "r", encoding="utf8") as file: self.data = json.load(file) + except FileNotFoundError: + self.data = {} except Exception: errors.report(f'\nCould not load settings\nThe config file "{filename}" is likely corrupted\nIt has been moved to the "tmp/config.json"\nReverting config to default\n\n''', exc_info=True) os.replace(filename, os.path.join(script_path, "tmp", "config.json")) -- cgit v1.2.3