Compare commits

..

5 Commits

Author SHA1 Message Date
324226f87d Merge pull request #1379 from easydiffusion/yaml-legacy-path
Handle the legacy yaml config path
2023-06-30 16:31:16 +05:30
3120b593c6 Handle the legacy yaml config path 2023-06-30 16:30:29 +05:30
d98e4772ac Merge pull request #1378 from easydiffusion/yaml-to-json
Allow main to switch back from yaml to json config files
2023-06-30 15:55:02 +05:30
cf87c34bef Allow main to switch back from yaml to json config files 2023-06-30 15:53:54 +05:30
656acafed3 Don't read config.yaml just yet in the main branch 2023-06-30 09:52:10 +05:30
2 changed files with 33 additions and 11 deletions

View File

@ -4,7 +4,7 @@ import sys
# The config file is in the same directory as this script
config_directory = os.path.dirname(__file__)
config_yaml = os.path.join(config_directory, "config.yaml")
# config_yaml = os.path.join(config_directory, "config.yaml")
config_json = os.path.join(config_directory, "config.json")
parser = argparse.ArgumentParser(description='Get values from config file')
@ -16,15 +16,16 @@ parser.add_argument('key', metavar='key', nargs='+',
args = parser.parse_args()
if os.path.isfile(config_yaml):
import yaml
with open(config_yaml, 'r') as configfile:
try:
config = yaml.safe_load(configfile)
except Exception as e:
print(e, file=sys.stderr)
config = {}
elif os.path.isfile(config_json):
# if os.path.isfile(config_yaml):
# import yaml
# with open(config_yaml, 'r') as configfile:
# try:
# config = yaml.safe_load(configfile)
# except Exception as e:
# print(e, file=sys.stderr)
# config = {}
# el
if os.path.isfile(config_json):
import json
with open(config_json, 'r') as configfile:
try:

View File

@ -100,7 +100,28 @@ def init():
def getConfig(default_val=APP_CONFIG_DEFAULTS):
try:
config_json_path = os.path.join(CONFIG_DIR, "config.json")
if not os.path.exists(config_json_path):
# compatibility with upcoming yaml changes, switching from beta to main
config_yaml_path = os.path.join(CONFIG_DIR, "..", "config.yaml")
# migrate the old config yaml location
config_legacy_yaml = os.path.join(CONFIG_DIR, "config.yaml")
if os.path.isfile(config_legacy_yaml):
shutil.move(config_legacy_yaml, config_yaml_path)
if os.path.exists(config_yaml_path):
try:
import yaml
with open(config_yaml_path, "r", encoding="utf-8") as f:
config = yaml.safe_load(f)
setConfig(config) # save to config.json
os.remove(config_yaml_path) # delete the yaml file
except:
log.warn(traceback.format_exc())
config = default_val
elif not os.path.exists(config_json_path):
config = default_val
else:
with open(config_json_path, "r", encoding="utf-8") as f: