From d82a59df1ef28d8619b81fea5962ccd63793e249 Mon Sep 17 00:00:00 2001 From: MialLewis <95620982+MialLewis@users.noreply.github.com> Date: Fri, 15 Dec 2023 10:49:48 +0000 Subject: [PATCH] add option to specify yes to all --- EVSVesuvio/analysis_runner.py | 4 ++-- EVSVesuvio/scripts/__init__.py | 9 +++++---- EVSVesuvio/vesuvio_analysis/run_script.py | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/EVSVesuvio/analysis_runner.py b/EVSVesuvio/analysis_runner.py index b3990386..a80e1f56 100644 --- a/EVSVesuvio/analysis_runner.py +++ b/EVSVesuvio/analysis_runner.py @@ -6,7 +6,7 @@ from EVSVesuvio.scripts import handle_config -def run(): +def run(yes_to_all=False): scriptName = handle_config.read_config_var('caching.experiment') experimentsPath = Path(handle_config.read_config_var('caching.location')) / "experiments" / scriptName # Path to the repository inputs_path = experimentsPath / "analysis_inputs.py" @@ -23,7 +23,7 @@ def run(): bootIC = ai.BootstrapInitialConditions userCtr = ai.UserScriptControls - runScript(userCtr, scriptName, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC) + runScript(userCtr, scriptName, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC, yes_to_all) end_time = time.time() print("\nRunning time: ", end_time-start_time, " seconds") diff --git a/EVSVesuvio/scripts/__init__.py b/EVSVesuvio/scripts/__init__.py index c1b84428..5e5164d3 100644 --- a/EVSVesuvio/scripts/__init__.py +++ b/EVSVesuvio/scripts/__init__.py @@ -14,7 +14,7 @@ def main(): if args.command == "run": if not handle_config.config_set(): __setup_config(None) - __run_analysis() + __run_analysis(args.yes) def __set_up_parser(): @@ -25,7 +25,8 @@ def __set_up_parser(): config_parser.add_argument("--set-ipfolder", "-p", help="set the intrument parameters directory", default="", type=str) config_parser.add_argument("--set-experiment", "-e", help="set the current experiment", default="", type=str) - config_parser = subparsers.add_parser("run", help="run mvesuvio analysis") + run_parser = subparsers.add_parser("run", help="run mvesuvio analysis") + run_parser.add_argument("--yes", "-y", help="Say yes to all input prompts", action='store_true') return parser @@ -52,10 +53,10 @@ def __setup_config(args): handle_config.check_dir_exists("IP folder", ipfolder_dir) -def __run_analysis(): +def __run_analysis(yes_to_all): environ['MANTIDPROPERTIES'] = path.join(handle_config.VESUVIO_CONFIG_PATH, "Mantid.user.properties") from EVSVesuvio import analysis_runner - analysis_runner.run() + analysis_runner.run(yes_to_all) if __name__ == '__main__': diff --git a/EVSVesuvio/vesuvio_analysis/run_script.py b/EVSVesuvio/vesuvio_analysis/run_script.py index eeeaecb2..c6e51f7f 100644 --- a/EVSVesuvio/vesuvio_analysis/run_script.py +++ b/EVSVesuvio/vesuvio_analysis/run_script.py @@ -6,7 +6,7 @@ from mantid.api import mtd -def runScript(userCtr, scriptName, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC): +def runScript(userCtr, scriptName, wsBackIC, wsFrontIC, bckwdIC, fwdIC, yFitIC, bootIC, yes_to_all=False): # Set extra attributes from user attributes completeICFromInputs(fwdIC, scriptName, wsFrontIC) @@ -66,7 +66,7 @@ def runProcedure(): resYFit = fitInYSpaceProcedure(yFitIC, IC, mtd[wsName]) return None, resYFit # To match return below. - checkUserClearWS() # Check if user is OK with cleaning all workspaces + checkUserClearWS(yes_to_all) # Check if user is OK with cleaning all workspaces res = runProcedure() resYFit = None @@ -76,10 +76,10 @@ def runProcedure(): return res, resYFit # Return results used only in tests -def checkUserClearWS(): +def checkUserClearWS(yes_to_all=False): """If any workspace is loaded, check if user is sure to start new procedure.""" - if len(mtd) != 0: + if not yes_to_all and len(mtd) != 0: userInput = input("This action will clean all current workspaces to start anew. Proceed? (y/n): ") if (userInput == "y") | (userInput == "Y"): pass