mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
correctly create directory for outputs if not existing
This commit is contained in:
+10
-7
@@ -95,7 +95,7 @@ if isinstance(preset, str):
|
|||||||
print(e)
|
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
|
global config_dict, visited_keys, always_save_keys
|
||||||
|
|
||||||
if key not in visited_keys:
|
if key not in visited_keys:
|
||||||
@@ -105,9 +105,15 @@ def get_dir_or_set_default(key, default_value):
|
|||||||
always_save_keys.append(key)
|
always_save_keys.append(key)
|
||||||
|
|
||||||
v = config_dict.get(key, None)
|
v = config_dict.get(key, None)
|
||||||
if isinstance(v, str) and os.path.exists(v) and os.path.isdir(v):
|
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
|
return v
|
||||||
else:
|
|
||||||
if v is not None:
|
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.')
|
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))
|
dp = os.path.abspath(os.path.join(os.path.dirname(__file__), default_value))
|
||||||
@@ -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_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_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_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):
|
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')
|
'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)
|
json.dump({k: config_dict[k] for k in visited_keys}, json_file, indent=4)
|
||||||
|
|
||||||
|
|
||||||
os.makedirs(path_outputs, exist_ok=True)
|
|
||||||
|
|
||||||
model_filenames = []
|
model_filenames = []
|
||||||
lora_filenames = []
|
lora_filenames = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user