From dfc9a8dd40e90dea40e044ea91514dddad53bb2d Mon Sep 17 00:00:00 2001 From: bmaltais Date: Mon, 20 Feb 2023 07:56:24 -0500 Subject: [PATCH] Fix issue with save config --- dreambooth_gui.py | 7 +++++++ finetune_gui.py | 11 +++++++++-- lora_gui.py | 7 +++++++ textual_inversion_gui.py | 11 +++++++---- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/dreambooth_gui.py b/dreambooth_gui.py index a58c333..1db8668 100644 --- a/dreambooth_gui.py +++ b/dreambooth_gui.py @@ -122,6 +122,13 @@ def save_configuration( ] } + # Extract the destination directory from the file path + destination_directory = os.path.dirname(file_path) + + # Create the destination directory if it doesn't exist + if not os.path.exists(destination_directory): + os.makedirs(destination_directory) + # Save the data to the selected file with open(file_path, 'w') as file: json.dump(variables, file, indent=2) diff --git a/finetune_gui.py b/finetune_gui.py index 01f04d1..4200dd5 100644 --- a/finetune_gui.py +++ b/finetune_gui.py @@ -104,8 +104,8 @@ def save_configuration( # print(file_path) - if file_path == None: - return original_file_path + if file_path == None or file_path == '': + return original_file_path # In case a file_path was provided and the user decide to cancel the open action # Return the values of the variables as a dictionary variables = { @@ -118,6 +118,13 @@ def save_configuration( ] } + # Extract the destination directory from the file path + destination_directory = os.path.dirname(file_path) + + # Create the destination directory if it doesn't exist + if not os.path.exists(destination_directory): + os.makedirs(destination_directory) + # Save the data to the selected file with open(file_path, 'w') as file: json.dump(variables, file, indent=2) diff --git a/lora_gui.py b/lora_gui.py index 9d3df33..efd4feb 100644 --- a/lora_gui.py +++ b/lora_gui.py @@ -133,6 +133,13 @@ def save_configuration( ] } + # Extract the destination directory from the file path + destination_directory = os.path.dirname(file_path) + + # Create the destination directory if it doesn't exist + if not os.path.exists(destination_directory): + os.makedirs(destination_directory) + # Save the data to the selected file with open(file_path, 'w') as file: json.dump(variables, file, indent=2) diff --git a/textual_inversion_gui.py b/textual_inversion_gui.py index 7ceffb1..fc73d73 100644 --- a/textual_inversion_gui.py +++ b/textual_inversion_gui.py @@ -117,10 +117,6 @@ def save_configuration( if file_path == None or file_path == '': return original_file_path # In case a file_path was provided and the user decide to cancel the open action - directory = os.path.dirname(file_path) - if not os.path.exists(directory): - os.makedirs(directory) - # Return the values of the variables as a dictionary variables = { name: value @@ -132,6 +128,13 @@ def save_configuration( ] } + # Extract the destination directory from the file path + destination_directory = os.path.dirname(file_path) + + # Create the destination directory if it doesn't exist + if not os.path.exists(destination_directory): + os.makedirs(destination_directory) + # Save the data to the selected file with open(file_path, 'w') as file: json.dump(variables, file, indent=2)