#4611 Merge python classes App and Instance

This commit is contained in:
Gaute Lindkvist 2019-08-22 11:11:16 +02:00
parent f13f6c29e7
commit 07cb9e52cb
4 changed files with 40 additions and 8 deletions

View File

@ -164,7 +164,6 @@ if (RESINSIGHT_GRPC_PYTHON_EXECUTABLE)
${GRPC_PYTHON_GENERATED_SOURCES} ${GRPC_PYTHON_GENERATED_SOURCES}
"rips/generated/RiaVersionInfo.py" "rips/generated/RiaVersionInfo.py"
"rips/__init__.py" "rips/__init__.py"
"rips/App.py"
"rips/Case.py" "rips/Case.py"
"rips/Commands.py" "rips/Commands.py"
"rips/Grid.py" "rips/Grid.py"

View File

@ -6,10 +6,12 @@ import logging
import time import time
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated')) 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 import RiaVersionInfo
from .App import App
from .Commands import Commands from .Commands import Commands
from .Project import Project from .Project import Project
@ -19,7 +21,6 @@ class Instance:
Attributes: Attributes:
launched (bool): Tells us whether the application was launched as a new process. 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. 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. commands (Commands): Command executor. Set when creating an instance.
project (Project): Current project in ResInsight. project (Project): Current project in ResInsight.
Set when creating an instance and updated when opening/closing projects. Set when creating an instance and updated when opening/closing projects.
@ -99,8 +100,8 @@ class Instance:
def __checkVersion(self): def __checkVersion(self):
try: try:
majorVersionOk = self.app.majorVersion() == int(RiaVersionInfo.RESINSIGHT_MAJOR_VERSION) majorVersionOk = self.majorVersion() == int(RiaVersionInfo.RESINSIGHT_MAJOR_VERSION)
minorVersionOk = self.app.minorVersion() == int(RiaVersionInfo.RESINSIGHT_MINOR_VERSION) minorVersionOk = self.minorVersion() == int(RiaVersionInfo.RESINSIGHT_MINOR_VERSION)
return True, majorVersionOk and minorVersionOk return True, majorVersionOk and minorVersionOk
except grpc.RpcError as e: except grpc.RpcError as e:
return False, False return False, False
@ -118,7 +119,7 @@ class Instance:
self.launched = launched self.launched = launched
# Main version check package # Main version check package
self.app = App(self.channel) self.app = self.app = App_pb2_grpc.AppStub(self.channel)
connectionOk = False connectionOk = False
versionOk = False versionOk = False
@ -147,3 +148,35 @@ class Instance:
path = os.getcwd() path = os.getcwd()
self.commands.setStartDir(path=path) 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')

View File

@ -38,4 +38,4 @@ def pytest_configure(config):
def pytest_unconfigure(config): def pytest_unconfigure(config):
if not config.getoption('--existing'): if not config.getoption('--existing'):
_rips_instance.app.exit() _rips_instance.exit()

View File

@ -10,7 +10,7 @@ import rips
import dataroot import dataroot
def test_exportSnapshots(rips_instance, initializeTest): 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") pytest.skip("Cannot run test without a GUI")
casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID" casePath = dataroot.PATH + "/TEST10K_FLT_LGR_NNC/TEST10K_FLT_LGR_NNC.EGRID"