From 72a954e9f76110ee37e369fb47b912d688434d70 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Fri, 23 Aug 2019 15:25:26 +0200 Subject: [PATCH 1/2] Python: Stop copying Python files to build folder. --- ApplicationCode/CMakeLists.txt | 2 +- ApplicationCode/GrpcInterface/CMakeLists.cmake | 7 +------ ApplicationCode/GrpcInterface/Python/.gitignore | 3 +++ 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/ApplicationCode/CMakeLists.txt b/ApplicationCode/CMakeLists.txt index 5a8704384b..01761782ed 100644 --- a/ApplicationCode/CMakeLists.txt +++ b/ApplicationCode/CMakeLists.txt @@ -713,7 +713,7 @@ if (RESINSIGHT_PRIVATE_INSTALL) add_custom_command( TARGET ResInsight 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() install(DIRECTORY ${GRPC_PYTHON_SOURCE_PATH}/ DESTINATION ${RESINSIGHT_INSTALL_FOLDER}/Python) diff --git a/ApplicationCode/GrpcInterface/CMakeLists.cmake b/ApplicationCode/GrpcInterface/CMakeLists.cmake index 4bd57c097b..6271a0ad20 100644 --- a/ApplicationCode/GrpcInterface/CMakeLists.cmake +++ b/ApplicationCode/GrpcInterface/CMakeLists.cmake @@ -202,12 +202,7 @@ if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE) "README.md" "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}) foreach(PYTHON_SCRIPT ${GRPC_PYTHON_SOURCES}) diff --git a/ApplicationCode/GrpcInterface/Python/.gitignore b/ApplicationCode/GrpcInterface/Python/.gitignore index b95f862edb..d740b896f4 100644 --- a/ApplicationCode/GrpcInterface/Python/.gitignore +++ b/ApplicationCode/GrpcInterface/Python/.gitignore @@ -5,3 +5,6 @@ dist build rips.egg-info setup.py +grpc +grpcio* +six* \ No newline at end of file From f279aeced70cc1a5e60325efdeba04e161d41441 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Fri, 23 Aug 2019 15:26:31 +0200 Subject: [PATCH 2/2] #4610 Enable command line options and port number in rips.Instance.launch() --- .../GrpcInterface/Python/rips/Instance.py | 18 ++++++++++++++++-- .../LaunchWithCommandLineOptions.py | 11 +++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 ApplicationCode/GrpcInterface/Python/rips/PythonExamples/LaunchWithCommandLineOptions.py diff --git a/ApplicationCode/GrpcInterface/Python/rips/Instance.py b/ApplicationCode/GrpcInterface/Python/rips/Instance.py index d5b55b3ecd..818fcd2039 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/Instance.py +++ b/ApplicationCode/GrpcInterface/Python/rips/Instance.py @@ -33,7 +33,7 @@ class Instance: return s.connect_ex(('localhost', port)) == 0 @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 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. @@ -43,6 +43,9 @@ class Instance: will take precedence over what is provided in the RESINSIGHT_EXECUTABLE environment variable. 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: Instance: an instance object if it worked. None if not. """ @@ -51,6 +54,8 @@ class Instance: portEnv = os.environ.get('RESINSIGHT_GRPC_PORT') if portEnv: port = int(portEnv) + if launchPort is not -1: + port = launchPort if not resInsightExecutable: resInsightExecutable = os.environ.get('RESINSIGHT_EXECUTABLE') @@ -64,10 +69,19 @@ class Instance: print('Port ' + str(port)) print('Trying to launch', resInsightExecutable) - parameters = ["ResInsight", "--server", str(port)] + + if isinstance(commandLineParameters, str): + commandLineParameters = [str] + + parameters = ["ResInsight", "--server", str(port)] + commandLineParameters if console: print("Launching as console app") 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) if pid: instance = Instance(port=port, launched=True) diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/LaunchWithCommandLineOptions.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/LaunchWithCommandLineOptions.py new file mode 100644 index 0000000000..ae6975408e --- /dev/null +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/LaunchWithCommandLineOptions.py @@ -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())