Skip to content

Commit 51dca1f

Browse files
committed
Fix in workspace initialization when workspace dir set does not exists
1 parent 272e3ab commit 51dca1f

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

MLC/GUI/mlc_gui.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,14 @@ def on_experiment_list_clicked(self, model_index):
426426
experiment_name = list_view.model().itemFromIndex(model_index).text()
427427
self._refresh_experiment_description(experiment_name)
428428

429-
def load_gui_config(self):
430-
abspath = os.path.abspath(".")
431-
config_filepath = os.path.join(abspath, MLC_GUI.GUI_CONFIG_FILE)
432-
workspace_dir = ""
429+
def _set_workspace_dir(self, cfg_file, workspace_exists=False):
430+
if not os.path.isfile(cfg_file) or workspace_exists == True:
431+
workspace_exists_msg = "Workspace set does not exist anymore. Do you want to reset it?"
432+
workspace_doesnt_exists_msg = "Workspace has not been set yet. Do you want to set it?"
433+
initial_msg = workspace_exists_msg if workspace_exists else workspace_doesnt_exists_msg
433434

434-
if not os.path.isfile(config_filepath):
435435
reply = QMessageBox.question(self, 'Message',
436-
"Workspace has not been set yet. Do you want to set it?",
436+
initial_msg,
437437
QMessageBox.Yes | QMessageBox.No,
438438
QMessageBox.Yes)
439439

@@ -455,17 +455,33 @@ def load_gui_config(self):
455455
self.close()
456456
sys.exit(0)
457457

458-
self._create_gui_config_from_scratch(config_filepath, workspace_dir)
458+
if not workspace_exists:
459+
self._create_gui_config_from_scratch(cfg_file, workspace_dir)
460+
459461
QMessageBox.information(self, 'MLC Manager',
460462
'Workspace was succesfully set',
461463
QMessageBox.Ok)
462464
logger.debug('[MLC_GUI] [LOAD_GUI] - Workspace was succesfully set: {0}'.format(workspace_dir))
465+
return workspace_dir
466+
467+
def load_gui_config(self):
468+
abspath = os.path.abspath(".")
469+
config_filepath = os.path.join(abspath, MLC_GUI.GUI_CONFIG_FILE)
470+
workspace_dir = self._set_workspace_dir(cfg_file=config_filepath,
471+
workspace_exists=False)
463472

464473
# Load GUI config
465474
self._gui_config = ConfigParser.ConfigParser()
466475
self._gui_config.read(config_filepath)
467476
workspace_dir = self._gui_config.get('MAIN', 'workspace')
468477

478+
# Check if workspace exists
479+
if not os.path.exists(workspace_dir):
480+
workspace_dir = self._set_workspace_dir(cfg_file=config_filepath,
481+
workspace_exists=True)
482+
self._gui_config.set('MAIN', 'workspace', workspace_dir)
483+
self._gui_config.write(open(config_filepath, "wt"))
484+
469485
# Create the MLC Local instance and initialize the Experiments_Manager
470486
self._mlc_local = MLCLocal(workspace_dir)
471487
self._experiments_manager = ExperimentsManager(self._mlc_local, self._gui_config)

0 commit comments

Comments
 (0)