Display error when no output plot files are generated#42
Conversation
So far, if any problem in the generation of the output plot files happened, no error message was shown to the user if the output folder already had plot files with the same names. This has been addressed by checking the last modification time of the output files: if any change in the last modification time occurs, it means the files have been generated, otherwise an exception is raised and a pop-up message is shown.
So far, if any problems arise when loading an invalid .inp file, the error message was not shown. Now, should any exception occurs, it is caught in the 'display_inp_plots' method and a pop-up message is displayed.
|
|
||
| Returns | ||
| ------- | ||
| The file last modification time, if exists; None otherwise. |
There was a problem hiding this comment.
For clarity, I'd suggest using this explanatory sentence:
"The last modification time of the file, if it exists; None otherwise."
| # Check if the files has been created after running the plot executable: | ||
| # if the time has not changed, it means that either the .dat or the .plt | ||
| # files have not been generated, hence an exception is raised. | ||
| if (modif_time0 == get_file_modification_time(datGen.dat_paths[i]) or |
There was a problem hiding this comment.
Please, check how the function "os.path.getmtime()" works. In case multiple .dat files are generated as specified in the same .inp file, they have slightly different "getmtime()" times. If, in a subsequent .dat file generation, something goes wrong with any .dat files that is not the first one, this if statement cannot identify the issue. I'd suggest trying to check whether changing the logical operator from "==" to ">" would work appropriately.
There was a problem hiding this comment.
Since the tuplot executable always overwrites any already present output file, I decided to simplify the treatment by applying the following logic:
- since the path names of the files that tuplot will generate are known, the files are removed if found in the output folder just before running the executable;
- after running the tuplot executable, the existence of these files is checked; an exception is raised if any .dat/.plt file is missing.
A specific function remove_if_file_exists has been added to the support.py module for the purpose of removing the already present files. In particular, given the path name, it tries to remove the file; if not present, the OSError exception is caught, but not re-raised as it does not imply an issue for its purpose. The exception will only be re-raised if the error type is different from the one indicating a missing file.
…g tuplot executable
| "for plotting. One or both the requested .dat/.plt files have " | ||
| "not been produced.") | ||
|
|
||
| # Build the paths of the generated plot files from the user-specified |
There was a problem hiding this comment.
The remaining portion of this for loop seems useless in case the output folder coincides with the folder of the .inp file. If so, I'd suggest avoiding to apply the remaining portion of this for loop and continue directly to the next for loop iteration. This should remove the overhead.
So far, if any problem in the generation of the output plot files happened, no error message was shown to the user if the output folder already had plot files with the same names.
This could happen either when configuring the plot from the GUI or when loading an invalid .inp file.
The issue has been addressed by checking the last modification time of the output files: now, if no change in the last modification time occurs, an exception is raised and a pop-up message is displayed.