Skip to content

Commit

Permalink
Merge pull request #80 from mantidproject/0_add_yes_option
Browse files Browse the repository at this point in the history
Add yes option to Vesuvio CLI
  • Loading branch information
MialLewis authored Dec 15, 2023
2 parents 96e2593 + d82a59d commit 744a625
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions EVSVesuvio/analysis_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down
9 changes: 5 additions & 4 deletions EVSVesuvio/scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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


Expand All @@ -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__':
Expand Down
8 changes: 4 additions & 4 deletions EVSVesuvio/vesuvio_analysis/run_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 744a625

Please sign in to comment.