Skip to content

Commit

Permalink
Merge pull request #2473 from bmaltais/2470-v2412-does-not-create-out…
Browse files Browse the repository at this point in the history
…put-folder-if-not-exist

Fix creation of output folders
  • Loading branch information
bmaltais authored May 9, 2024
2 parents a0c7e5c + 27b58a7 commit f8b30fe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
16 changes: 10 additions & 6 deletions kohya_gui/common_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1368,17 +1368,21 @@ def validate_file_path(file_path: str) -> bool:
return True


def validate_folder_path(folder_path: str, can_be_written_to: bool = False) -> bool:
def validate_folder_path(folder_path: str, can_be_written_to: bool = False, create_if_not_exists: bool = False) -> bool:
if folder_path == "":
return True
msg = f"Validating {folder_path} existence{' and writability' if can_be_written_to else ''}..."
if not os.path.isdir(folder_path):
log.error(f"{msg} FAILED: does not exist")
return False
if can_be_written_to:
if not os.access(folder_path, os.W_OK):
log.error(f"{msg} FAILED: is not writable.")
if create_if_not_exists:
os.makedirs(folder_path)
log.info(f"{msg} SUCCESS")
return True
else:
log.error(f"{msg} FAILED: does not exist")
return False
if can_be_written_to and not os.access(folder_path, os.W_OK):
log.error(f"{msg} FAILED: is not writable.")
return False
log.info(f"{msg} SUCCESS")
return True

Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/dreambooth_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,10 @@ def train_model(
if not validate_file_path(log_tracker_config):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(logging_dir, can_be_written_to=True):
if not validate_folder_path(logging_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(output_dir, can_be_written_to=True):
if not validate_folder_path(output_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_model_path(pretrained_model_name_or_path):
Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/finetune_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,10 @@ def train_model(
if not validate_file_path(log_tracker_config):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(logging_dir, can_be_written_to=True):
if not validate_folder_path(logging_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(output_dir, can_be_written_to=True):
if not validate_folder_path(output_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_model_path(pretrained_model_name_or_path):
Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ def train_model(
if not validate_file_path(log_tracker_config):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(logging_dir, can_be_written_to=True):
if not validate_folder_path(logging_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if LyCORIS_preset not in LYCORIS_PRESETS_CHOICES:
Expand All @@ -717,7 +717,7 @@ def train_model(
if not validate_file_path(network_weights):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(output_dir, can_be_written_to=True):
if not validate_folder_path(output_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_model_path(pretrained_model_name_or_path):
Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/textual_inversion_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,10 @@ def train_model(
if not validate_file_path(log_tracker_config):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(logging_dir, can_be_written_to=True):
if not validate_folder_path(logging_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_folder_path(output_dir, can_be_written_to=True):
if not validate_folder_path(output_dir, can_be_written_to=True, create_if_not_exists=True):
return TRAIN_BUTTON_VISIBLE

if not validate_model_path(pretrained_model_name_or_path):
Expand Down

0 comments on commit f8b30fe

Please sign in to comment.