diff --git a/ApplicationCode/GrpcInterface/CMakeLists.cmake b/ApplicationCode/GrpcInterface/CMakeLists.cmake index 1d10dac6a9..1a39a18a2e 100644 --- a/ApplicationCode/GrpcInterface/CMakeLists.cmake +++ b/ApplicationCode/GrpcInterface/CMakeLists.cmake @@ -164,7 +164,6 @@ if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE) ${GRPC_PYTHON_GENERATED_SOURCES} "rips/generated/RiaVersionInfo.py" "rips/__init__.py" - "rips/App.py" "rips/Case.py" "rips/Commands.py" "rips/Grid.py" diff --git a/ApplicationCode/GrpcInterface/Python/rips/Instance.py b/ApplicationCode/GrpcInterface/Python/rips/Instance.py index db05e08044..5c1654900c 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/Instance.py +++ b/ApplicationCode/GrpcInterface/Python/rips/Instance.py @@ -6,10 +6,12 @@ import logging import time sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated')) +import App_pb2 +import App_pb2_grpc +from Definitions_pb2 import Empty import RiaVersionInfo -from .App import App from .Commands import Commands from .Project import Project @@ -19,7 +21,6 @@ class Instance: Attributes: launched (bool): Tells us whether the application was launched as a new process. If the application was launched we may need to close it when exiting the script. - app (App): Application information object. Set when creating an instance. commands (Commands): Command executor. Set when creating an instance. project (Project): Current project in ResInsight. Set when creating an instance and updated when opening/closing projects. @@ -99,8 +100,8 @@ class Instance: def __checkVersion(self): try: - majorVersionOk = self.app.majorVersion() == int(RiaVersionInfo.RESINSIGHT_MAJOR_VERSION) - minorVersionOk = self.app.minorVersion() == int(RiaVersionInfo.RESINSIGHT_MINOR_VERSION) + majorVersionOk = self.majorVersion() == int(RiaVersionInfo.RESINSIGHT_MAJOR_VERSION) + minorVersionOk = self.minorVersion() == int(RiaVersionInfo.RESINSIGHT_MINOR_VERSION) return True, majorVersionOk and minorVersionOk except grpc.RpcError as e: return False, False @@ -118,7 +119,7 @@ class Instance: self.launched = launched # Main version check package - self.app = App(self.channel) + self.app = self.app = App_pb2_grpc.AppStub(self.channel) connectionOk = False versionOk = False @@ -147,3 +148,35 @@ class Instance: path = os.getcwd() self.commands.setStartDir(path=path) + + def __versionMessage(self): + return self.app.GetVersion(Empty()) + + def majorVersion(self): + """Get an integer with the major version number""" + return self.__versionMessage().major_version + + def minorVersion(self): + """Get an integer with the minor version number""" + return self.__versionMessage().minor_version + + def patchVersion(self): + """Get an integer with the patch version number""" + return self.__versionMessage().patch_version + + def versionString(self): + """Get a full version string, i.e. 2019.04.01""" + return str(self.majorVersion()) + "." + str(self.minorVersion()) + "." + str(self.patchVersion()) + + def exit(self): + """Tell ResInsight instance to quit""" + print("Telling ResInsight to Exit") + return self.app.Exit(Empty()) + + def isConsole(self): + """Returns true if the connected ResInsight instance is a console app""" + return self.app.GetRuntimeInfo(Empty()).app_type == App_pb2.ApplicationTypeEnum.Value('CONSOLE_APPLICATION') + + def isGui(self): + """Returns true if the connected ResInsight instance is a GUI app""" + return self.app.GetRuntimeInfo(Empty()).app_type == App_pb2.ApplicationTypeEnum.Value('GUI_APPLICATION') diff --git a/ApplicationCode/GrpcInterface/Python/rips/tests/conftest.py b/ApplicationCode/GrpcInterface/Python/rips/tests/conftest.py index 14345eabd1..b9d1efb2f3 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/tests/conftest.py +++ b/ApplicationCode/GrpcInterface/Python/rips/tests/conftest.py @@ -38,4 +38,4 @@ def pytest_configure(config): def pytest_unconfigure(config): if not config.getoption('--existing'): - _rips_instance.app.exit() + _rips_instance.exit() diff --git a/ApplicationCode/GrpcInterface/Python/rips/tests/test_commands.py b/ApplicationCode/GrpcInterface/Python/rips/tests/test_commands.py index a5aafd798b..184b0e42e6 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/tests/test_commands.py +++ b/ApplicationCode/GrpcInterface/Python/rips/tests/test_commands.py @@ -10,7 +10,7 @@ import rips import dataroot def test_exportSnapshots(rips_instance, initializeTest): - if not rips_instance.app.isGui(): + if not rips_instance.isGui(): pytest.skip("Cannot run test without a GUI") casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"