Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
update rms script to use argparse
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSava committed Sep 2, 2019
1 parent 18a1953 commit 50fcf7a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 17 deletions.
8 changes: 8 additions & 0 deletions python/tests/res/fm/test_rms_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,15 @@ def test_rms_load_env(self):
rms_exec = os.path.join(self.SOURCE_ROOT, 'share/ert/forward-models/res/script/rms')
subprocess.check_call([
rms_exec,
'--run-path',
'run_path',
'0',
'--version',
'10.4',
'project',
'--import-path',
'./',
'--export-path',
'./',
'workflow',
])
Expand Down Expand Up @@ -221,11 +225,15 @@ def test_rms_drop_env(self):
rms_exec = os.path.join(self.SOURCE_ROOT, 'share/ert/forward-models/res/script/rms')
subprocess.check_call([
rms_exec,
'--run-path',
'run_path',
'0',
'--version',
'10.4',
'project',
'--import-path',
'./',
'--export-path',
'./',
'workflow',
])
Expand Down
2 changes: 1 addition & 1 deletion share/ert/forward-models/old_style/RMS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ DEFAULT <RMS_IMPORT_PATH> ./
DEFAULT <RMS_EXPORT_PATH> ./
DEFAULT <RMS_RUNPATH> rms/model
TARGET_FILE <RMS_TARGET_FILE>
ARGLIST <RMS_RUNPATH> <IENS> <RMS_VERSION> <RMS_PROJECT> <RMS_EXPORT_PATH> <RMS_IMPORT_PATH> <RMS_WORKFLOW>
ARGLIST <IENS> <RMS_PROJECT> <RMS_WORKFLOW> "--run-path=<RMS_RUNPATH>" "--target-file=<RMS_TARGET_FILE>" "--import-path=<RMS_IMPORT_PATH>" "--version=<RMS_VERSION>" "--export-path=<RMS_EXPORT_PATH>"

EXEC_ENV PYTHONPATH <RMS_PYTHONPATH>
83 changes: 67 additions & 16 deletions share/ert/forward-models/res/script/rms
Original file line number Diff line number Diff line change
@@ -1,21 +1,72 @@
#!/usr/bin/env python
import sys
import argparse
from res.fm.rms import run

run_path = sys.argv[1]
iens = int(sys.argv[2])
version = sys.argv[3]
project = sys.argv[4]
export_path = sys.argv[5]
import_path = sys.argv[6]
workflow = sys.argv[7]

run(iens,
project,
workflow,
run_path,
target_file=None,
import_path=import_path,
export_path=export_path,
version=version,
def _build_argument_parser():
description = 'Wrapper script to run rms.'
usage = ('The script must be invoked with minimum three positional arguments:\n\n'
' rms iens project workflow \n\n'
'Optional arguments supported: \n'
' target file [-t][--target-file]\n'
' run path [-t][--run-path] default=rms/model\n'
' import path [-i][--import-path] default=./ \n'
' export path [-e][--export-path] default=./ \n'
' version [-v][--version]\n')
parser = argparse.ArgumentParser(description=description, usage=usage)
parser.add_argument(
'iens',
help='Realization number',
)
parser.add_argument(
'project',
help='The RMS project we are running',
)
parser.add_argument(
'workflow',
help='The rms workflow we intend to run',
)
parser.add_argument(
'-r', '--run-path',
default='rms/model',
help='The directory which will be used as cwd when running rms',
)
parser.add_argument(
'-t', '--target-file',
default=None,
help='name of file which should be created/updated by rms',
)
parser.add_argument(
'-i', '--import-path',
default='./',
help='the prefix of all relative paths when rms is importing',
)
parser.add_argument(
'-e', '--export-path',
default='./',
help='the prefix of all relative paths when rms is exporting',
)
parser.add_argument(
'-v', '--version',
default=None,
help='the prefix of all relative paths when rms is exporting',
)
return parser


# The first three arguments; iens, project and workflow are positional
# and *must* be supplied. The run_path and target_file arguments are optional.

if __name__ == '__main__':
arg_parser = _build_argument_parser()
args = arg_parser.parse_args()

run(args.iens,
args.project,
args.workflow,
run_path=args.run_path,
target_file=args.target_file,
import_path=args.import_path,
export_path=args.export_path,
version=args.version
)

0 comments on commit 50fcf7a

Please sign in to comment.