correctly create directory for outputs if not existing
This commit is contained in:
parent
8e62a72a63
commit
917c422ec6
|
|
@ -95,7 +95,7 @@ if isinstance(preset, str):
|
|||
print(e)
|
||||
|
||||
|
||||
def get_dir_or_set_default(key, default_value):
|
||||
def get_dir_or_set_default(key, default_value, make_directory=False):
|
||||
global config_dict, visited_keys, always_save_keys
|
||||
|
||||
if key not in visited_keys:
|
||||
|
|
@ -105,15 +105,21 @@ def get_dir_or_set_default(key, default_value):
|
|||
always_save_keys.append(key)
|
||||
|
||||
v = config_dict.get(key, None)
|
||||
if isinstance(v, str) and os.path.exists(v) and os.path.isdir(v):
|
||||
return v
|
||||
else:
|
||||
if v is not None:
|
||||
print(f'Failed to load config key: {json.dumps({key:v})} is invalid or does not exist; will use {json.dumps({key:default_value})} instead.')
|
||||
dp = os.path.abspath(os.path.join(os.path.dirname(__file__), default_value))
|
||||
os.makedirs(dp, exist_ok=True)
|
||||
config_dict[key] = dp
|
||||
return dp
|
||||
if isinstance(v, str):
|
||||
if make_directory:
|
||||
try:
|
||||
os.makedirs(v, exist_ok=True)
|
||||
except OSError as error:
|
||||
print(f'Directory {v} could not be created, reason: {error}')
|
||||
if os.path.exists(v) and os.path.isdir(v):
|
||||
return v
|
||||
|
||||
if v is not None:
|
||||
print(f'Failed to load config key: {json.dumps({key:v})} is invalid or does not exist; will use {json.dumps({key:default_value})} instead.')
|
||||
dp = os.path.abspath(os.path.join(os.path.dirname(__file__), default_value))
|
||||
os.makedirs(dp, exist_ok=True)
|
||||
config_dict[key] = dp
|
||||
return dp
|
||||
|
||||
|
||||
path_checkpoints = get_dir_or_set_default('path_checkpoints', '../models/checkpoints/')
|
||||
|
|
@ -125,7 +131,7 @@ path_inpaint = get_dir_or_set_default('path_inpaint', '../models/inpaint/')
|
|||
path_controlnet = get_dir_or_set_default('path_controlnet', '../models/controlnet/')
|
||||
path_clip_vision = get_dir_or_set_default('path_clip_vision', '../models/clip_vision/')
|
||||
path_fooocus_expansion = get_dir_or_set_default('path_fooocus_expansion', '../models/prompt_expansion/fooocus_expansion')
|
||||
path_outputs = get_dir_or_set_default('path_outputs', '../outputs/')
|
||||
path_outputs = get_dir_or_set_default('path_outputs', '../outputs/', True)
|
||||
|
||||
|
||||
def get_config_item_or_set_default(key, default_value, validator, disable_empty_as_none=False):
|
||||
|
|
@ -377,9 +383,6 @@ with open(config_example_path, "w", encoding="utf-8") as json_file:
|
|||
'and there is no "," before the last "}". \n\n\n')
|
||||
json.dump({k: config_dict[k] for k in visited_keys}, json_file, indent=4)
|
||||
|
||||
|
||||
os.makedirs(path_outputs, exist_ok=True)
|
||||
|
||||
model_filenames = []
|
||||
lora_filenames = []
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue