Use yaml instead of json for the config file

This commit is contained in:
JeLuF 2023-02-16 01:19:36 +01:00
parent fa205f483a
commit 932ee11c91
5 changed files with 88 additions and 25 deletions

View File

@ -15,6 +15,7 @@ mkdir dist\win\stable-diffusion-ui\scripts
copy scripts\on_env_start.bat dist\win\stable-diffusion-ui\scripts\
copy scripts\bootstrap.bat dist\win\stable-diffusion-ui\scripts\
copy scripts\config.yaml.sample dist\win\stable-diffusion-ui\scripts\config.yaml
copy "scripts\Start Stable Diffusion UI.cmd" dist\win\stable-diffusion-ui\
copy LICENSE dist\win\stable-diffusion-ui\
copy "CreativeML Open RAIL-M License" dist\win\stable-diffusion-ui\

View File

@ -29,6 +29,7 @@ mkdir -p dist/linux-mac/stable-diffusion-ui/scripts
cp scripts/on_env_start.sh dist/linux-mac/stable-diffusion-ui/scripts/
cp scripts/bootstrap.sh dist/linux-mac/stable-diffusion-ui/scripts/
cp scripts/functions.sh dist/linux-mac/stable-diffusion-ui/scripts/
cp scripts/config.yaml.sample dist/linux-mac/stable-diffusion-ui/scripts/config.yaml
cp scripts/start.sh dist/linux-mac/stable-diffusion-ui/
cp LICENSE dist/linux-mac/stable-diffusion-ui/
cp "CreativeML Open RAIL-M License" dist/linux-mac/stable-diffusion-ui/

View File

@ -0,0 +1,24 @@
# Change listen_port if port 9000 is already in use on your system
# Set listen_to_network to true to make Easy Diffusion accessibble on your local network
net:
listen_port: 9000
listen_to_network: false
# Multi GPU setup
render_devices: auto
# Set open_browser_on_start to false to disable opening a new browser tab on each restart
ui:
open_browser_on_start: true
# set update_branch to main to use the stable version, or to beta to use the experimental
# beta version.
update_branch: main
# Set force_save_path to enforce an auto save path. Clients will not be able to change or
# disable auto save when this option is set. Please adapt the path in the examples to your
# needs.
# Windows:
# force_save_path: C:\\Easy Diffusion Images\\
# Linux:
# force_save_path: /data/easy-diffusion-images/

View File

@ -135,6 +135,23 @@ if "%ERRORLEVEL%" EQU "0" (
)
)
@rem install ruamel.yaml
call python ..\scripts\check_modules.py ruamel.yaml
if "%ERRORLEVEL%" EQU "0" (
echo "ruamel.yaml has already been installed."
) else (
echo "Installing ruamel.yaml.."
set PYTHONNOUSERSITE=1
set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages
call python -m pip install ruamel.yaml==0.17.21 || (
echo "Error installing ruamel.yaml. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!"
pause
exit /b
)
)
set PATH=C:\Windows\System32;%PATH%
call python ..\scripts\check_modules.py uvicorn fastapi

View File

@ -5,6 +5,9 @@ import json
import traceback
import logging
import shlex
from ruamel.yaml import YAML
yaml = YAML()
from rich.logging import RichHandler
from sdkit.utils import log as sdkit_log # hack, so we can overwrite the log config
@ -54,13 +57,12 @@ def init():
update_render_threads()
def getConfig(default_val=APP_CONFIG_DEFAULTS):
config_yaml_path = os.path.join(CONFIG_DIR, 'config.yaml')
if os.path.isfile(config_yaml_path):
try:
config_json_path = os.path.join(CONFIG_DIR, 'config.json')
if not os.path.exists(config_json_path):
config = default_val
else:
with open(config_json_path, 'r', encoding='utf-8') as f:
config = json.load(f)
log.info('Loading config.yaml')
with open(config_yaml_path, 'r', encoding='utf-8') as f:
config = yaml.load(f)
if 'net' not in config:
config['net'] = {}
if os.getenv('SD_UI_BIND_PORT') is not None:
@ -75,12 +77,30 @@ def getConfig(default_val=APP_CONFIG_DEFAULTS):
except Exception as e:
log.warn(traceback.format_exc())
return default_val
else:
try:
config_json_path = os.path.join(CONFIG_DIR, 'config.json')
if not os.path.exists(config_json_path):
return default_val
else:
log.info('Converting old json config file to yaml')
with open(config_json_path, 'r', encoding='utf-8') as f:
config = json.load(f)
# Save config in new format
setConfig(config)
os.rename(config_json_path, config_json_path + '.bak')
log.info('Saved old config.json as config.json.bak')
return getConfig(default_val)
except Exception as e:
log.warn(traceback.format_exc())
return default_val
def setConfig(config):
try: # config.json
config_json_path = os.path.join(CONFIG_DIR, 'config.json')
with open(config_json_path, 'w', encoding='utf-8') as f:
json.dump(config, f)
try: # config.yaml
config_yaml_path = os.path.join(CONFIG_DIR, 'config.yaml')
yaml.indent(mapping=2, sequence=4, offset=2)
with open(config_yaml_path, 'w', encoding='utf-8') as f:
yaml.dump(config, f)
except:
log.error(traceback.format_exc())