mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Merge pull request #4628 from OPM/feature-python-command-line
#4610 Python: Add support for sending in command line arguments when launching ResInsight
This commit is contained in:
@@ -713,7 +713,7 @@ if (RESINSIGHT_PRIVATE_INSTALL)
|
|||||||
add_custom_command(
|
add_custom_command(
|
||||||
TARGET ResInsight
|
TARGET ResInsight
|
||||||
POST_BUILD
|
POST_BUILD
|
||||||
COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} -m pip install --target=${CMAKE_BINARY_DIR}/Python grpcio
|
COMMAND ${RESINSIGHT_GRPC_PYTHON_EXECUTABLE} -m pip install --target=${GRPC_PYTHON_SOURCE_PATH} grpcio
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
install(DIRECTORY ${GRPC_PYTHON_SOURCE_PATH}/ DESTINATION ${RESINSIGHT_INSTALL_FOLDER}/Python)
|
install(DIRECTORY ${GRPC_PYTHON_SOURCE_PATH}/ DESTINATION ${RESINSIGHT_INSTALL_FOLDER}/Python)
|
||||||
|
|||||||
@@ -203,11 +203,6 @@ if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
|
|||||||
"LICENSE"
|
"LICENSE"
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach(PYTHON_SCRIPT ${GRPC_PYTHON_SOURCES})
|
|
||||||
# Copy into build folder so the python code is present for debugging
|
|
||||||
configure_file("${GRPC_PYTHON_SOURCE_PATH}/${PYTHON_SCRIPT}" "${CMAKE_BINARY_DIR}/Python/${PYTHON_SCRIPT}" COPYONLY)
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
list(APPEND GRPC_PYTHON_SOURCES ${GRPC_PYTHON_GENERATED_SOURCES})
|
list(APPEND GRPC_PYTHON_SOURCES ${GRPC_PYTHON_GENERATED_SOURCES})
|
||||||
|
|
||||||
foreach(PYTHON_SCRIPT ${GRPC_PYTHON_SOURCES})
|
foreach(PYTHON_SCRIPT ${GRPC_PYTHON_SOURCES})
|
||||||
|
|||||||
@@ -5,3 +5,6 @@ dist
|
|||||||
build
|
build
|
||||||
rips.egg-info
|
rips.egg-info
|
||||||
setup.py
|
setup.py
|
||||||
|
grpc
|
||||||
|
grpcio*
|
||||||
|
six*
|
||||||
@@ -33,7 +33,7 @@ class Instance:
|
|||||||
return s.connect_ex(('localhost', port)) == 0
|
return s.connect_ex(('localhost', port)) == 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def launch(resInsightExecutable = '', console = False):
|
def launch(resInsightExecutable = '', console = False, launchPort = -1, commandLineParameters=[]):
|
||||||
""" Launch a new Instance of ResInsight. This requires the environment variable
|
""" Launch a new Instance of ResInsight. This requires the environment variable
|
||||||
RESINSIGHT_EXECUTABLE to be set or the parameter resInsightExecutable to be provided.
|
RESINSIGHT_EXECUTABLE to be set or the parameter resInsightExecutable to be provided.
|
||||||
The RESINSIGHT_GRPC_PORT environment variable can be set to an alternative port number.
|
The RESINSIGHT_GRPC_PORT environment variable can be set to an alternative port number.
|
||||||
@@ -43,6 +43,9 @@ class Instance:
|
|||||||
will take precedence over what is provided in the RESINSIGHT_EXECUTABLE
|
will take precedence over what is provided in the RESINSIGHT_EXECUTABLE
|
||||||
environment variable.
|
environment variable.
|
||||||
console (bool): If True, launch as console application, without GUI.
|
console (bool): If True, launch as console application, without GUI.
|
||||||
|
launchPort(int): If -1 will use the default port of 50051 or look for RESINSIGHT_GRPC_PORT
|
||||||
|
if anything else, ResInsight will try to launch with this port
|
||||||
|
commandLineParameters(list): Additional command line parameters as string entries in the list.
|
||||||
Returns:
|
Returns:
|
||||||
Instance: an instance object if it worked. None if not.
|
Instance: an instance object if it worked. None if not.
|
||||||
"""
|
"""
|
||||||
@@ -51,6 +54,8 @@ class Instance:
|
|||||||
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
portEnv = os.environ.get('RESINSIGHT_GRPC_PORT')
|
||||||
if portEnv:
|
if portEnv:
|
||||||
port = int(portEnv)
|
port = int(portEnv)
|
||||||
|
if launchPort is not -1:
|
||||||
|
port = launchPort
|
||||||
|
|
||||||
if not resInsightExecutable:
|
if not resInsightExecutable:
|
||||||
resInsightExecutable = os.environ.get('RESINSIGHT_EXECUTABLE')
|
resInsightExecutable = os.environ.get('RESINSIGHT_EXECUTABLE')
|
||||||
@@ -64,10 +69,19 @@ class Instance:
|
|||||||
|
|
||||||
print('Port ' + str(port))
|
print('Port ' + str(port))
|
||||||
print('Trying to launch', resInsightExecutable)
|
print('Trying to launch', resInsightExecutable)
|
||||||
parameters = ["ResInsight", "--server", str(port)]
|
|
||||||
|
if isinstance(commandLineParameters, str):
|
||||||
|
commandLineParameters = [str]
|
||||||
|
|
||||||
|
parameters = ["ResInsight", "--server", str(port)] + commandLineParameters
|
||||||
if console:
|
if console:
|
||||||
print("Launching as console app")
|
print("Launching as console app")
|
||||||
parameters.append("--console")
|
parameters.append("--console")
|
||||||
|
|
||||||
|
# Stringify all parameters
|
||||||
|
for i in range(0, len(parameters)):
|
||||||
|
parameters[i] = str(parameters[i])
|
||||||
|
|
||||||
pid = os.spawnv(os.P_NOWAIT, resInsightExecutable, parameters)
|
pid = os.spawnv(os.P_NOWAIT, resInsightExecutable, parameters)
|
||||||
if pid:
|
if pid:
|
||||||
instance = Instance(port=port, launched=True)
|
instance = Instance(port=port, launched=True)
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Load ResInsight Processing Server Client Library
|
||||||
|
import rips
|
||||||
|
# Launch ResInsight with last project file and a Window size of 600x1000 pixels
|
||||||
|
resInsight = rips.Instance.launch(commandLineParameters=['--last', '--size', 600, 1000])
|
||||||
|
# Get a list of all cases
|
||||||
|
cases = resInsight.project.cases()
|
||||||
|
|
||||||
|
print ("Got " + str(len(cases)) + " cases: ")
|
||||||
|
for case in cases:
|
||||||
|
print("Case name: " + case.name)
|
||||||
|
print("Case grid path: " + case.gridPath())
|
||||||
Reference in New Issue
Block a user